stable-diffusion-webui-cv2-external-masking-script icon indicating copy to clipboard operation
stable-diffusion-webui-cv2-external-masking-script copied to clipboard

Suddenly stopped working

Open VantomPayne opened this issue 3 years ago • 12 comments

the script stopped working after I installed a bunch of extensions, might be a conflict?

Traceback (most recent call last): File "F:\stable-diffusion-webui\modules\ui.py", line 185, in f res = list(func(*args, **kwargs)) File "F:\stable-diffusion-webui\webui.py", line 54, in f res = func(*args, **kwargs) File "F:\stable-diffusion-webui\modules\img2img.py", line 137, in img2img processed = modules.scripts.scripts_img2img.run(p, *args) File "F:\stable-diffusion-webui\modules\scripts.py", line 290, in run processed = script.run(p, *script_args) File "F:\stable-diffusion-webui\scripts\external_masking.py", line 227, in run p.image_mask,self.lastPolys = display_mask_ui(p.init_images[0],p.image_mask,max_size,self.lastPolys) File "F:\stable-diffusion-webui\scripts\external_masking.py", line 69, in display_mask_ui cv2.namedWindow('MaskingWindow', cv2.WINDOW_AUTOSIZE) cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1250: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'

VantomPayne avatar Nov 14 '22 17:11 VantomPayne

Seems to indicate it's the gui-less version that got installed for you opencv-python-headless. Try the sequence of:

py -m pip uninstall opencv-python-headless
py -m pip uninstall opencv-python
py -m pip install --upgrade opencv-python

dfaker avatar Nov 14 '22 21:11 dfaker

Still does not fix it, when launching with the new dreambooth extension installed, I noticed this in the console.

Building wheels for collected packages: pycocotools Building wheel for pycocotools (pyproject.toml): started Building wheel for pycocotools (pyproject.toml): finished with status 'error' Failed to build pycocotools

stderr: error: subprocess-exited-with-error

Building wheel for pycocotools (pyproject.toml) did not run successfully. exit code: 1 [16 lines of output] running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-cpython-310 creating build\lib.win-amd64-cpython-310\pycocotools copying pycocotools\coco.py -> build\lib.win-amd64-cpython-310\pycocotools copying pycocotools\cocoeval.py -> build\lib.win-amd64-cpython-310\pycocotools copying pycocotools\mask.py -> build\lib.win-amd64-cpython-310\pycocotools copying pycocotools_init_.py -> build\lib.win-amd64-cpython-310\pycocotools running build_ext cythoning pycocotools/_mask.pyx to pycocotools_mask.c C:\Users\admin\AppData\Local\Temp\pip-build-env-g8ty80qo\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\admin\AppData\Local\Temp\pip-install-a_ntrjch\pycocotools_441a89abd0c04cc49f2937d97e296165\pycocotools_mask.pyx tree = Parsing.p_module(s, pxd, full_module_name) building 'pycocotools._mask' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pycocotools ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects

Couold this be related?

VantomPayne avatar Nov 15 '22 19:11 VantomPayne

Doesn't seem related, let's try to narrow down the failing version location.

from inside the stable-diffusion-webui folder:

py -c "import cv2;import numpy;cv2.imshow('test_window',numpy.zeros((512,512,3)));cv2.waitKey(0)"

venv\Scripts\python.exe -c "import cv2;import numpy;cv2.imshow('test_window',numpy.zeros((512,512,3)));cv2.waitKey(0)"

both should produce a black window with the title 'test_window'

If just the second one fails we can run that same uninstall/reinstall run just for the venv:

from inside the stable-diffusion-webui folder:

venv\Scripts\python -m pip uninstall opencv-python-headless
venv\Scripts\python -m pip uninstall opencv-python
venv\Scripts\python -m pip install --upgrade opencv-python

dfaker avatar Nov 15 '22 19:11 dfaker

Thanks, previous attempts at fixes failed at uninstalling headless opencv because it is not found, after adding venv to the argument all three command worked, but the script is still not working and giving the same error.

