File size: 652 Bytes
c5d43bc
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3
import PIL
from transformers import CLIPImageProcessor
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker

feature_extractor = CLIPImageProcessor.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="feature_extractor")
safety_checker = StableDiffusionSafetyChecker.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="safety_checker")
device = "cpu"

image = PIL.Image.open("/home/patrick/images/0.png")

safety_checker_input = feature_extractor(image, return_tensors="pt").to(device)
image, has_nsfw_concept = safety_checker(images=image, clip_input=safety_checker_input.pixel_values)