Mikubill / sd-webui-controlnet

WebUI extension for ControlNet
GNU General Public License v3.0
16.8k stars 1.93k forks source link

Depth_anything_v2: No module named 'depth_anything_v2.dpt error #3018

Open zthrx opened 1 month ago

zthrx commented 1 month ago

Hey @MackinationsAi

I've reinstalled Controlnet plugin but I keep getting this error.

Traceback (most recent call last): File "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 488, in run_predict output = await app.get_blocks().process_api( File "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1431, in process_api result = await self.call_function( File "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1103, in call_function prediction = await anyio.to_thread.run_sync( File "C:\Users...\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 "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 937, in run_sync_in_worker_thread return await future File "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\anyio_backends_asyncio.py", line 867, in run result = context.run(func, args) File "C:\Users...\stable-diffusion-webui\venv\lib\site-packages\gradio\utils.py", line 707, in wrapper response = f(args, kwargs) File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\controlnet_ui\controlnet_ui_group.py", line 951, in run_annotator result = preprocessor.cached_call( File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\supported_preprocessor.py", line 198, in cached_call result = self._cached_call(input_image, *args, *kwargs) File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\utils.py", line 82, in decorated_func return cached_func(args, kwargs) File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\utils.py", line 66, in cached_func return func(*args, *kwargs) File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\supported_preprocessor.py", line 211, in _cached_call return self(args, **kwargs) File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\preprocessor\legacy\legacy_preprocessors.py", line 105, in call result, is_image = self.call_function( File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\preprocessor\legacy\processor.py", line 200, in depth_anything_v2 from annotator.depth_anything_v2 import DepthAnythingV2Detector File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator\depth_anything_v2.py", line 9, in from depth_anything_v2.dpt import DepthAnythingV2 ModuleNotFoundError: No module named 'depth_anything_v2.dpt'

Depth_anything, midas etc. works fine

depth2 depth1

Cheers!

Z

MackinationsAi commented 1 month ago

@zthrx try the following. Open up cmd at your main folder - C:\Users...\stable-diffusion-webui, input venv\scripts\activate & hit enter, then run pip install https://github.com/MackinationsAi/UDAV2-ControlNet/releases/download/v1.0.0/depth_anything_v2-2024.7.1.0-py2.py3-none-any.whl. Now go to your C:\Users...\stable-diffusion-webui\venv\Lib\site-packages folder & you should see a depth_anything_v2 & depth_anything_v2-2024.7.1.0.dist-info folder, that is where the module named 'depth_anything_v2.dpt' is located. Now that everything is installed correctly you should be able to run the depth_anything_v2 preprocessor!

Also I noticed that you have depth_anything_v2_vitb_fp32 [c0792524] as your model, which will not work, that model is a preprocessor model & not a controlnet model. You need bdsqlsz_controlllite_xl_depth, diffusers_xl_depth_full, sargezt_xl_depth or one of the other sdxl controlnet depth models for sdxl generations. Or control_v11f1p_sd15_depth for sd_v1.5 generations.

zthrx commented 1 month ago

@zthrx try the following. Open up cmd at your main folder - C:\Users...\stable-diffusion-webui, input venv\scripts\activate & hit enter, then run pip install https://github.com/MackinationsAi/UDAV2-ControlNet/releases/download/v1.0.0/depth_anything_v2-2024.7.1.0-py2.py3-none-any.whl. Now go to your C:\Users...\stable-diffusion-webui\venv\Lib\site-packages folder & you should see a depth_anything_v2 & depth_anything_v2-2024.7.1.0.dist-info folder, that is where the module named 'depth_anything_v2.dpt' is located. Now that everything is installed correctly you should be able to run the depth_anything_v2 preprocessor!

Also I noticed that you have depth_anything_v2_vitb_fp32 [c0792524] as your model, which will not work, that model is a preprocessor model & not a controlnet model. You need bdsqlsz_controlllite_xl_depth, diffusers_xl_depth_full, sargezt_xl_depth or one of the other sdxl controlnet depth models for sdxl generations. Or control_v11f1p_sd15_depth for sd_v1.5 generations.

Hey,

Thank you for the solution. I've done everything you said but still getting the same errors :/

File "C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator\depth_anything_v2.py", line 9, in from depth_anything_v2.dpt import DepthAnythingV2 ModuleNotFoundError: No module named 'depth_anything_v2.dpt'

I just have no idea, I can live without depth_anything_v2 for now, everything else works fine except this one preprocessor

After all that reinstallation I still do not see depth_anything_v2.dpt' in the depth_anything_v2-2024.7.1.0.dist-info folder

depth3

Cheers!

zthrx commented 1 month ago

depth 2 folder

dpt

MackinationsAi commented 1 month ago

depth_anything_v2.dpt means from depth_anything_v2 folder, script dpt.py. Try copying the depth_anything_v2 folder from site-packages into your C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator folder that might fix the error.

zthrx commented 1 month ago

depth_anything_v2.dpt means from depth_anything_v2 folder, script dpt.py. Try copying the depth_anything_v2 folder from site-packages into your C:\Users...\stable-diffusion-webui\extensions\sd-webui-controlnet\annotator folder that might fix the error.

Hey,

Tried every combination but no success. Getting same errors :( (every other preprocessor works fine)

jj2 jjj

MackinationsAi commented 1 month ago

I have one more potential fix - install if this doesn't work then I don't know how to get it working for you unfortunately... :/

zthrx commented 1 month ago

I have one more potential fix - install if this doesn't work then I don't know how to get it working for you unfortunately... :/

Hey, late reply (holiday mood)

I still can't make it work in controlnet but somehow it all works in "depth" tab

obraz

DominikDoom commented 3 weeks ago

I had the same issue, and after experimenting a bit just put in a print for the imported module. The result was:

<module 'depth_anything_v2' from 'C:\\sd-webui\\extensions\\stable-diffusion-webui-depthmap-script\\depth_anything_v2\\__init__.py'>

From this it's obvious that the issue was a namespace conflict with the depthmap script (to which the "Depth" tab in the picture from @zthrx belongs, so it's likely the same issue).

For maintainability reasons, depthmap-script doesn't require the v2 package or install it from a wheel, but instead ships with a full copy of the depth_anything_v2 code in a subfolder (from the looks of it, it's the depth_anythingv2 gradio demo). This has its own __init_\.py, causing it to override the reference if it's loaded after controlnet.

Just deleting the whole depth_anything_v2 folder in depthmap-script's install root is enough, after that the import in controlnet references

<module 'depth_anything_v2' (<_frozen_importlib_external._NamespaceLoader object at ...>)>

(i.e. the one in the venv site-packages) and works as expected. ~It also still works in the Depth tab despite deleting the folder, since the depthmap-script import will just reference the proper package as well.~

Issue in the depthmap-script repo: https://github.com/thygate/stable-diffusion-webui-depthmap-script/issues/463

zthrx commented 3 weeks ago

I had the same issue, and after experimenting a bit just put in a print for the imported module. The result was:

<module 'depth_anything_v2' from 'C:\\sd-webui\\extensions\\stable-diffusion-webui-depthmap-script\\depth_anything_v2\\__init__.py'>

From this it's obvious that the issue was a namespace conflict with the depthmap script (to which the "Depth" tab in the picture from @zthrx belongs, so it's likely the same issue).

