CompVis / stable-diffusion

A latent text-to-image diffusion model
https://ommer-lab.com/research/latent-diffusion-models/
Other
67.92k stars 10.12k forks source link

I can't turn off the NSFW filter #331

Closed Igglepud closed 2 years ago

Igglepud commented 2 years ago

I tried looking for NSFW and the word "safety" in both dream.py and text2img.py, but nothing is there to change. Everything I make comes back as a black image. I assume it's the green box issue, but I can't disable the safety checks to tell. How do you turn this off so I can see my outputs?

Cyberes commented 2 years ago

Stop generating porn.

Igglepud commented 2 years ago

Stop generating porn.

Ha! If only that was the issue. My last prompt was "potato in a hammock." Before that I tried "kitten butler" and "blatant patriotism". I should also note that this is using dream. If I use txt2img it works about 50%.

2phx commented 2 years ago

Looking for same answer

dlondero commented 2 years ago

Safety checker maybe?

Igglepud commented 2 years ago

Safety checker maybe?

That's my problem. My txt2img.py doesn't look like that. If I ctrl+f, the word "safety" isn't in it.

Igglepud commented 2 years ago

Just wasted another four hours rendering black boxes. So frustrating.

dlondero commented 2 years ago

Well did you pull main branch to get latest commits?

Igglepud commented 2 years ago

Well did you pull main branch to get latest commits?

I used this guide: https://github.com/joelparkerhenderson/stable-diffusion-macos-install-help

Just saw it doesn't come from CompVis, it comes from here:

git clone https://github.com/lstein/stable-diffusion.git

Igglepud commented 2 years ago

OK, cloned the main from here and the files look like they are supposed to. Thanks! I'll run that when I get home. Need to move a bunch of things around now.

2phx commented 2 years ago

https://colab.research.google.com/drive/1nHnP9casbna4ppEuVOM07G3SbjT-ojgk?usp=sharing#scrollTo=yEErJFjlrSWS

There is a line here that does it, didn't try to update it in original repo here, but should work in theory. Or use that colab, no filter there.

def dummy(images, **kwargs): return images, False pipe.safety_checker = dummy

Igglepud commented 2 years ago

Well did you pull main branch to get latest commits?

So with the main branch, I'm getting this:

from imwatermark import WatermarkEncoder

ModuleNotFoundError: No module named 'imwatermark'

I just ran a conda install and a pip install watermark and am getting the same thing.

2phx commented 2 years ago

https://github.com/JustinGuese/stable-diffusor-docker-text2image/blob/master/txt2img.py

On another thread, someone posted fixed txt2img.py

Igglepud commented 2 years ago

https://github.com/JustinGuese/stable-diffusor-docker-text2image/blob/master/txt2img.py

On another thread, someone posted fixed txt2img.py

What's this do? Fix the import issue?

2phx commented 2 years ago

removes safety filter

Igglepud commented 2 years ago

removes safety filter

Thanks! I solved that, but now I'm stuck with the watermark.

2phx commented 2 years ago

Update me if you get watermark solved :)

Igglepud commented 2 years ago

Update me if you get watermark solved :)

I ran pip install imWatermark and changed line 8 to this:

from imWatermark import watermark

Now I'm getting one about no diffusers module.

Igglepud commented 2 years ago

And now it says my model file doesn't exist...

Igglepud commented 2 years ago

OK, running! We'll see if I get any images.

Igglepud commented 2 years ago

"Torch not compiled with CUDA enabled"...

Igglepud commented 2 years ago

Running again, this time with CUDA. Didn't know I even had a GPU in this thing.

Except it still says I don't have CUDA installed. WTF? I just ran the command from here:

https://pytorch.org/get-started/locally/

Igglepud commented 2 years ago

Tediously going through .py files as they crash and changing all "cuda" references to "cpu"

Igglepud commented 2 years ago

Update me if you get watermark solved :)

I deleted the watermark. Maybe that's naughty, but now it runs. Getting weird memory errors, but I can fix that (I think). Going to close this since my original issue is resolved.

RahulBhalley commented 2 years ago

What prompt did you guys put for NSFW? I couldn't get anything dirty even after removing safety check.

Ccode-lang commented 1 year ago

What prompt did you guys put for NSFW? I couldn't get anything dirty even after removing safety check.

You are not supposed to use this model for NSFW. As said before:

Stop generating porn.

RahulBhalley commented 1 year ago

Everyone has freedom to do what they want to.

Cyberes commented 1 year ago

What prompt did you guys put for NSFW? I couldn't get anything dirty even after removing safety check.

"little girl"

RahulBhalley commented 1 year ago

"little girl"

Umm, I'd rather write something else.

docteurzoidberg commented 1 year ago

seems to have trouble drawing a duck's duckbill correctly without triggering the nfsw, almost all prompt i try ends with lots of nsfw triggerers

Avishka-Perera commented 1 year ago

After instantiating the pipeline, just before feeding the prompts, do this

def disabled_safety_checker(images, clip_input):
    if len(images.shape) == 4:
        num_images = images.shape[0]
        return images, [False]*num_images
    else:
        return images, False
pipeline.safety_checker = disabled_safety_checker

This will turn off the NSFW checker. Make sure to disable this after doing all the configurations of the pipeline. Else it might throw errors. example:

# instantiate and configure the pipeline
model_id = "CompVis/stable-diffusion-v1-4"
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
pipe.enable_attention_slicing() # saves GPU memory
pipe.enable_xformers_memory_efficient_attention() # speeds inferencing

# disables safety checks
def disabled_safety_checker(images, clip_input):
    if len(images.shape)==4:
        num_images = images.shape[0]
        return images, [False]*num_images
    else:
        return images, False
pipe.safety_checker = disabled_safety_checker

# generate and save images
pipe_res = pipe("An astronaut riding a horse on a desert", num_inference_steps=50, guidance_scale=7.5)
image = pipe_res.images[0]
image.save(f"results/astronaut.jpg")