pull/34/head
jason 6 years ago
parent 5854f4737b
commit 7da89c89b8
  1. 41
      nsfw/src/main/java/com/zwy/nsfw/Classifier.java
  2. 4
      nsfw/src/main/java/com/zwy/nsfw/api/NsfwHelper.java

@ -154,31 +154,6 @@ public abstract class Classifier {
Log.d(TAG, "Timecost to put values into ByteBuffer: " + (endTime - startTime) + "ms");
}
private void pross(int[] data){
int pixel = 0;
long startTime = SystemClock.uptimeMillis();
for (int i = 0; i < getImageSizeX(); ++i) {
for (int j = 0; j < getImageSizeY(); ++j) {
//操作每一个像素
//拿出每一个像素点对应的R、G、B的int值
//对每一个int值减去阈值 R-123 B-104 G-117
//将R、G、B 利用 B、G、R顺序重新写入数组
//将数组传入tflite获取回传结果
final int color = data[pixel++];
int r1 = Color.red(color) - 123;
int g1 = Color.green(color) - 117;
int b1 = Color.blue(color) - 104;
imgData.putFloat(b1);
imgData.putFloat(g1);
imgData.putFloat(r1);
}
}
long endTime = SystemClock.uptimeMillis();
Log.d(TAG, "Timecost to put values into ByteBuffer: " + (endTime - startTime) + "ms");
}
public NsfwBean run(Bitmap bitmap) {
convertBitmapToByteBuffer(bitmap);
long startTime = SystemClock.uptimeMillis();
@ -190,22 +165,6 @@ public abstract class Classifier {
}
/**
* 224 * 224 int颜色值
* @param data
* @return
*/
public NsfwBean run(int[] data){
pross(data);
long startTime = SystemClock.uptimeMillis();
float[][] labelProbArray = new float[1][2];
tflite.run(imgData, labelProbArray);
long endTime = SystemClock.uptimeMillis();
Log.d(TAG, "Timecost to run model inference: " + (endTime - startTime) + "ms");
return new NsfwBean(labelProbArray[0][0], labelProbArray[0][1]);
}
/**
* Closes the interpreter and model to release resources.
*/

@ -37,10 +37,6 @@ public class NsfwHelper {
return classifier.run(bitmap);
}
public NsfwBean scanByIntColorsSyn(int[] colors){
return classifier.run(colors);
}
public void scanBitmap(final Bitmap bitmap, final OnScanBitmapListener onScanBitmapListener) {
new Thread(new Runnable() {

Loading…
Cancel
Save