sd-webui-segment-anything
sd-webui-segment-anything copied to clipboard
[Bug]: ModuleNotFoundError: No module named 'pycocotools'
Is there an existing issue for this?
- [X] I have searched the existing issues and checked the recent builds/commits of both this extension and the webui
Have you updated WebUI and this extension to the latest version?
- [X] I have updated WebUI and this extension to the latest version
Do you understand that you should read the 1st item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you cannot install GroundingDINO?
- [X] My problem is not about installing GroundingDINO
Do you understand that you should use the latest ControlNet extension and enable external control if you want SAM extension to control ControlNet?
- [X] I have updated ControlNet extension and enabled "Allow other script to control this extension"
Do you understand that you should read the 2nd item of https://github.com/continue-revolution/sd-webui-segment-anything#faq if you observe problems like AttributeError bool object has no attribute enabled and TypeError bool object is not subscriptable?
- [X] My problem is not about such issue, otherwise I have tried changing the extension directory name from sd-webui-segment-anything to a1111-sd-webui-segment-anything
What happened?
After I upgraded the latest version of segmentanything today, groudingDINO is really working, thank you. Both the "Single Image" and "Batch Process" functions can be used normally, but the third function- "Auto SAM", is still not available and will report an error.
Steps to reproduce the problem
- Go to “Auto SAM”, use seg_ofade20k, Upload pictures,
- Press “Preview segmentation image”
What should have happened?
If normal, there will be a SEG picture.
Commit where the problem happens
webui: python: 3.10.6 • torch: 2.0.0+cu118 • xformers: 0.0.17 • gradio: 3.28.1 • commit: [5ab7f213] extension: sd-webui-segment-anything
Requirement already satisfied: send2trash~=1.8 in e:\stable-diffusion-webui\venv\lib\site-packages (1.8.0) Requirement already satisfied: dynamicprompts[attentiongrabber,magicprompt]~=0.27.0 in e:\stable-diffusion-webui\venv\lib\site-packages (0.27.0) Requirement already satisfied: jinja2~=3.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.1.2) Requirement already satisfied: pyparsing~=3.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.0.9) Requirement already satisfied: transformers[torch]~=4.19 in e:\stable-diffusion-webui\venv\lib\site-packages (from dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.25.1) Requirement already satisfied: MarkupSafe>=2.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from jinja2~=3.1->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.1.2) Requirement already satisfied: filelock in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.12.0) Requirement already satisfied: huggingface-hub<1.0,>=0.10.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.13.4) Requirement already satisfied: numpy>=1.17 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.23.5) Requirement already satisfied: packaging>=20.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (23.1) Requirement already satisfied: pyyaml>=5.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (6.0) Requirement already satisfied: regex!=2019.12.17 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2023.3.23) Requirement already satisfied: requests in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.25.1) Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.13.3) Requirement already satisfied: tqdm>=4.27 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.65.0) Requirement already satisfied: torch!=1.12.0,>=1.7 in e:\stable-diffusion-webui\venv\lib\site-packages (from transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.0.0+cu118) Requirement already satisfied: typing-extensions>=3.7.4.3 in e:\stable-diffusion-webui\venv\lib\site-packages (from huggingface-hub<1.0,>=0.10.0->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.5.0) Requirement already satisfied: sympy in e:\stable-diffusion-webui\venv\lib\site-packages (from torch!=1.12.0,>=1.7->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.11.1) Requirement already satisfied: networkx in e:\stable-diffusion-webui\venv\lib\site-packages (from torch!=1.12.0,>=1.7->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (3.1) Requirement already satisfied: colorama in e:\stable-diffusion-webui\venv\lib\site-packages (from tqdm>=4.27->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (0.4.6) Requirement already satisfied: chardet<5,>=3.0.2 in e:\stable-diffusion-webui\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (4.0.0) Requirement already satisfied: idna<3,>=2.5 in e:\stable-diffusion-webui\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2.10) Requirement already satisfied: urllib3<1.27,>=1.21.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.26.15) Requirement already satisfied: certifi>=2017.4.17 in e:\stable-diffusion-webui\venv\lib\site-packages (from requests->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (2022.12.7) Requirement already satisfied: mpmath>=0.19 in e:\stable-diffusion-webui\venv\lib\site-packages (from sympy->torch!=1.12.0,>=1.7->transformers[torch]~=4.19->dynamicprompts[attentiongrabber,magicprompt]~=0.27.0) (1.3.0) sd-dynamic-prompts installer: running 'E:\stable-diffusion-webui\venv\Scripts\python.exe' -m pip install 'send2trash~=1.8' 'dynamicprompts[attentiongrabber,magicprompt]~=0.27.0'
What browsers do you use to access the UI ?
Microsoft Edge
Command Line Arguments
webui-user.bat
Console logs
Running on local URL: http://127.0.0.1:7860
To create a public link, set `share=True` in `launch()`.
Startup time: 58.3s (import torch: 1.9s, import gradio: 1.2s, import ldm: 0.5s, other imports: 0.9s, list SD models: 0.3s, load scripts: 9.0s, load SD checkpoint: 5.1s, create ui: 12.1s, gradio launch: 27.0s, scripts app_started_callback: 0.1s).
Start processing categorical mask
Traceback (most recent call last):
File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 399, in run_predict
output = await app.get_blocks().process_api(
File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1299, in process_api
result = await self.call_function(
File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1022, in call_function
prediction = await anyio.to_thread.run_sync(
File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
result = context.run(func, *args)
File "E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\scripts\sam.py", line 348, in categorical_mask
register_auto_sam(sam, auto_sam_points_per_side, auto_sam_points_per_batch, auto_sam_pred_iou_thresh,
File "E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\scripts\auto.py", line 306, in register_auto_sam
global_sam = SamAutomaticMaskGenerator(
File "E:\stable-diffusion-webui\venv\lib\site-packages\segment_anything\automatic_mask_generator.py", line 118, in __init__
from pycocotools import mask as mask_utils # type: ignore # noqa: F401
ModuleNotFoundError: No module named 'pycocotools'
Additional information
I pip under (venv) environment and (sdwebui) [miniconda] environment respectively,But it will also be errors:
(venv) E:\stable-diffusion-webui\venv\Scripts>pip install pycocotools WARNING: Ignoring invalid distribution -equests (e:\stable-diffusion-webui\venv\lib\site-packages) Collecting pycocotools Using cached pycocotools-2.0.6-cp310-cp310-win_amd64.whl Requirement already satisfied: matplotlib>=2.1.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from pycocotools) (3.7.1) Requirement already satisfied: numpy in e:\stable-diffusion-webui\venv\lib\site-packages (from pycocotools) (1.23.5) Requirement already satisfied: contourpy>=1.0.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (1.0.7) Requirement already satisfied: cycler>=0.10 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (0.11.0) Requirement already satisfied: fonttools>=4.22.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (4.39.3) Requirement already satisfied: kiwisolver>=1.0.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (1.4.4) Requirement already satisfied: packaging>=20.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (23.1) Requirement already satisfied: pillow>=6.2.0 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (9.4.0) Requirement already satisfied: pyparsing>=2.3.1 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (3.0.9) Requirement already satisfied: python-dateutil>=2.7 in e:\stable-diffusion-webui\venv\lib\site-packages (from matplotlib>=2.1.0->pycocotools) (2.8.2) Requirement already satisfied: six>=1.5 in e:\stable-diffusion-webui\venv\lib\site-packages (from python-dateutil>=2.7->matplotlib>=2.1.0->pycocotools) (1.16.0) WARNING: Ignoring invalid distribution -equests (e:\stable-diffusion-webui\venv\lib\site-packages) Installing collected packages: pycocotools Successfully installed pycocotools-2.0.6
After installation, re-operate segmentanything,it will also be errors:
Start semantic segmentation with processor seg_ufade20k Traceback (most recent call last): File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 399, in run_predict output = await app.get_blocks().process_api( File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1299, in process_api result = await self.call_function( File "E:\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1022, in call_function prediction = await anyio.to_thread.run_sync( File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync return await get_asynclib().run_sync_in_worker_thread( File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "E:\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, *args) File "E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\scripts\sam.py", line 313, in cnet_seg outputs = semantic_segmentation(cnet_seg_input_image, cnet_seg_processor, cnet_seg_processor_res, File "E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\scripts\auto.py", line 220, in semantic_segmentation if not os.path.isdir(os.path.join(scripts.basedir(), "annotator")) and not create_symbolic_link(): File "E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\scripts\auto.py", line 58, in create_symbolic_link os.symlink(cnet_annotator_dir, sam_annotator_dir, target_is_directory=True) OSError: [WinError 1314] The client does not have the required privileges.: 'E:\stable-diffusion-webui\extensions\sd-webui-controlnet/annotator' -> 'E:\stable-diffusion-webui\extensions\sd-webui-segment-anything\annotator'
Please open webui with administrative mode the first time you use semantic features, if you are on windows. Windows seems to restrict creating symbolic link, while linux (my development environment) does not.
Please open webui with administrative mode the first time you use semantic features, if you are on windows. Windows seems to restrict creating symbolic link, while linux (my development environment) does not.
just installed the extension and got the pycocotools error. Windows10. I can not start the .bat file with right click -> run as admin. Somehow it just closes the window instant
~Any updates for this issue? I am on windows 11 also. And I tried to open the terminal or powershell in admin mode and then run the webui-user.bat. But still met the issue that when I run Auto SAM -> Mask by Category -> Single Image -> preview, error posted with: "ModuleNotFoundError: No module named 'pycocotools'".~
~Any inputs would be much appreciated. Thanks in advance.~
I just figured that out by manually adding Cpython and pycocotools in requirement.txt and requirement_versions.txt when installing dependencies in the venv. This procedure is invoked in prepare_environment
method in launch.py file (more specfically run_pip(f"install -r \"{requirements_file}\"", "requirements")
).
Another thing need to be noted here is on your host machine(mine is windows 11), need to install C++ build tools for pycocotools. I just installed Vistual studio 2022 C++ build tool (in installer need to select Windows11 SDK for build tools option).
@JonyTianming The way you tried which is directly installed the package in the venv probably did not compatiable to the procedure that webui-user.bat prepared for its env. Highly possible they are in different virtual environment. I am not expert in python but you probably can try my way.
Also this seems not to require me executing in admin mode.
Please open webui with administrative mode the first time you use semantic features, if you are on windows. Windows seems to restrict creating symbolic link, while linux (my development environment) does not.
just installed the extension and got the pycocotools error. Windows10. I can not start the .bat file with right click -> run as admin. Somehow it just closes the window instant
It should be some windows setting issue. Probably you can just open the terminal with admin mode and then run it. This should work in the same way with directly executing the script with admin mode. But I tried still met the issue.