How to remove the 18+ safety filter of image generation AI 'Stable Diffusion'

Stable Diffusion , an AI that generates images according to text instructions, is equipped with a safety filter that blacks out images that contain adult expressions such as sexy depictions. A method to remove this safety filter is shared on the overseas bulletin board Reddit.
Tutorial: How to Remove the Safety Filter in 5 seconds : StableDiffusion
https://www.reddit.com/r/StableDiffusion/comments/wv2nw0/tutorial_how_to_remove_the_safety_filter_in_5/
Stable Diffusion is an AI that generates images that match the text when you input text, and has been attracting a lot of attention since it was released to the public in August 2022. You can understand what kind of images you can generate with Stable Diffusion by reading the article below.
The AI ``Stable Diffusion'' that creates pictures and photos that look like they were drawn by humans according to keywords has been released to the public, so I tried using it - GIGAZINE

Stable Diffusion can be executed on a PC equipped with an NVIDIA GPU or a Google Python execution environment , but if you generate an image that contains adult expressions such as sexy depictions, it will be automatically blacked out. When I tried inputting the sentence 'sexy woman' into Stable Diffusion, which runs on Google's Python execution environment, I received a notification saying, 'An image that should not be viewed was detected and has been replaced with a pitch-black image.' was displayed, and instead of a sexy woman, a pitch black image was displayed.
Stable Diffusion does not generate images that should not be viewed, but rather checks whether the image is a cautionary image after generating the image. Therefore, by rewriting the 'image check function' part of the source code, it is possible to generate warning images without any problems. This image check function disabling method is being shared on the overseas bulletin board Reddit. The shared method is intended for users who clone Stable Diffusion from the GitHub repository .
·step 1
Create a backup of 'txt2img.py' located in the 'scripts' folder
・Step 2
Open 'txt2img.py' in an editor and look for the following line (usually line 309)
x_checked_image, has_nsfw_concept = check_safety(x_samples_ddim)
・Step 3
Rewrite the line found in step 2 as follows, keeping the indentation
x_checked_image = x_samples_ddim
If you follow the steps above, you will be able to disable the warning image check function. Furthermore, if you want to disable loading of the caution image model, you can delete the following three lines (usually lines 26 to 28) included in 'txt2img.py'. However, please be aware that if you create a cautionary image in an online environment such as Google Colab, it may be considered a violation of the terms and your account may be deleted. It is safe to generate images with caution in the local environment.
safety_model_id = 'CompVis/stable-diffusion-safety-checker'
safety_feature_extractor = AutoFeatureExtractor.from_pretrained(safety_model_id)
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id)
Since the public release of Stable Diffusion, desktop apps and smartphone apps that can generate images using Stable Diffusion have been actively developed, but some of these apps have the warning image check function disabled. Distributed in The 'NMKD Stable Diffusion GUI', which explains how to use it in the article below, also has the warning image check function disabled, and can output images containing adult depictions without blacking out.
A summary of how to use the ``NMKD Stable Diffusion GUI'' that allows you to easily install the image generation AI ``Stable Diffusion'' on Windows for free, and you can easily understand the tips for spell settings and image generation - GIGAZINE

Related Posts:
in Software, , Posted by log1o_hf