This repository was archived by the owner on Apr 8, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork343
🔥🔥🔥色情图片离线识别,基于TensorFlow实现。识别只需20ms,可断网测试,成功率99%,调用只要一行代码,从雅虎的开源项目open_nsfw移植,该模型文件可用于iOS、java、C++等平台
NotificationsYou must be signed in to change notification settings
devzwy/open_nsfw_android
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
该项目从yahoo-open_nsfw移植,本人能力有限,停止维护该库,部分图片识别可能不准确,仅能保证pb模型识别的结果与tflite结果一致,误差不超过0.00001
所有相关数据已放在data目录下,需要自取
⚠️ ⚠️ ⚠️ 已从jCenter仓库迁移到Maven,原引用地址发生变更,建议所有老用户升级到新版本。新版本需要手动下载nsfw.tflite模型初始化使用
iOS请参考:issues13
Java参考:Tensorflow-Api
C++参考:TensorflowLite-Api
JavaScript参考JS相关文档
其中Python、C++均有两种数据喂入的方式,可根据需求选择pb模型或tfLite文件,详细请参考上面的链接.Java的目前只能加载pb模型。其他的平台可自行百度
- 🔥下载模型文件并放入assets目录下
- 🔥开启tflite文件读取支持(解决模型放在assets目录下无法读取的问题。如果模型不放在assets目录下可跳过该步骤)
android { ... aaptOptions { //防止模型被压缩 noCompress "tflite" }}
- 🔥引入依赖
dependencies { ... implementation 'io.github.devzwy:nsfw:1.5.1' }
- 🔥初始化(建议在Application中进行)
class KtApp : Application() { override fun onCreate() { super.onCreate() //开启日志输出,可选 NSFWHelper.openDebugLog() //扫描前必须初始化 NSFWHelper.initHelper( context = this) //初始化api原型 /* NSFW初始化函数 内部日志默认关闭,调试环境可使用openDebugLog()开启日志*/ fun initHelper( context: Context, //建议传入application,传入activity可能会有内存泄漏 modelPath: String? = null,//模型文件路径,为空时将默认从Assets下读取 isOpenGPU: Boolean = true, //是否开启GPU扫描加速,部分机型兼容不友好的可关闭。默认开启 numThreads: Int = 4 //扫描数据时内部分配的线程 默认4 ) } }
- 🔥支持的api列表 带返回值的为同步,传入函数的为异步:
异步识别文件:getNSFWScore(file: File, onResult: ((NSFWScoreBean) -> Unit))
异步识别文件:getNSFWScore(filePath: String, onResult: ((NSFWScoreBean) -> Unit))
同步识别bitmap:getNSFWScore(bitmap: Bitmap): NSFWScoreBean
异步识别bitmap:getNSFWScore(bitmap: Bitmap, onResult: ((NSFWScoreBean) -> Unit))
- 🔥识别结果说明
NSFWScoreBean.sfw ... 非涉黄数值 数值越大约安全 NSFWScoreBean.nsfw ... 涉黄数值 数值越大约危险 NSFWScoreBean.timeConsumingToLoadData ... 装载数据耗时 单位ms NSFWScoreBean.timeConsumingToScanData ... 扫描图片耗时 单位ms
- 🔥调用参考
//异步方式 NSFWHelper.getNSFWScore(item.bitmap) { this.text = "nsfw:${it.nsfwScore}\nsfw:${it.sfwScore}\n扫描耗时:${it.timeConsumingToScanData} ms" if (it.nsfwScore > 0.7) { this.setBackgroundColor(Color.parseColor("#C1FF0000")) } else if (it.nsfwScore > 0.5) { this.setBackgroundColor(Color.parseColor("#C1FF9800")) } else { this.setBackgroundColor(Color.parseColor("#803700B3")) } } //同步方式 NSFWHelper.getNSFWScore(item.bitmap).let { this.text = "nsfw:${it.nsfwScore}\nsfw:${it.sfwScore}\n扫描耗时:${it.timeConsumingToScanData} ms" if (it.nsfwScore > 0.7) { this.setBackgroundColor(Color.parseColor("#C1FF0000")) } else if (it.nsfwScore > 0.5) { this.setBackgroundColor(Color.parseColor("#C1FF9800")) } else { this.setBackgroundColor(Color.parseColor("#803700B3")) } }
🔥 安卓手机直接点我安装
About
🔥🔥🔥色情图片离线识别,基于TensorFlow实现。识别只需20ms,可断网测试,成功率99%,调用只要一行代码,从雅虎的开源项目open_nsfw移植,该模型文件可用于iOS、java、C++等平台
Topics
tensorflow nsfw tensorflow-models tensorflow-examples tensorflow-android tensorflow-gpu tensorflowlite pornography tensorflow-lite nsfw-android tensorflow-lite-nsfw nsfw-filter photographs-to-discern-yellow yellow-chart picture-recognition picture-recognition-sdk photo-recognition-sdk photo-recognition photo-identification
Resources
Stars
Watchers
Forks
Packages0
No packages published