|
9 | 9 | ### C++参考:[TensorflowLite-Api](https://tensorflow.google.cn/lite/api_docs/cc) |
10 | 10 | ### JavaScript参考[JS相关文档](https://js.tensorflow.org/api/latest/) |
11 | 11 | >>> 其中Python、C++均有两种数据喂入的方式,可根据需求选择pb模型或tfLite文件,详细请参考上面的链接.Java的目前只能加载pb模型。其他的平台可自行[百度](https://www.baidu.com) |
12 | | -### [pb模型下载](https://github.com/devzwy/NSFW-Python/tree/master/model) |
13 | 12 | ### 本项目移除测试图片,请下载Demo后自行配图测试 |
14 | 13 | #### 即将优化Demo使用MVVM模式,可用作开发脚手架使用 |
15 | 14 | `Kotlin+okhttp3+rxjava2+retrofit2+koin+glide+greendao+databinding+Livedata` |
16 | 15 |
|
17 | 16 |  |
18 | 17 |
|
19 | 18 |
|
20 | | -#### 1.3.2版本优化说明: |
21 | | -模型大小改动较大,原量化模型虽小(6M),但对GPU加速支持不友好,新模型大约26M,完美支持GPU加速并优化识别精度,加速效果明显。建议全部升级该版本。__新版本的GPU加速默认开启状态__,SDK默认会检测设备是否支持,不支持时会自动取消加速(老版本会奔溃) |
| 19 | +#### 1.3.5版本优化说明: |
| 20 | +模型大小改动较大,原量化模型虽小(6M),但对GPU加速支持不友好,新模型大约23M,完美支持GPU加速并优化识别精度,加速效果明显。建议全部升级该版本。__新版本的GPU加速默认开启状态__,SDK默认会检测设备是否支持,不支持时会自动取消加速(老版本会奔溃) |
| 21 | +#### 1.3.4版本特殊说明: |
| 22 | +由于模型支持GPU加速后模型文件变大,部分用户反馈Apk体积增大,考虑到这方面,在1.3.4版本中增加初始化方式,可通过传入模型文件的路径进行初始化,该模型在`/OpenNSFW/src/main/assets/nsfw.tflite`处,可自行下载并存放适当位置,比如放在后台,app端自行下载后初始化NSFW后使用。初始化方式: |
| 23 | +``` |
| 24 | + Classifier.Build() |
| 25 | +// .context(this) //1.3.4版本可不用调用该代码。其他版本必须调用,否则会有异常抛出 |
| 26 | +// .isOpenGPU(true)//默认不开启GPU加速,默认为true |
| 27 | +// .numThreads(100) //分配的线程数 根据手机配置设置,默认1 |
| 28 | + .nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //1.3.4版本必须配置模型存放路径,否则会有异常抛出 |
| 29 | + .build() |
| 30 | +``` |
22 | 31 |
|
23 | | -### 使用方式一 (建议) |
| 32 | + |
| 33 | +### 开始使用 |
24 | 34 | - 添加远程仓库支持 |
25 | 35 | ``` |
26 | 36 | allprojects { |
27 | 37 | repositories { |
28 | | - ... |
29 | 38 | maven { url 'https://jitpack.io' } |
30 | 39 | } |
31 | 40 | } |
32 | 41 | ``` |
33 | 42 |
|
34 | | -- 配置依赖 [](https://jitpack.io/#devzwy/open_nsfw_android) (编译过程报错时请自行使用梯子) |
| 43 | +- 配置依赖(如果需要自行配置模型路径可适用1.3.4版本,否则请使用最新版本,版本号看右边的icon中的数字) [](https://jitpack.io/#devzwy/open_nsfw_android) (编译过程报错时请自行使用梯子) |
35 | 44 |
|
36 | 45 | ``` |
37 | 46 | dependencies { |
|
41 | 50 |
|
42 | 51 | ``` |
43 | 52 |
|
44 | | -### 使用方式二,源码依赖方式 |
45 | | -- 克隆源码 |
46 | | -``` |
47 | | - git clone 'https://github.com/devzwy/open_nsfw_android.git' |
48 | | -``` |
49 | | - |
50 | | -- 项目中依赖lib |
51 | | - |
52 | | -``` |
53 | | - dependencies { |
54 | | - implementation project(path: ':OpenNSFW') |
55 | | - } |
56 | | -
|
57 | | -``` |
58 | | -- 扫描时报如下错误 |
59 | | -``` |
60 | | -java.lang.NullPointerException: Attempt to invoke virtual method 'com.zwy.nsfw.api.NsfwBean com.zwy.nsfw.Classifier.run(android.graphics.Bitmap)' on a null object reference |
61 | | -``` |
62 | | -__无论哪种方式依赖项目,都需要添加如下代码__ |
| 53 | +- 以下配置1.3.4版本可跳过 |
| 54 | +__除1.3.4版本外,其他任何版本均需要添加如下代码,否则会有`java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed`异常抛出,因为assets下模型文件较大__ |
63 | 55 | ``` |
64 | 56 | android { |
65 | | - ... |
66 | 57 | aaptOptions { |
67 | 58 | noCompress "tflite" |
68 | 59 | } |
69 | 60 | } |
70 | 61 | ``` |
71 | 62 |
|
72 | 63 |
|
73 | | -- 使用(请使用最新版本1.3.2) |
74 | 64 | - 建议在Application中全局初始化 |
75 | 65 |
|
76 | 66 | ``` |
77 | 67 | Classifier.Build() |
78 | | - .context(this) //必须调用 否则会有异常抛出 |
79 | | -// .isOpenGPU(true)//是否开启GPU加速 ,默认true |
80 | | -// .numThreads(10) //分配的线程数 根据手机配置设置,默认1 |
| 68 | + .context(this) //1.3.4版本可不用调用该代码。其他版本必须调用,否则会有异常抛出 |
| 69 | +// .isOpenGPU(true)//默认不开启GPU加速,默认为true |
| 70 | +// .numThreads(100) //分配的线程数 根据手机配置设置,默认1 |
| 71 | +// .nsfwModuleFilePath("/data/user/0/com.zwy.demo/files/nsfw.tflite") //1.3.4版本必须配置模型存放路径,否则会有异常抛出 |
81 | 72 | .build() |
82 | 73 | ``` |
83 | 74 | - 使用: |
|
0 commit comments