-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
Hi, I have a problem with InceptionV3 tflite model executed on MLKit SDK. I'm not using the ILSVRC Dataset for reasons of storage space and execution time. I'm using the Caltech Dataset , find it here. I have also remove categories that Inception V3 is not able to recognize. I'm doing a comparison of the new Mobile Machine Learning SDKs, and i try to use the new Snapdragon Neural Processing Engine (SNPE) and MLKit. I ran inceptionV3 on both SDKs, and with SNPE I have reached the 82% of correct classifications, and with MLKit the 47%. For MlKit, I have download the tflite float model from here.
I build the network with the following code:
long startBuild = SystemClock.elapsedRealtime();
FirebaseLocalModelSource localSource =
new FirebaseLocalModelSource.Builder("inception_v3") // Assign a name for this model
.setAssetFilePath("inception_v3.tflite")
.build();
FirebaseModelManager.getInstance().registerLocalModelSource(localSource);
FirebaseModelOptions options = new FirebaseModelOptions.Builder()
.setLocalModelName("inception_v3")
.build();
FirebaseModelInterpreter firebaseInterpreter =
FirebaseModelInterpreter.getInstance(options);
FirebaseModelInputOutputOptions inputOutputOptions =
new FirebaseModelInputOutputOptions.Builder()
.setInputFormat(0, FirebaseModelDataType.FLOAT32, new int[]{1, 299, 299, 3})
.setOutputFormat(0, FirebaseModelDataType.FLOAT32, new int[]{1, 1001})
.build();
long endBuild = SystemClock.elapsedRealtime();
And then I preprocess image:
resized_image = Bitmap.createScaledBitmap(image, 299,299, false);
input = new float[1][299][299][3];
for (int x = 0; x < 299; x++) {
for (int y = 0; y < 299; y++) {
int pixel = resized_image.getPixel(x, y);
// Normalize channel values to [0.0, 1.0]. This requirement varies by
// model. For example, some models might require values to be normalized
// to the range [-1.0, 1.0] instead.
float b = ((pixel) & 0xFF);
float g = ((pixel >> 8) & 0xFF);
float r = ((pixel >> 16) & 0xFF);
input[batchNum][x][y][0] = (r - 127) / 128.0f;
input[batchNum][x][y][1] = (g - 127) / 128.0f;
input[batchNum][x][y][2] = (b - 127) / 128.0f;
//input[batchNum][x][y][0] = (Color.red(pixel) - 128) / 128.0f;
//input[batchNum][x][y][1] = (Color.green(pixel) - 128) / 128.0f;
//input[batchNum][x][y][2] = (Color.blue(pixel) - 128) / 128.0f;
}
}
inputs = new FirebaseModelInputs.Builder()
.add(input) // add() as many input arrays as your model requires
.build();
Task<FirebaseModelOutputs> task = firebaseInterpreter.run(inputs, inputOutputOptions);
Metadata
Metadata
Assignees
Labels
No labels