Extraltodeus / depthmap2mask

Create masks out of depthmaps in img2img
355 stars 35 forks source link

Error if midas_v21 or dpt_large are used #12

Open celiaafisher opened 1 year ago

celiaafisher commented 1 year ago

If I use midas_v21 or dpt_large on any image, I receive this error:

UnboundLocalError: local variable 'model' referenced before assignment

I have tried installing both manually and using the automatic install method. midas_v21_small works fine.

Extraltodeus commented 1 year ago

UnboundLocalError: local variable 'model' referenced before assignment

That error comes when the depth analysis script can not load. Which python version do you use by the way?

korrasam commented 1 year ago

UnboundLocalError: local variable 'model' referenced before assignment

That error comes when the depth analysis script can not load. Which python version do you use by the way?

i have the same issue , python ver. [Python 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0]] using automatic webui runing on rocm 5.2 *edit : 5.3 gpu :rx 6800m

Wukong1-137 commented 1 year ago

Im having the same issue. Running with Python 3.11.0, Auto1111 webui, and an Nvidia 3060

celiaafisher commented 1 year ago

I have Python 3.10.7, Auto1111 webui, and a Nvidia 2070

AugmentedRealityCat commented 1 year ago

I tried removing the models from the ./models/midas/ folder to see if it would generate the same error, but the depthmap2mask extension actually fixes this problem all by itself by downloading any missing model the moment you use them.

Just for your information, since this is not a bug, here is the message I got when I removed midas_v21_small :

./models/midas/midas_v21_small-70d6b9c8.pt
Downloading midas model weights to ./models/midas/midas_v21_small-70d6b9c8.pt
Loading weights:  ./models/midas/midas_v21_small-70d6b9c8.pt

I guess you don't get anything like this in your log window when trying to use midas_v21 or dpt_large ? Have you tried removing any of the two models that don't work? Does it try to download them if you try to use them after?

Wukong1-137 commented 1 year ago

(update) I tried a third time with Midas_v21 and am still getting the same problem. Im thinking that maybe the first time I downloaded my connection might have dropped and something got cached or stored somewhere that is making the file look corrupted, because its the third time I have downloaded the file and am still getting the same inicial error that ends with the UnboundLocalError.

(update)

I removed both files Midas_v21 and DPT_large. I tried Midas first and it didnt work, it gave me the same error as the first time I downloaded (I have saved the error text if that helps). I then tried the same with the DPT model before going to bed, and in the morning I found that it had worked! Thank you!

However, one thing to note for other that have this problem is that the DPT_large model is GPU thirsty and will often give me runtime errors if I dont downgrade what I would run on any other img-2-img run. Also, Im getting strange things like this... Screenshot 2022-11-30 084859

I used DDIM at 40 steps here, but it gave me 8 out of 9 steps and didnt finish the 9th, I did however get a depth to image map and an image that looks nice. This is happening everytime.

I will now try again (3rd download) with Midas_v21 to see if it all comes together.

(original) I removed Midas and redownloaded it. it gave me the same error I got last time, where it says the file might be corrupted, that would be the second time in a row, however, so I'm guessing it's not that. I will copy the text wall that I got in case that helps.

I also removed the DPT Large and will try again with that one, but I have to get some sleep. I will update in the morning.

Here comes the text wall of errors and other stuff that doesnt mean much to me but might make sense to people who know...

Downloading midas model weights to ./models/midas/midas_v21-f6b98070.pt Loading weights: ./models/midas/midas_v21-f6b98070.pt Using cache found in C:\Users\Wukong/.cache\torch\hub\facebookresearch_WSL-Images_main Error completing request Traceback (most recent call last): File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\extensions/depthmap2mask/scripts/depthmap_for_depth2img.py", line 74, in calculate_depth_maps model = MidasNet(model_path, non_negative=True) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\repositories\midas\midas\midas_net.py", line 30, in init self.pretrained, self.scratch = _make_encoder(backbone="resnext101_wsl", features=features, use_pretrained=use_pretrained) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\repositories\midas\midas\blocks.py", line 37, in _make_encoder pretrained = _make_pretrained_resnext101_wsl(use_pretrained) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\repositories\midas\midas\blocks.py", line 115, in _make_pretrained_resnext101_wsl resnet = torch.hub.load("facebookresearch/WSL-Images", "resnext101_32x8d_wsl") File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\hub.py", line 540, in load model = _load_local(repo_or_dir, model, *args, kwargs) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\hub.py", line 569, in _load_local model = entry(args, kwargs) File "C:\Users\Wukong/.cache\torch\hub\facebookresearch_WSL-Images_main\hubconf.py", line 39, in resnext101_32x8d_wsl return _resnext('resnext101_32x8d', Bottleneck, [3, 4, 23, 3], True, progress, kwargs) File "C:\Users\Wukong/.cache\torch\hub\facebookresearch_WSL-Images_main\hubconf.py", line 24, in _resnext state_dict = load_state_dict_from_url(model_urls[arch], progress=progress) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\hub.py", line 731, in load_state_dict_from_url return torch.load(cached_file, map_location=map_location) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\safe.py", line 102, in load return load_with_extra(filename, args, kwargs) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\safe.py", line 147, in load_with_extra return unsafe_torch_load(filename, *args, kwargs) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\serialization.py", line 713, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\venv\lib\site-packages\torch\serialization.py", line 938, in _legacy_load typed_storage._storage._set_from_file( RuntimeError: unexpected EOF, expected 1356128 more bytes. The file might be corrupted.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 45, in f res = list(func(*args, *kwargs)) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\call_queue.py", line 28, in f res = func(args, *kwargs) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\img2img.py", line 137, in img2img processed = modules.scripts.scripts_img2img.run(p, args) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\modules\scripts.py", line 317, in run processed = script.run(p, *script_args) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\extensions\depthmap2mask\scripts\depth2image_depthmask.py", line 81, in run d_m = sdmg.calculate_depth_maps(p.init_images[0],img_x,img_y,model_type,invert_depth) File "D:\Stable Diffusion Automatic1111\stable-diffusion-webui\extensions/depthmap2mask/scripts/depthmap_for_depth2img.py", line 169, in calculate_depth_maps del model UnboundLocalError: local variable 'model' referenced before assignment

Rogal80 commented 1 year ago

Same here with large model

UnboundLocalError: local variable 'model' referenced before assignment

korrasam commented 1 year ago

so for all of u out there still having the same issue , the solution for me was too simple, just delete the model that was downloaded earlier and download the model manually from this link https://github.com/intel-isl/DPT/releases/download/1_0/dpt_large-midas-2f21e586.pt then place in models folder