VantomPayne avatar Nov 15 '22 20:11 VantomPayne

Still, same here :(

Rogal80 avatar Nov 15 '22 20:11 Rogal80

Thanks, previous attempts at fixes failed at uninstalling headless opencv because it is not found, after adding venv to the argument all three command worked, but the script is still not working and giving the same error.

And the test command:

venv\Scripts\python.exe -c "import cv2;import numpy;cv2.imshow('test_window',numpy.zeros((512,512,3)));cv2.waitKey(0)"

Fails with the same error?

What does:

venv\Scripts\python.exe -m pip list

List for you?

dfaker avatar Nov 15 '22 20:11 dfaker

First command produce a black window correctly, while venv\Scripts\python.exe -c "import cv2;import numpy;cv2.imshow('test_window',numpy.zeros((512,512,3)));cv2.waitKey(0)" gives an error:

Traceback (most recent call last): File "<string>", line 1, in <module> cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:1267: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

VantomPayne avatar Nov 17 '22 18:11 VantomPayne

Here's everything from the pip list:

`F:\stable-diffusion-webui>venv\Scripts\python.exe -m pip list Package Version


absl-py 1.2.0 accelerate 0.12.0 addict 2.4.0 aiohttp 3.8.1 aiosignal 1.2.0 albumentations 1.3.0 analytics-python 1.4.0 antlr4-python3-runtime 4.9.3 anyio 3.6.1 astunparse 1.6.3 async-timeout 4.0.2 attrs 22.1.0 backoff 1.10.0 basicsr 1.4.2 bcrypt 4.0.0 beautifulsoup4 4.11.1 bitsandbytes 0.35.0 cachetools 5.2.0 certifi 2022.6.15 cffi 1.15.1 chardet 4.0.0 charset-normalizer 2.1.1 clean-fid 0.1.29 click 8.1.3 clip 1.0 colorama 0.4.5 coloredlogs 15.0.1 commonmark 0.9.1 cryptography 37.0.4 cycler 0.11.0 deepdanbooru 1.0.0 diffusers 0.8.0.dev0 docker-pycreds 0.4.0 einops 0.4.1 facexlib 0.2.5 fairscale 0.4.9 fastapi 0.81.0 ffmpy 0.3.0 filelock 3.8.0 filterpy 1.4.5 flatbuffers 2.0.7 font-roboto 0.0.1 fonts 0.0.3 fonttools 4.37.1 frozenlist 1.3.1 fsspec 2022.8.2 ftfy 6.1.1 functorch 0.2.1 future 0.18.2 gast 0.4.0 gdown 4.5.1 gfpgan 1.3.8 gitdb 4.0.9 GitPython 3.1.27 google-auth 2.11.0 google-auth-oauthlib 0.4.6 google-pasta 0.2.0 gradio 3.9 grpcio 1.48.1 h11 0.12.0 h5py 3.7.0 httpcore 0.15.0 httpx 0.23.0 huggingface-hub 0.10.1 humanfriendly 10.0 idna 2.10 imageio 2.21.2 importlib-metadata 4.12.0 inflection 0.5.1 invisible-watermark 0.1.5 Jinja2 3.1.2 joblib 1.2.0 jsonmerge 1.8.0 jsonschema 4.15.0 k-diffusion 0.0.1 keras 2.10.0 Keras-Preprocessing 1.1.2 kiwisolver 1.4.4 kornia 0.6.7 lark 1.1.2 libclang 14.0.6 linkify-it-py 1.0.3 llvmlite 0.39.1 lmdb 1.3.0 lpips 0.1.4 Markdown 3.4.1 markdown-it-py 2.1.0 MarkupSafe 2.1.1 matplotlib 3.5.3 mdit-py-plugins 0.3.0 mdurl 0.1.2 mmcv-full 1.7.0 model-index 0.1.11 modelcards 0.1.6 monotonic 1.6 mpmath 1.2.1 multidict 6.0.2 mypy-extensions 0.4.3 networkx 2.8.6 numba 0.56.2 numpy 1.23.3 oauthlib 3.2.0 omegaconf 2.2.3 onnx 1.12.0 onnxruntime 1.12.1 opencv-python 4.6.0.66 opencv-python-headless 4.6.0.66 openmim 0.3.3 opt-einsum 3.3.0 ordered-set 4.1.0 orjson 3.8.0 packaging 21.3 pandas 1.4.4 paramiko 2.11.0 pathtools 0.1.2 piexif 1.1.3 Pillow 9.2.0 pip 22.2.1 promise 2.3 protobuf 3.19.4 psutil 5.9.1 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycparser 2.21 pycryptodome 3.15.0 pydantic 1.10.1 pyDeprecate 0.3.2 pydub 0.25.1 Pygments 2.13.0 PyNaCl 1.5.0 pyparsing 3.0.9 pyre-extensions 0.0.23 pyreadline3 3.4.1 pyrsistent 0.18.1 PySocks 1.7.1 python-dateutil 2.8.2 python-multipart 0.0.5 pytorch-lightning 1.7.6 pytz 2022.2.1 PyWavelets 1.3.0 PyYAML 6.0 qudida 0.0.4 realesrgan 0.3.0 regex 2022.9.13 requests 2.25.1 requests-oauthlib 1.3.1 resize-right 0.0.2 rfc3986 1.5.0 rich 12.6.0 rsa 4.9 scikit-image 0.19.2 scikit-learn 1.1.3 scipy 1.9.1 sentry-sdk 1.9.7 setproctitle 1.3.2 setuptools 59.8.0 shortuuid 1.0.9 six 1.16.0 smmap 5.0.0 sniffio 1.3.0 soupsieve 2.3.2.post1 starlette 0.19.1 sympy 1.11.1 tabulate 0.9.0 tb-nightly 2.11.0a20220903 tensorboard 2.10.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.1 tensorflow 2.10.0 tensorflow-estimator 2.10.0 tensorflow-io 0.27.0 tensorflow-io-gcs-filesystem 0.27.0 termcolor 2.0.1 threadpoolctl 3.1.0 tifffile 2022.8.12 timm 0.6.7 tokenizers 0.12.1 torch 1.12.1+cu116 torchdiffeq 0.2.3 torchmetrics 0.9.3 torchvision 0.13.1+cu116 tqdm 4.64.1 transformers 4.21.0 typing_extensions 4.3.0 typing-inspect 0.8.0 uc-micro-py 1.0.1 urllib3 1.26.12 uvicorn 0.18.3 wandb 0.13.2 wcwidth 0.2.5 websockets 10.3 Werkzeug 2.2.2 wheel 0.37.1 wrapt 1.14.1 xformers 0.0.14.dev0 yapf 0.32.0 yarl 1.8.1 zipp 3.8.1

[notice] A new release of pip available: 22.2.1 -> 22.3.1 [notice] To update, run: F:\stable-diffusion-webui\venv\Scripts\python.exe -m pip install --upgrade pip`

VantomPayne avatar Nov 17 '22 18:11 VantomPayne

@VantomPayne Hmm, I see opencv-python-headless is still there.

dfaker avatar Nov 17 '22 20:11 dfaker

After repeating the process a couple times, I think some of the extension must have been installing the headless version on every launch, which might explain why people are having this problem.

`Installing requirements for Web UI Installing Installing Jinja2==3.1.2 Installing Installing requests==2.28.1

loading Dreambooth reqs from F:\stable-diffusion-webui\extensions\sd_dreambooth_extension\requirements.txt`

Since I have removed opencv from my requirements.txt, it's likely caused by "requests", though I'm not sure which extension is this.

VantomPayne avatar Nov 17 '22 22:11 VantomPayne

d8ahazard/sd_dreambooth_extension depends on albumentations which is in turn depending on the headless version of cv2.

dfaker avatar Nov 17 '22 23:11 dfaker

Thanks for figuring this out, until the conflict is solved I will remove the dreambooth extension for now, not really using it at the moment anyway.

VantomPayne avatar Nov 18 '22 05:11 VantomPayne