Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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
You can’t perform that action at this time.