Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep getting Rickrolled #71

Closed
mokiat opened this issue Aug 23, 2022 · 9 comments
Closed

Keep getting Rickrolled #71

mokiat opened this issue Aug 23, 2022 · 9 comments

Comments

@mokiat
Copy link

mokiat commented Aug 23, 2022

Hi,

I am trying to generate some AI art with your code but I keep getting broken results and half of them are the Rickroll meme photo.
rickrolled

Following is the command I used to generate this:

python 'scripts/txt2img.py' \
  --ckpt 'sd-v1-3.ckpt' \
  --config "configs/stable-diffusion/v1-inference.yaml" \
  --n_samples 1 \
  --W 256 \
  --H 256 \
  --plms \
  --n_iter 50 \
  --prompt "photo of a cat"

I tried the v1.4 model and get similar results. My videocard is an RTX 2080 Super, 8G VRAM, so I can't try any larger resolutions (they just fail with OOM errors).

I've tried simple commands, as in the README of the repository, or alternative variations of the above command and still get the same result.

At this point in time I am starting to worry if I have downloaded a virus, though I checked the sha values...

Any help would be welcome.

@magnusviri
Copy link

You don't have a virus. It's coming from this and this.

@mokiat
Copy link
Author

mokiat commented Aug 23, 2022

Well, my prompts so far have been the original one a photograph of an astronaut riding a horse, a car, photo of a cat. I think that's it.

Maybe some heuristic isn't working properly and is evaluating it as NSFW (looking at this line:

if has_nsfw_concept[i]:
).

Either way, the results are with much lower quality that what friends are getting. Could it be the 256x256 resolution that is messing everything up?

@mokiat
Copy link
Author

mokiat commented Aug 23, 2022

OK, so I managed to get it working. All I did was add the following line in scripts/txt2img.py:

model.half()

Not sure what it does, watched it in some YouTube clip. However, it allowed me to generate at 512x512 on my card and now it seems to generate images of fine quality and no rickrolls.

@breadbrowser
Copy link

breadbrowser commented Aug 23, 2022

@magnusviri
Copy link

@mokiat, where did you add that line?

@mokiat
Copy link
Author

mokiat commented Aug 24, 2022

@magnusviri , I added it immediately after this line:

model = instantiate_from_config(config.model)

so that it becomes:

model = instantiate_from_config(config.model)
model.half()

As far as I understand it, this converts the model from 32bit float to 16bit float, which gives some VRAM room to the GPU. Enough so that 512x512 works.

I also figured out how to get img2img to use float16 as well. You need to do the same thing after the following line:

model = instantiate_from_config(config.model)

And you also need to change float32 to float16 on the following line:

image = np.array(image).astype(np.float32) / 255.0

@Cabbagec
Copy link

Cabbagec commented Aug 24, 2022

It's the safety checker's doing. When NSFW features are detected, it replaces the image with rick.jpg. But the safety checker doesn't seem to work very well, it just randomly removes some of the images.

I've added an --unsafe command line flag to disable it temporarily, just add it to end of your command. Also, another side effect is that the safety checker model will not be loaded with this flag on, saving some gigs of your precious VRAM :D

See #79

@mokiat
Copy link
Author

mokiat commented Aug 24, 2022

@Cabbagec , nice. However, I think in general the model doesn't work well with 256x256. Just look at the cat photos above.
Going with float16 gives users with 8GB video cards a chance to generate at 512x512.
It's interesting to see if the resolution can indeed be pushed further without the safety check consuming RAM.

@mokiat
Copy link
Author

mokiat commented Aug 24, 2022

I am closing this, as there is a workaround and the reason for the Rickroll image was determined.

@mokiat mokiat closed this as completed Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants