Skip to content

Instantly share code, notes, and snippets.

Did you do good today?

Mirosław Stanek frogermcs

Did you do good today?
Block or report user

Report or block frogermcs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View test_results
Not true that <{0=1, 1=1, 2=1, 3=3, 4=0, 5=2, 6=1, 7=0, 8=1, 9=2, 10=2, 11=0, ... 29=1, 30=2, 31=3}>
contains exactly <{0=1, 1=1, 2=1, 3=3, 4=0, 5=2, 6=1, 7=0, 8=1, 9=2, 10=2, 11=0, ... 29=1, 30=2, 31=3}>.
It has the following entries with matching keys but different values: {16=(expected 2 but got 3), 20=(expected 2 but got 1)}
at com.frogermcs.imageclassificationtester.MLModelTest.testClassificationBatch(
public class MLModelTest {
/* ... */
public void testClassificationBatch() throws IOException {
ModelTestActivity activity = mainActivityActivityRule.getActivity();
ModelClassificator modelClassificator = new ModelClassificator(activity, new FlowersConfig());
public class MLModelTest {
public ActivityTestRule<ModelTestActivity> mainActivityActivityRule = new ActivityTestRule<>(ModelTestActivity.class);
public void testClassificationUI() {
ModelTestActivity activity = mainActivityActivityRule.getActivity();
public class ModelTestActivity extends AppCompatActivity {
private ImageView ivPreview;
private TextView tvClassification;
private ModelClassificator modelClassificator;
protected void onCreate(@Nullable Bundle savedInstanceState) {
from PIL import Image
VAL_BATCH_DIR = "validation_batch"
!mkdir {VAL_BATCH_DIR}
# Export batch to *.jpg files with specific naming convention.
# Make sure they are exported in the full quality, otherwise the inference
# process will return different results.
for n in range(32):
public class ModelClassificator {
private static final int MAX_CLASSIFICATION_RESULTS = 3;
private static final float CLASSIFICATION_THRESHOLD = 0.2f;
private final Interpreter interpreter;
private final List<String> labels;
private final ModelConfig modelConfig;
public ModelClassificator(Context context,
ModelConfig modelConfig) throws IOException {
public class ClassificationFrameProcessor implements FrameProcessor {
private final ModelClassificator modelClassificator;
private final ClassificationListener classificationListener;
public ClassificationFrameProcessor(ModelClassificator modelClassificator,
ClassificationListener classificationListener) {
this.modelClassificator = modelClassificator;
this.classificationListener = classificationListener;
public class MainActivity extends AppCompatActivity
implements ClassificationFrameProcessor.ClassificationListener {
private CameraView cameraView;
private TextView tvClassification;
private ClassificationFrameProcessor classificationFrameProcessor;
protected void onCreate(Bundle savedInstanceState) {
View outputs
Output, CoreML
(CPU) Prediction for Golden Retriever: golden retriever 0.611853480339
(GPU) Prediction for laptop: notebook 0.515091240406
Output, TensorFlow
Prediction for Golden Retriever: golden retriever 0.61186796
Prediction for laptop: notebook 0.51475537
TF_INPUT_TENSOR = 'input:0'
TF_OUTPUT_TENSOR = 'MobilenetV2/Predictions/Reshape_1:0'
with tf.Session(graph = g) as sess:
tf_laptop_out =, feed_dict={TF_INPUT_TENSOR: img_laptop_tf})
tf_golden_out =, feed_dict={TF_INPUT_TENSOR: img_golden_tf})
tf_laptop_out = tf_laptop_out.flatten()
tf_golden_out = tf_golden_out.flatten()
laptop_idx = np.argmax(tf_laptop_out)
golden_idx = np.argmax(tf_golden_out)
You can’t perform that action at this time.