Skip to content

Instantly share code, notes, and snippets.

@frogermcs
Created June 9, 2019 13:35
Show Gist options
  • Save frogermcs/698e792a82ee4e5b9db956e758ff62d7 to your computer and use it in GitHub Desktop.
Save frogermcs/698e792a82ee4e5b9db956e758ff62d7 to your computer and use it in GitHub Desktop.
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MLModelTest {
/* ... */
@Test
public void testClassificationBatch() throws IOException {
ModelTestActivity activity = mainActivityActivityRule.getActivity();
ModelClassificator modelClassificator = new ModelClassificator(activity, new FlowersConfig());
Map<Integer, Integer> batchClassificationResults = new HashMap<>();
Map<Integer, Integer> batchClassificationExepectedResults = new HashMap<>();
String[] valBatchImages = activity.getAssets().list("val_batch");
for (String valImagePath : valBatchImages) {
ValImageInfo valImageInfo = new ValImageInfo(valImagePath);
Bitmap bmp = TestUtils.getBitmapFromAsset(activity.getAssets(), "val_batch/" + valImagePath);
//Does nothing, it's just test's preview
activity.setImagePreview(bmp);
List<ClassificationResult> classificationResults = modelClassificator.process(bmp);
ClassificationResult topClassificationResult = classificationResults.get(0);
batchClassificationResults.put(valImageInfo.n, topClassificationResult.labelIndex);
batchClassificationExepectedResults.put(valImageInfo.n, valImageInfo.tflitePredict);
//Does nothing, it's just test's preview
activity.showClassificationResults(classificationResults);
}
Truth.assertThat(batchClassificationResults).isNotEmpty();
Truth.assertThat(batchClassificationResults).containsExactlyEntriesIn(batchClassificationExepectedResults);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment