Skip to content

Instantly share code, notes, and snippets.

View frogermcs's full-sized avatar
🤓
Did you do good today?

Mirosław Stanek frogermcs

🤓
Did you do good today?
View GitHub Profile
Predicted value for [0, 1] normalization. Label index: 682, confidence: 39%
Predicted value for [-1, 1] normalization. Label index: 682, confidence: 53%
imgUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Compaqarmada7800.jpg/1024px-Compaqarmada7800.jpg"
img = Image.open(requests.get(imgUrl, stream=True).raw)
img.load()
img = img.resize((224, 224), PIL.Image.ANTIALIAS)
# Normalize to [0, 1]
data = np.asarray( img, dtype="int32" ) / 255.0
# Inference on input data normalized to [0, 1]
inputImg = np.expand_dims(data,0).astype(np.float32)
== Input details ==
name: input
shape: [ 1 224 224 3]
type: <class 'numpy.float32’>
== Output details ==
name: MobilenetV2/Predictions/Reshape_1
shape: [ 1 1001]
type: <class 'numpy.float32’>
== Input details ==
name: flatten_input
shape: [ 1 28 28]
type: <class 'numpy.float32'>
== Output details ==
name: dense_2/Softmax
shape: [ 1 10]
type: <class 'numpy.float32'>
interpreter = tf.lite.Interpreter(model_path="mnist.tflite")
interpreter.allocate_tensors()
print("== Input details ==")
print("name:", interpreter.get_input_details()[0]['name'])
print("shape:", interpreter.get_input_details()[0]['shape'])
print("type:", interpreter.get_input_details()[0]['dtype’])
print("\n== Output details ==")
print("name:", interpreter.get_output_details()[0]['name'])
public abstract class ModelConfig {
static final int FLOAT_BYTES_COUNT = 4;
public abstract String getModelFilename();
public abstract String getLabelsFilename();
public abstract int getInputWidth();
public abstract int getInputHeight();
public abstract int getInputSize();
public abstract int getChannelsCount();
public abstract float getMean();
public class ClassificationFrameProcessor implements FrameProcessor {
private final Interpreter interpreter;
private final List<String> labels;
private final ClassificationListener classificationListener;
private final ModelConfig modelConfig;
/* ... */
@Override
public class MainActivity extends AppCompatActivity {
private CameraView cameraView;
private ClassificationFrameProcessor classificationFrameProcessor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public class SimpleObserver<T> implements Observer<T> {
///...
@Override
public void onError(Throwable e) {
view.showGeneralErrorPopup();
loggingManager.logException(e); // <-- !!!!!
}
}
@AutoHandler
public interface PaymentErrorListener {
@ErrorCode(CODE_UNSUPPORTED_PREPAID_CARD)
void onUnsupportedPrepaidCardError();
@ErrorCode(CODE_UNSUPPORTED_CONSUMER_CARD)
void onUnsupportedConsumerCardError();
@ErrorCode(CODE_INSUFFICIENT_FUNDS)