Giter Club home page Giter Club logo

Comments (5)

Sourland avatar Sourland commented on August 15, 2024

To use it as a package take the bg.py and the u2net folder. Delete the utilities.py imports and replace remove() with

def remove(
    data,
    model_name="u2net",
    alpha_matting=False,
    alpha_matting_foreground_threshold=240,
    alpha_matting_background_threshold=10,
    alpha_matting_erode_structure_size=10,
    alpha_matting_base_size=1000,
):
    model = get_model(model_name)
    img = Image.fromarray(data.astype('uint8'), 'RGB')
    mask = detect.predict(model, np.array(img)).convert("L")

    if alpha_matting:
        cutout = alpha_matting_cutout(
            img,
            mask,
            alpha_matting_foreground_threshold,
            alpha_matting_background_threshold,
            alpha_matting_erode_structure_size,
            alpha_matting_base_size,
        )
    else:
        cutout = naive_cutout(img, mask)

    # Convert the PIL Image back to ndarray
    cutout_array = np.array(cutout)

    return cutout_array

from backgroundremover.

Sourland avatar Sourland commented on August 15, 2024

@BanKeTang

from backgroundremover.

Tatsh avatar Tatsh commented on August 15, 2024

There is currently a circular import between bg.py and utilities.py:

(ins)>>> from backgroundremover.bg import remove
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/backgroundremover/bg.py", line 15, in <module>
    from .u2net import detect, u2net
  File "/usr/lib/python3.11/site-packages/backgroundremover/u2net/detect.py", line 11, in <module>
    from .. import utilities
  File "/usr/lib/python3.11/site-packages/backgroundremover/utilities.py", line 9, in <module>
    from .bg import DEVICE, Net, iter_frames, remove_many
ImportError: cannot import name 'DEVICE' from partially initialized module 'backgroundremover.bg' (most likely due to a circular import) (/usr/lib/python3.11/site-packages/backgroundremover/bg.py)

It is possible to import from the cli module, but this should not be necessary.

(ins)>>> from backgroundremover.cmd.cli import remove
(ins)>>> remove
<function remove at 0x7f27dd192ca0>

from backgroundremover.

ahmad88me avatar ahmad88me commented on August 15, 2024

I ran into the same problem. I created a pull request with the fix here: #138

from backgroundremover.

nadermx avatar nadermx commented on August 15, 2024

Fixed in 123d444 read ReadMe to on how to. Tx @ahmad88me

from backgroundremover.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.