OPHoperHPO / image-background-remove-tool

✂️ Automated high-quality background removal framework for an image using neural networks. ✂️
https://carve.photos
Apache License 2.0
1.39k stars 272 forks source link

Python 3.10 requirements need to be updated #76

Closed 6r1d closed 2 years ago

6r1d commented 2 years ago

I've posted #75 and to help with tests, I am running CarveKit in venv with Python 3.10.4 to do a clean installation and I see this when trying to install the packages:

ERROR: Could not find a version that satisfies the requirement torch~=1.10.0 (from versions: 1.11.0, 1.11.0+cpu)
ERROR: No matching distribution found for torch~=1.10.0

Should I update Torch to 1.11.0, I'd see:

ERROR: Ignored the following versions that require a different python version: 3.10.0.0 Requires-Python >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <3.5; 3.7.4.2 Requires-Python >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <3.5
ERROR: Could not find a version that satisfies the requirement torchvision~=0.11.0 (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.12.0, 0.12.0+cpu)
ERROR: No matching distribution found for torchvision~=0.11.0

Let us try torchvision~=0.12.0 and torch~=1.11.0:

ERROR: Cannot install -r requirements.txt (line 6), -r requirements.txt (line 7) and numpy~=1.19.5 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested numpy~=1.19.5
    torchvision 0.12.0 depends on numpy
    opencv-python 4.5.5.64 depends on numpy>=1.19.3; python_version >= "3.9"
    opencv-python 4.5.5.64 depends on numpy>=1.21.2; python_version >= "3.10"
    The user requested numpy~=1.19.5
    torchvision 0.12.0 depends on numpy
    opencv-python 4.5.5.62 depends on numpy>=1.19.3; python_version >= "3.9"
    opencv-python 4.5.5.62 depends on numpy>=1.21.2; python_version >= "3.10

Let's fix NumPy now: numpy~=1.21.2. Things seem to work. I am not sure if warnings matter here:

python3 -m carvekit -i /home/grid/Downloads/c775c443b9b6a7413e61d347e83b2918.jpg -o /home/grid/Downloads/kitten.png --device cpu
Downloading u2net.pth model: 1377273it [02:01, 11378.81it/s]
Downloading fba_matting.pth model: 1084688it [01:38, 11032.32it/s]
Removing background: 0 image batch [00:00, ? image batch/s]/opt/carvekit/lib/python3.10/site-packages/torch/nn/functional.py:780: UserWarning: Note that order of the arguments: ceil_mode and return_indices will changeto match the args list in nn.MaxPool2d in a future release.
  warnings.warn("Note that order of the arguments: ceil_mode and return_indices will change"
/opt/carvekit/lib/python3.10/site-packages/torch/nn/functional.py:749: UserWarning: Note that order of the arguments: ceil_mode and return_indices will changeto match the args list in nn.MaxPool2d in a future release.
  warnings.warn("Note that order of the arguments: ceil_mode and return_indices will change"
Removing background: 1 image batch [00:02,  2.71s/ image batch]

Since this version of Torch seems to have ceil_mode and return_indices configured that way, it seems safe to update the package. Should I PR the change?

If not yet, I can test if there are defects on several test images. Thanks.

OPHoperHPO commented 2 years ago

Please use the Python version. e.g. 3.8.2 which supports the PyTorch version from requirements.txt when testing or running a project.

Currently python >= 3.10 is not supported. This version of python requires the latest dependencies which break the cuda docker image build.

You can submit a Pull Request with updated dependencies, but make sure all versions of the docker image (CUDA and CPU) correctly install dependencies and pass tests. If necessary, update the versions of the base images on which the project's docker images are built. I will update the project code to fix the warnings for the new version of pytorch if there is a Pull Request

6r1d commented 2 years ago

I'm sorry, but I've got no CUDA machine to test the version change on and Colab's Python is locked on Python 3.7.13. I'll just test if updated versions work on 3.7.3 and leave it for the CUDA test stage. Hope that'll help a bit.

I had to set the exact Pillow version because of this small error while attempting to test how deps work with Colab's Python.

Current test seems to be working well (and interestingly, there's small difference on image 4 between CPU and GPU version.):

Cat gpu cpu
1 gpu cpu
2 gpu cpu
3 gpu cpu
4 gpu cpu

So, the resulting requirements.txt is:

requests~=2.26.0
torch~=1.11.0
Pillow==9.0.0
typing~=3.7.4.3
gdown~=3.12.2
torchvision~=0.12.0
opencv-python~=4.5.5.62
numpy~=1.21.2
loguru~=0.5.3
uvicorn~=0.11.7
fastapi~=0.68.1
starlette~=0.14.2
pydantic~=1.7.4
click~=7.1.2
tqdm~=4.62.3
setuptools
aiofiles~=0.6.0
python-multipart~=0.0.5
OPHoperHPO commented 2 years ago

I created a Pull Request #79 with updated dependencies and support for the latest version of Python. I will merge it after June 24th.