Comments (5)
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.
from backgroundremover.
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.
I ran into the same problem. I created a pull request with the fix here: #138
from backgroundremover.
Fixed in 123d444 read ReadMe to on how to. Tx @ahmad88me
from backgroundremover.
Related Issues (20)
- Running backgroundremover on live server it take longer time and nothing happen and hanging the server. HOT 2
- backgroundremover -i "1.mp4" -toi "a.png" -o "output.mov" HOT 1
- Background removal exception
- efficiency HOT 1
- Great god, come on!
- How to use in a Android App ? HOT 1
- How to use as a library ? HOT 2
- Does this software support batch JPG processing? HOT 1
- Anyone can help? thanks HOT 6
- Error initializing filter 'alphamerge' with args 'shortest=1' HOT 3
- May I ask how to make a model
- Video removal produces mask only? HOT 4
- transparent mov not created HOT 1
- video over image not working HOT 1
- Server Requirements? HOT 2
- Mismatch Between GitHub and PyPI Versions of backgroundremover v0.2.7 HOT 3
- Solved - ValueError: invalid literal for int() with base 10: '9222,\n\n' HOT 2
- API rotates image HOT 6
- It doesn't use GPU and runs much slower on Intel CPU
- How to start http server. ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backgroundremover.