This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void runInferenceOnQuantizedModel(ByteBuffer byteBufferToClassify) { | |
byte[][] result = new byte[1][labels.size()]; | |
interpreter.run(byteBufferToClassify, result); | |
float[][] resultFloats = new float[1][labels.size()]; | |
byte[] bytes = result[0]; | |
for (int i = 0; i < bytes.length; i++) { | |
float resultF = (bytes[i] & 0xff) / 255.f; | |
resultFloats[0][i] = resultF; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private byte[] pixelToChannelValuesQuant(int pixel) { | |
byte[] rgbVals = new byte[3]; | |
rgbVals[0] = (byte) ((pixel >> 16) & 0xFF); | |
rgbVals[1] = (byte) ((pixel >> 8) & 0xFF); | |
rgbVals[2] = (byte) ((pixel) & 0xFF); | |
return rgbVals; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_training_data.zip | |
|____accordion | |
| |____001.jpg | |
| |____002.jpg | |
| |____003.jpg | |
|____bass_guitar | |
| |____hofner.gif | |
| |____p-bass.png | |
|____clavier | |
|____well-tempered.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(MLModelTest.java:72) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
@LargeTest | |
public class MLModelTest { | |
/* ... */ | |
@Test | |
public void testClassificationBatch() throws IOException { | |
ModelTestActivity activity = mainActivityActivityRule.getActivity(); | |
ModelClassificator modelClassificator = new ModelClassificator(activity, new FlowersConfig()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
@LargeTest | |
public class MLModelTest { | |
@Rule | |
public ActivityTestRule<ModelTestActivity> mainActivityActivityRule = new ActivityTestRule<>(ModelTestActivity.class); | |
@Test | |
public void testClassificationUI() { | |
ModelTestActivity activity = mainActivityActivityRule.getActivity(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModelTestActivity extends AppCompatActivity { | |
private ImageView ivPreview; | |
private TextView tvClassification; | |
private ModelClassificator modelClassificator; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(com.frogermcs.imageclassificationtester.test.R.layout.activity_model_test); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
NewerOlder