# Image Classification with Transfer Learning On MobileNet issue

**URL:** <https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950>\
**Category:** OpenMV Boards\
**Created:** [May 27, 2021, 10:52pm UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950 "2021-05-27T22:52:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoZen](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@MoZen](https://forums.openmv.io/u/MoZen)\
**Post date:** [May 27, 2021, 10:52pm UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/1 "2021-05-27T22:52:48Z")

</div>

Hi, I am running an image classifier with 3 classes using transfer learning MobilenetV1 on OpenMV, in computer Tensorflow has more than 90% accuracy and on OpenMV, code runs but gives wrong inference results.

Looking at my model with the Netron, it has Sub and Mul layers in the input, but in your Mobilent example it does not have such layers, also I get an error that input should be float32 that I could fix it by converting to float 32 input and that model runs in OpenMv but the zip file size was 11 MBytes so I could not upload it.

In layer 33 of the model also when it’s integer input it, as attached, has the mean layer error;  
Node MEAN (number 33) failed to invoke with status 1,  
but when I convert it to float as I said it does not have that error but gives wring inference results.

[V1\_integer.zip](https://forums.openmv.io/uploads/short-url/dO7d0Fto2BRnBFCqtjlA076XOZu.zip) (2.8 MB)

Here is the OpenMV code;

crb\_threshold = 0.8

# LED setting (1: red, 2: green, 3: blue, 4: IR)

led = pyb.LED(1)  
led.off()  
sensor.reset() # Reset and initialize the sensor.  
sensor.set\_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)  
sensor.set\_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)  
sensor.set\_windowing((128, 128)) # Set 128x128 window.  
sensor.skip\_frames(time=2000) # Let the camera adjust.

# Load the built-in cat dog detection network (the network is in your OpenMV Cam’s firmware).

net = tf.load(‘V1\_integer.tflite’,load\_to\_fb=True)  
labels = [‘bee’,‘butterfly’,‘rhino beetle’]

# Star the clock to measure FPS

clock = time.clock()

# Main while loop

while(True):  
# Measure time  
clock.tick()  
# Get image from camera  
img = sensor.snapshot()

```
for obj in net.classify(img, min_scale=1.0, scale_mul=0.0, x_overlap=0.0, y_overlap=0.0):
    # Give classification scores
    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]))
    # Highlight identified object
    img.draw_rectangle(obj.rect())
    img.draw_string(obj.x()+3, obj.y()-1, labels[obj.output().index(max(obj.output()))], mono_space = False)
    # Light LED if dog detected
    idx = labels.index('rhino beetle')
    if obj.output()[idx] > crb_threshold:
        led.on()
    else:
        led.off()
pyb.delay(1500)
print(clock.fps(), "fps")

```

How can I fix this issue?

Thanks

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [May 28, 2021, 2:28am UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/2 "2021-05-28T02:28:42Z")

</div>

Hi, we just use EdgeImpulse based networks. I can’t say what’s wrong exactly. I’ll be working on updating our TensorFlow package. It’s about 6 months old on the firmware.

If you need this fixed in the mean-time please use EdgeImpulse to retrain.

---

<div class="post-metadata">

**Author:** ![MoZen](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@MoZen](https://forums.openmv.io/u/MoZen)\
**Post date:** [June 21, 2021, 11:51pm UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/3 "2021-06-21T23:51:55Z")

</div>

Thanks, I was able to run classification both in edge impulse and with TensorFlow Quantization.

---

<div class="post-metadata">

**Author:** ![darrask](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@darrask](https://forums.openmv.io/u/darrask)\
**Post date:** [July 23, 2021, 9:21am UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/4 "2021-07-23T09:21:51Z")

</div>

We have similar issues here using a re-trained MobileNet to classify around a dozen classes of objects.

However, we cannot use EdgeImpulse for training the model due to the restriction on training time and dataset size, we achieve very low accuracy around 70%. EdgeImpulse offers some means to fine-tune the training but it is currently impossible to use SOTA methods.

It would be awesome if we can upgrade the openMV runtime to TF Lite 2.5.

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [July 23, 2021, 2:57pm UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/5 "2021-07-23T14:57:05Z")

</div>

This will happen in the coming months. I’ve been busy with life but should have more time soon.

---

<div class="post-metadata">

**Author:** ![darrask](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@darrask](https://forums.openmv.io/u/darrask)\
**Post date:** [July 24, 2021, 4:05am UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/6 "2021-07-24T04:05:12Z")

</div>

Sure Kwabena, thanks for this and good luck. Just wanted to touch ground.

---

<div class="post-metadata">

**Author:** ![MoZen](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@MoZen](https://forums.openmv.io/u/MoZen)\
**Post date:** [January 25, 2022, 3:20am UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/7 "2022-01-25T03:20:22Z")

</div>

Hi Kwabena,

How can I tell the version of OpenMV TFLite runtime from the firmware release? And what is the current TF Lite one on v4.2.1?

> **[Releases · openmv/openmv](https://github.com/openmv/openmv/releases)**
>
> OpenMV Camera Module. Contribute to openmv/openmv development by creating an account on GitHub.

**Details:**  
I got a new image dataset and fine-tuned it on a mobilenetV2 and got the tflite and tflite quantized files. The TensorFlow I am using is 2.7, with the older TF version it was working but now I can not run the tflite model on H7 plus R3 using firmware v4.2.1., I have older versions of TensorFlow on my Anaconda packages too which I can try to build tflite models.

Thanks

---

<div class="post-metadata">

**Author:** ![kwagyeman](https://yyz1.discourse-cdn.com/flex029/user_avatar/forums.openmv.io/kwagyeman/32/4_2.png) [@kwagyeman](https://forums.openmv.io/u/kwagyeman)\
**Post date:** [January 25, 2022, 7:45am UTC](https://forums.openmv.io/t/image-classification-with-transfer-learning-on-mobilenet-issue/5950/8 "2022-01-25T07:45:12Z")

</div>

I don’t know exactly, I’ll see if I can fix this I’ve the weekend by updating our branch we pull from TensorFlow. We’re using edge impulses fork of TensorFlow now since the latest release of TensorFlow crashes on any model being used.

I can’t debug these things because of how complex the TensorFlow library is. I can only just try different library versions.
