Hi guys again,
First of all, thanks for releasing the Tensorflow support with the latest firmware. I am now stuck with the model classification failed issue. I will summarize the process I have gone through so far.
CNN Type
Binary classification. Ouput is simply good or bad. Input size is 100x100x3 (100pixels by 100 pixels, 3 channels).
0) Module using
OpenMV H7 R1
1) Train the model
Used tensorflow with Keras. 2D convolution layer, flattening layer, global average pooling and output layer
2) Converted to tensorflow lite
Followed the guide on the website. Post training quantization: 8 bit flatbuffer quantization through representative dataset. Final size 107KB, small enough to not use a SD card and run on H7 ram using tf.classify. Has no problem with width, height and channel.
My model shows the following output when I use the tf.lite.Interperter
== Input details ==
name: conv2d_input
shape: [ 1 100 100 3]
type: <class 'numpy.uint8'>
index: 23
quantization: (1.0, 0)
== Output details ==
name: Identity
shape: [1 2]
type: <class 'numpy.uint8'>
index: 23
quantization: (1.0, 0)
I also checked the pretrained mobilenet that was provided with the new release. I see that the shape is ok.
== Input details ==
name: input
shape: [ 1 128 128 3]
type: <class 'numpy.uint8'>
index: 88
quantization: (0.0078125, 128)
== Output details ==
name: MobilenetV1/Predictions/Reshape_1
shape: [ 1 1001]
type: <class 'numpy.uint8'>
index: 88
quantization: (0.0078125, 128)
I do notice a difference in quantization where my model is (1.0,0) and the model you provided is (0.0078125, 128). Not sure if this is the problem.
I have attached my tensorflow lite model below:
https://drive.google.com/file/d/1nM-ZAJD6tbOqVWq3NAXJtUy1jP3zm7Nx/view?usp=sharing
The way I approached is simple: I used the example code for person detection and replaced that with my own model. Here’s an example:
import sensor, image, time, os, tf
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 because it is 3 channel
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((100, 100)) # Set 100x100 window, the input is 100x100
sensor.skip_frames(time=2000) # Let the camera adjust.
net = "model_quantized_io2.tflite"
labels = ['bad','good']
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
for obj in tf.classify(net, img, min_scale=0.5, scale_mul=0.5, x_overlap=-1, y_overlap=-1):
print("**********\nDetections at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
for i in range(len(obj.output())):
print("%s = %f" % (labels[i], obj.output()[i]))
img.draw_rectangle(obj.rect())
img.draw_string(obj.x()+3, obj.y()-1, labels[obj.output().index(max(obj.output()))], mono_space = False)
print(clock.fps(), "fps")
Is there anything I am missing? I will go through the entire training process again to check if my tflite model is ok. Do let me know your thoughts.
Thanks again.