首页 > 其他分享 >Diffusers去除NSFW限制

Diffusers去除NSFW限制

时间:2023-11-26 14:56:55浏览次数:28  
标签:__ image Diffusers pipe StableDiffusionPipeline NSFW 去除 import

title: Diffusers去除NSFW限制
banner_img: https://drive.studyinglover.com/api/raw/?path=/photos/blog/background/1679397024795.jpeg
date: 2023-6-11 0:02:00
tags:
- 文字生成图片

众所周知,涩涩是文字生成图片技术发展的重大推动力 . Huggingface的diffusers封装了大量的算法用于生成图片。但是,很不幸的,diffusers会检测生成的图片是否存在NSFW(not safe for work)的内容,这就给我们涩涩带来了不必要的麻烦。所以我将介绍如何去除限制

该方法来自网友,原链接

先给一段示例代码

import numpy as np
import matplotlib.pyplot as plt
from diffusers import StableDiffusionPipeline
import cv2 as cv
if __name__ == '__main__':
	pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
	new_image = pipe(prompt, num_inference_steps=20).images[0]
	plt.save('image.png',new_image)

我们只需要设置StableDiffusionPipeline 这个类的safety_checker函数,更改之后的代码

import numpy as np
import matplotlib.pyplot as plt
from diffusers import StableDiffusionPipeline
import cv2 as cv
def dummy(images, **kwargs): 
	return images, False
if __name__ == '__main__':
	pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
	pipe.safety_checker = dummy
	new_image = pipe(prompt, num_inference_steps=20).images[0]
	plt.save('image.png',new_image)

成功实现涩涩自由

标签:__,image,Diffusers,pipe,StableDiffusionPipeline,NSFW,去除,import
From: https://www.cnblogs.com/studyinglover/p/17857220.html

相关文章

  • riffusion调用diffusers出错:No module named ‘diffusers.modeling_utils
    追溯错误来源:C:\Users\Administrator\riffusion-main\riffusion\riffusion_pipeline.pyfromdiffusers.pipline_utilsimportDiffusionPipeline 意思是在安装路径里有个代码想import库的时候无法找到“diffusers.modeling_utils”。 查错:是diffusers不存在这个库吗?更新......
  • springboot去除内嵌tomcat
    springboot去除内嵌tomcat步骤在pom文件中加入以下代码点击查看代码<!--多模块排除内置tomcat--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> ......
  • leet code 316. 去除重复字母
    316.去除重复字母题目描述给你一个字符串s请你去除字符串中重复的字母使得每个字母只出现一次。需保证返回结果的字典序最小(要求不能打乱其他字符的相对位置)。示例1:输入:s="bcabc"输出:"abc"示例2:输入:s="cbacdcbc"输出:"acdb"提示:s由小写英文字母组成题目解析考虑从前往......
  • java 去除首尾指定字符
    /***删除字符串首尾指定字符*/publicstaticStringcustomTrim(Stringstr,charc){char[]chars=str.toCharArray();intlen=chars.length;intst=0;while((st<len)&&(chars[st]==c)){......
  • 新版本 el-input 不支持 v-model.trim,自定义指令去除首尾空格
    问题场景<el-inputtype="textarea"v-model.trim="value"/>多行文本输入框无法换行。经测试,去掉.trim修饰符后,就可正常换行了。从官网文档,发现element-ui新版本不支持v-model修饰符。因此,若在新版本的element-ui的el-input中使用v-model.trim,会发生以下问题......
  • python-tkinter去除命令日志
    Python打包exe文件后,执行exe文件总会打开命令行窗口,通过查找相关解决的方法,经过亲测,介绍几种可行的方案。修改文件名后缀将.py文件改成.pyw文件(使用的是脚本解析程序pythonw.exe)修改打包命令pyinstaller-i添加图标        -w去除命令行解决报错AttributeError......
  • 去除:Vue项目打包后生成的.map文件&文件hash值命名
    在vue.config.js文件中设置productionSourceMap和filenameHashing项为false即可。//vue.config.js文件module.exports={outputDir:'dist',assetsDir:'assets',publicPath:'./',//需注意是相对路径,不然dist打包访问后就会出现空白问题。productionSourceMap......
  • 单个变量添加、去除=空格、转行、等
    一.单个变量添加去除转行空格datat1; a=cats("aaa",'0a'x); b=cats("aaa"); c=compress(a,'0a'x); ifa=bthenf1=1; elsef1=2; ifb=csthenf2=1; elsef2=2; OUTPUT;run;编码表链接:十六进制的字符对照表_16进制代码对照表-CSDN博客......
  • input type="number" 时去除上下按钮样式
    全局样式/*取消[type='number']的input的上下箭头*/input::-webkit-inner-spin-button{-webkit-appearance:none!important;}input::-webkit-outer-spin-button{-webkit-appearance:none!important;}input[type="number"]{-moz-appearance......
  • 取标签列表的最后两位,并去除最后一个逗号,没有标签就用标题
    defupdate_biaoqian(tag_list,title):iftag_list==['']ortag_list==[]:print('没有标签,取标题作为标签')titless=re.sub('\s',',',title)tag_list=title.replace('、',','......