Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
赵文文 committed Sep 19, 2020
1 parent 5692c3c commit b0f57ac
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
[![](https://jitpack.io/v/devzwy/open_nsfw_android.svg)](https://jitpack.io/#devzwy/open_nsfw_android) [![](https://img.shields.io/badge/Base-TensorFlow-brightgreen.svg)](https://github.com/devzwy/open_nsfw_android) [![](https://img.shields.io/badge/license-Apache%202-green.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-赵文贇-orange.svg)](https://github.com/devzwy/open_nsfw_android) [![](https://img.shields.io/badge/QQ-3648415-brightgreen.svg)](https://github.com/devzwy/KUtils) [![](https://img.shields.io/badge/Mail-dev_zwy@aliyun.com-green.svg)](https://github.com/devzwy/open_nsfw_android) ![Mozilla Add-on](https://img.shields.io/amo/stars/dustman.svg?label=stars&logo=1&logoColor=1&style=popout)

[English Doc](https://github.com/devzwy/open_nsfw_android/blob/dev/README_EN.md)


### 色情图片离线识别,基于TensorFlow实现。识别只需20ms,可断网测试,成功率99%,调用只要一行代码,从雅虎的开源项目open_nsfw移植,该模型文件可用于iOS、java、C++等平台
### iOS请参考:[issues13](https://github.com/devzwy/open_nsfw_android/issues/13)
### Python参考:[NSFW-Python](https://github.com/devzwy/NSFW-Python)[Python-TensorflowLite-Api](https://tensorflow.google.cn/api_docs/python/tf/lite)[Python-Tensorflow-Api](https://tensorflow.google.cn/api_docs/python/tf)
Expand All @@ -10,7 +13,7 @@
### JavaScript参考[JS相关文档](https://js.tensorflow.org/api/latest/)
>>> 其中Python、C++均有两种数据喂入的方式,可根据需求选择pb模型或tfLite文件,详细请参考上面的链接.Java的目前只能加载pb模型。其他的平台可自行[百度](https://www.baidu.com)
### 本项目移除测试图片,请下载Demo后自行配图测试
#### 即将优化Demo使用MVVM模式,可用作开发脚手架使用
#### Demo使用MVVM模式,可用作开发脚手架使用
`Kotlin+okhttp3+rxjava2+retrofit2+koin+glide+greendao+databinding+Livedata`

![MVVM](https://github.com/devzwy/open_nsfw_android/blob/dev/img/4.jpg)
Expand All @@ -23,7 +26,7 @@
```
Classifier.Build()
// .context(this) //1.3.4版本可不用调用该代码。其他版本必须调用,否则会有异常抛出
// .isOpenGPU(true)//默认不开启GPU加速,默认为true
// .isOpenGPU(true)//GPU加速
// .numThreads(100) //分配的线程数 根据手机配置设置,默认1
.nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //1.3.4版本必须配置模型存放路径,否则会有异常抛出
.build()
Expand Down Expand Up @@ -66,7 +69,7 @@ __除1.3.4版本外,其他任何版本均需要添加如下代码,否则会
```
Classifier.Build()
.context(this) //1.3.4版本可不用调用该代码。其他版本必须调用,否则会有异常抛出
// .isOpenGPU(true)//默认为true开启GPU加速
// .isOpenGPU(true)//GPU加速
// .numThreads(100) //分配的线程数 根据手机配置设置,默认1
// .nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //1.3.4版本必须配置模型存放路径,否则会有异常抛出
.build()
Expand Down
98 changes: 98 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# open_nsfw_android
[![](https://jitpack.io/v/devzwy/open_nsfw_android.svg)](https://jitpack.io/#devzwy/open_nsfw_android) [![](https://img.shields.io/badge/Base-TensorFlow-brightgreen.svg)](https://github.com/devzwy/open_nsfw_android) [![](https://img.shields.io/badge/license-Apache%202-green.svg)](https://www.apache.org/licenses/LICENSE-2.0)
[![](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-jason-orange.svg)](https://github.com/devzwy/open_nsfw_android) [![](https://img.shields.io/badge/QQ-3648415-brightgreen.svg)](https://github.com/devzwy/KUtils) [![](https://img.shields.io/badge/Mail-dev_zwy@aliyun.com-green.svg)](https://github.com/devzwy/open_nsfw_android) ![Mozilla Add-on](https://img.shields.io/amo/stars/dustman.svg?label=stars&logo=1&logoColor=1&style=popout)

[中文文档](https://github.com/devzwy/open_nsfw_android/blob/dev/README.md)


### The off-line identification of pornographic images is based on tensorflow. Identification only takes 20ms, can be disconnected test, the success rate is 99%, call as long as a line of code, open from the open source project of Yahoo_ Nsfw transplantation, the model file can be used in IOS, Java, C + + and other platforms
### iOS like this:[issues13](https://github.com/devzwy/open_nsfw_android/issues/13)
### Python like this:[NSFW-Python](https://github.com/devzwy/NSFW-Python)[Python-TensorflowLite-Api](https://tensorflow.google.cn/api_docs/python/tf/lite)[Python-Tensorflow-Api](https://tensorflow.google.cn/api_docs/python/tf)
### Java like this:[Tensorflow-Api](https://tensorflow.google.cn/api_docs/java/reference/org/tensorflow/package-summary)
### C++ like this:[TensorflowLite-Api](https://tensorflow.google.cn/lite/api_docs/cc)
### JavaScript like this[js doc](https://js.tensorflow.org/api/latest/)
>>> Python and C + + have two ways to feed data. You can select PB model or tflite file according to your needs. Please refer to the above link for details. Java can only load PB model at present. Other platforms can [Google]https://www.google.cn )
### This project removes the test picture, please download demo and test by yourself
#### Demo uses MVVM mode, which can be used to develop scaffolding
`Kotlin+okhttp3+rxjava2+retrofit2+koin+glide+greendao+databinding+Livedata`

![MVVM](https://github.com/devzwy/open_nsfw_android/blob/dev/img/4.jpg)


#### 1.3.5 optimization description:
Although the original quantization model is small (6m), it is not friendly to GPU acceleration. The new model is about 23m, which perfectly supports GPU acceleration and optimizes the recognition accuracy. The acceleration effect is obvious. It is recommended to upgrade all of this version__ The new version of GPU acceleration is on by default__ By default, the SDK will detect whether the device supports it. If it does not, it will automatically cancel the acceleration (the old version will crash)
#### 1.3.4 Special description of this version:
Since the model supports GPU acceleration, the model file becomes larger, and some users feedback that the APK volume increases. In this regard, the initialization method is added in version 1.3.4, which can be initialized through the path of the model file. The model can be initialized in '/ opennsfw / SRC / main / assets/ nsfw.tflite `You can download and store it in an appropriate location by yourself, such as in the background, and the app will download it by itself Use after nsfw. Initialization mode:
```
Classifier.Build()
// .context(this) //Version 1.3.4 does not need to call this code. Other versions must be called, otherwise an exception will be thrown
// .isOpenGPU(true)//GPU acceleration
// .numThreads(100) //The number of threads allocated is set according to the phone configuration. The default value is 1
.nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //Version 1.3.4 must configure the model storage path, otherwise an exception will be thrown
.build()
```


### dependencies
- add jitpack repository
```
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```

- Configuration dependency (if you need to configure the model path by yourself, version 1.3.4 is applicable; otherwise, please use the latest version. For version number, see the number in the icon on the right) [![](https://jitpack.io/v/devzwy/open_nsfw_android.svg)](https://jitpack.io/#devzwy/open_nsfw_android)

```
dependencies {
//versionCode:The latest version number in the small icon above
implementation 'com.github.devzwy:open_nsfw_android:[versionCode]'
}
```

- The following configuration version 1.3.4 can be skipped
__Except for version 1.3.4, the following code needs to be added to any other version, otherwise there will be`java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed`Exception thrown, because the model file under assets is large__
```
android {
aaptOptions {
noCompress "tflite"
}
}
```


- Global initialization in application

```
Classifier.Build()
.context(this) //Version 1.3.4 does not need to call this code. Other versions must be called, otherwise an exception will be thrown
// .isOpenGPU(true)//GPU acceleration
// .numThreads(100) //The number of threads allocated is set according to the phone configuration. The default value is 1
// .nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //Version 1.3.4 must configure the model storage path, otherwise an exception will be thrown
.build()
```
- use:

```
//like this:
val nsfwBean = Classifier.Build().context(this).build().run(bitmap)
//or like this
val nsfwBean = bitmap.getNsfwScore()
//or like this
val nsfwBean = file.getNsfwScore()
nsfwBean.sfw ... The more approximate the value, the safer it is
nsfwBean.nsfw ... The more approximate the value, the more dangerous it is
```
### android install[click me to installing](http://d.6short.com/q9cv)

### Scan qrcode to download

![pic](https://github.com/devzwy/open_nsfw_android/blob/dev/img/2.png)

### Demo run results:

![pic2](https://github.com/devzwy/open_nsfw_android/blob/dev/img/1.png)

0 comments on commit b0f57ac

Please sign in to comment.