For maintainability reasons, depthmap-script doesn't require the v2 package or install it from a wheel, but instead ships with a full copy of the depth_anything_v2 code in a subfolder (from the looks of it, it's the depth_anything_v2 gradio demo). This has its own init.py, causing it to override the reference if it's loaded after controlnet.

Just deleting the whole depth_anything_v2 folder in depthmap-script's install root is enough, after that the import in controlnet references

<module 'depth_anything_v2' (<_frozen_importlib_external._NamespaceLoader object at ...>)>

(i.e. the one in the venv site-packages) and works as expected. It also still works in the Depth tab despite deleting the folder, since the depthmap-script import will just reference the proper package as well.

Issue in the depthmap-script repo: thygate/stable-diffusion-webui-depthmap-script#463

Heyooo, You are my hero!

Deleting depth_anything_v2 folder from depthmap script works! so I can use depth_anything_v2 in controlnet d11

but by doing so it breaks my Depth tab plugin :(

d12

Temp solution for me is to keep depth_anything_v2 somewhere and when needed copy it back to stable-diffusion-webui-depthmap-script. Any other solution is welcome :)

Thank you again for your reply!

DominikDoom commented 3 weeks ago

Ah sorry, looks like I changed something during experimenting without realizing. The same happens to me on a fresh install. The proposed fix on the depthmap-script issue is just renaming the folder & import, which I can confirm works.

You can either wait for the official fix by them or just do the same manually:

  1. Rename the root depthmap-script/depth_anything_v2 folder to something different, e.g. ddepth_anything_v2
  2. Edit depthmap-script/src/depthmap_generation.py and change the import name in line 30 to the same thing: image

That should then work for both.

zthrx commented 3 weeks ago

Ah sorry, looks like I changed something during experimenting without realizing. The same happens to me on a fresh install. The proposed fix on the depthmap-script issue is just renaming the folder & import, which I can confirm works.

You can either wait for the official fix by them or just do the same manually:

1. Rename the root `depthmap-script/depth_anything_v2` folder to something different, e.g. **d**depth_anything_v2

2. Edit `depthmap-script/src/depthmap_generation.py` and change the import name in line 30 to the same thing:
   ![image](https://private-user-images.githubusercontent.com/34448969/358831129-7d84a602-f913-4550-aac7-aea1edf59075.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4ODk0NzEsIm5iZiI6MTcyMzg4OTE3MSwicGF0aCI6Ii8zNDQ0ODk2OS8zNTg4MzExMjktN2Q4NGE2MDItZjkxMy00NTUwLWFhYzctYWVhMWVkZjU5MDc1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE3VDEwMDYxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYzYWNhZGI4YTYyYzM2ZjEwY2RlMGJmYjBlNDg4Yjk5ODA0MjEzZWFlMWViM2M4YWE1YWRiYjliZThjNmY1YmImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.uQnv8dmtuq3FpnPDxcMvhqAr2sjjV-kJP6w1aFQUXFQ)

That should then work for both.

Heyo, Thank you for the solution. If it works for you then I must been doing something wrong :)

I've renamed the folder dd1

and had to add this extra line with ddepth (edited in notepad like a noob :) note

but still getting same error :(

dd2

Thanks for your time!

DominikDoom commented 3 weeks ago

You misunderstood me, you have to replace the line, not add it. My screenshot is a diff view, meaning it shows what was there before (in red) and what it has been replaced with (green) to highlight changes.

zthrx commented 3 weeks ago

You misunderstood me, you have to replace the line, not add it. My screenshot is a diff view, meaning it shows what was there before (in red) and what it has been replaced with (green) to highlight changes.

Damn, it works now. I will keep my replies just in case someone else will end up being as stupid as me ;)

Thank you and have a great weekend!