afiaka87 / clip-guided-diffusion

A CLI tool/python module for generating images from text using guided diffusion and CLIP from OpenAI.
MIT License
457 stars 62 forks source link

TypeError got an unexpected keyword argument 'custom_classes' #12

Closed DavidSHolz closed 3 years ago

DavidSHolz commented 3 years ago

Running on Windows we always get the following crash

Loading model from: C:\Program Files\Python39\lib\site-packages\lpips-0.1.4-py3.9.egg\lpips\weights\v0.1\vgg.pth
0it [00:07, ?it/s]
Traceback (most recent call last):
  File "C:\Program Files\Python39\Scripts\cgd-script.py", line 33, in <module>
    sys.exit(load_entry_point('cgd-pytorch==0.1.5', 'console_scripts', 'cgd')())
  File "C:\Program Files\Python39\lib\site-packages\cgd_pytorch-0.1.5-py3.9.egg\cgd\cgd.py", line 385, in main
    list(enumerate(tqdm(cgd_generator))) # iterate over generator
  File "C:\Users\david\AppData\Roaming\Python\Python39\site-packages\tqdm\std.py", line 1185, in __iter__
    for obj in iterable:
  File "C:\Program Files\Python39\lib\site-packages\cgd_pytorch-0.1.5-py3.9.egg\cgd\cgd.py", line 243, in clip_guided_diffusion
    cgd_samples = diffusion_sample_loop(
TypeError: ddim_sample_loop_progressive() got an unexpected keyword argument 'custom_classes'

At certain resolutions like 128,256,512 this crash occurs after all of the image generation iterations are completed, but before any files are saved.

Is it possible to either fix this or disable the LPIPS loss? This isn't actually required for the image generation right?

afiaka87 commented 3 years ago

@DavidSHolz Thanks for filing an issue on this - wasn't aware of this issue.

I believe this bug may actually be for a different reason than you suspect - are you using DDIM respacing?

"At certain resolutions like 128,256,512 this crash occurs after all of the image generation iterations are completed, but before any files are saved."

Before any files are saved? That certainly shouldn't be happening! I noticed you are on Windows; it's possible you aren't having your files saved to due windows-specific path issues.

afiaka87 commented 3 years ago

I'll have a look into this specifically however: TypeError: ddim_sample_loop_progressive() got an unexpected keyword argument 'custom_classes'

DavidSHolz commented 3 years ago

I was just trying to run the examples in the readme.md, are the default ddim and num_classes arguments going to give stability issues? If so what are the defaults I should be trying?

afiaka87 commented 3 years ago

@DavidSHolz apologies I didnt mean to insinuate that what you were experiencing is not in fact a bug. There is indeed something strange going on and I'll investigate that specifically when I get a moment.

Until then; you might have more success with just using the defaults set in the argument parser. Depending on your GPU (nvidia RTX 2070 is all that's tested) - running something like the following should work fine:

cgd -txt "The text I want to generate" -respace "250" -size 128

Let me know if this fails too however. Super appreciate the patience btw; I haven't tested on Windows and there could be a few bugs on that platform.

afiaka87 commented 3 years ago

The reason I am specifically suspicious of the usage of ddim<> respacing is because of the error you posted in your top post:

TypeError: ddim_sample_loop_progressive() got an unexpected keyword argument 'custom_classes'

afiaka87 commented 3 years ago

@DavidSHolz to answer your original question about VGG loss; it is now completely disabled by default in v0.1.6

I've also updated the README to use mostly default options, which are indeed probably the best possible options (and should avoid certain edge cases I haven't ironed out with DDIM scheduling)

DavidSHolz commented 3 years ago

Thank you! Unfortunately I'm still getting crash about getting a custom keyword arguement 'custom_classes', but there's more information in the crash now:

Here's some more information about my machine, command line call, etc.

GPU: Nvidia 3090 OS: Windows

Command-line call: C:\python\clip-guided-diffusion>cgd --image_size 256 --prompts "cyberpunk wizard"

Command line response:

Given initial image:
Using:

CLIP guidance scale: 1000
TV Scale: 100.0
Range scale: 50.0
Dropout: 0.0.
Number of cutouts: 48 number of cutouts.
0it [00:00, ?it/s]
Using device cuda. You can specify a device manually with `--device/-dev`
Setting up [LPIPS] perceptual loss: trunk [vgg], v[0.1], spatial [off]
Loading model from: C:\Program Files\Python39\lib\site-packages\lpips-0.1.4-py3.9.egg\lpips\weights\v0.1\vgg.pth
0it [00:09, ?it/s]
Traceback (most recent call last):
  File "C:\Program Files\Python39\Scripts\cgd-script.py", line 33, in <module>
    sys.exit(load_entry_point('cgd-pytorch==0.1.5', 'console_scripts', 'cgd')())
  File "C:\Program Files\Python39\lib\site-packages\cgd_pytorch-0.1.5-py3.9.egg\cgd\cgd.py", line 385, in main
    init_image=args.init_image,
  File "C:\Users\david\AppData\Roaming\Python\Python39\site-packages\tqdm\std.py", line 1185, in __iter__
    for obj in iterable:
  File "C:\Program Files\Python39\lib\site-packages\cgd_pytorch-0.1.5-py3.9.egg\cgd\cgd.py", line 243, in clip_guided_diffusion
    loss = losses.sum() * clip_guidance_scale + tv_losses.sum() * tv_scale + range_losses.sum() * range_scale
TypeError: p_sample_loop_progressive() got an unexpected keyword argument 'custom_classes'
afiaka87 commented 3 years ago

Thank you! Unfortunately I'm still getting crash about getting a custom keyword arguement 'custom_classes', but there's more information in the crash now: ... Python39\lib\site-packages\cgd_pytorch-0.1.5-py3.9.egg\cgd\cgd.py", line 243, in clip_guided_diffusion loss = losses.sum() clip_guidance_scale + tv_losses.sum() tv_scale + range_losses.sum() * range_scale TypeError: p_sample_loop_progressive() got an unexpected keyword argument 'custom_classes'

Thanks for the stacktrace!

It looks as though you're using your globally installed Python3.9. No problem there; but I mention it because the first reason I think this bug might be happening is because you have an out-of-date copy of guided-diffusion. To get a fresh copy:

First delete any folder you have in your local files for guided-diffusion. In bash: rm -rf guided-diffusion

git clone https://github.com/afiaka87/guided-diffusion
python -m pip install --upgrade -e guided-diffusion
DavidSHolz commented 3 years ago

Works now thanks!