What happened to the people detection model

Couple of points.
When I use my OpenMV H7plus on a mac I can not upload sketches
One a Windows 10 machine it is ok

Second point I had a people detection model I ran about 18 months ago. It seems to have disappeared from your examples
Does this exist somewhere else
Regards

When I use my OpenMV H7plus on a mac I can not upload sketches

What’s the error?

Person detection is here:

We removed it being built-in since it took 360KB of flash and we were out of space.

Thanks for your speedy response

With the mac the option in tools to “save the open to OpenMV……. is greyed out

image

Regarding the people detection model do I download it from github and paste it to the sd card on the camera

Regards

Max

Yeah, it’s not connected to the camera? Those options are greyed out when you haven’t yet connected.

And yes, it can be put on the SD card and it can run off it. Just like other models from Edge Impulse.

I visited your githup repo and downoaded the 2 files. The model and labels. The model was 301 KB
I copied them both onto the sd card of the camera

I then copied my py file to main.py and connected

This produced an OSerror stating it can not find the file

If you can lead me to fix this I would be greatful

My program just make an led go red when there is a person and it makes a connection go high

regards

Max


# TensorFlow Lite Person Dection Example
#
# Google's Person Detection Model detects if a person is in view.
#
# In this example we slide the detector window over the image and get a list
# of activations. Note that use a CNN with a sliding window is extremely compute
# expensive so for an exhaustive search do not expect the CNN to be real-time.

import sensor, image, utime, os, tf
from pyb import LED
from pyb import Pin

#self LED test to ensure the LED is working
red_led = LED(1)
green_led = LED(2)
blue_led = LED(3)

p_out = Pin('P0', Pin.OUT_PP)

red_led.on()
utime.sleep(1)
red_led.off()
green_led.on()
utime.sleep(1)
green_led.off()
blue_led.on()
utime.sleep(1)
blue_led.off()
green_led.on()
utime.sleep(1)
green_led.off()

sensor.reset()                         # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)      # Set frame size to QVGA (320x240)
sensor.set_windowing((300, 300))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.

# Load the built-in person detection network (the network is in your OpenMV Cam's firmware).
net = tf.load('person_detection.tflite')
labels = [ 'NO DUDE', 'GOOD LOOKING DUDE', 'CONFUSED']

clock = utime.clock()
while(True):
    clock.tick()

    img = sensor.snapshot()


    # default settings just do one detection... change them to search the image...
    for obj in net.classify(img, min_scale=1.0, scale_mul=0.5, x_overlap=0.0, y_overlap=0.0):
        colour = 255,0,0
        led_green = 0
        led_red = 0
        print("**********\nDetections at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
        for i in range(len(obj.output())):
            print("%s = %f %d" % (labels[i], obj.output()[i], i))

            if i == 0:
             if obj.output()[i]>=0.50: # percent as fraction
                 colour = 255,255,255 # text colour
                 led_green = 1

            if i == 1:
             if obj.output()[i]>=0.50:
                 colour = 255,255,255
                 led_red = 1

        # after for range loop
        if led_green == 0:
            green_led.off()
        else:
            green_led.on()
            p_out.low()

        if led_red == 0:
            red_led.off()
        else:
            red_led.on()
            p_out.high()

        img.draw_rectangle(obj.rect())
        img.draw_string(obj.x()+3, obj.y()-1, labels[obj.output().index(max(obj.output()))],colour, mono_space = False, scale = 3)

    # after for obj loop
    print(clock.fps(), "fps")

Do you have the H7 or H7 plus? The model won’t fit on the H7 unless it’s baked into the firmware.

I have the H7 Plus

I did not answer because you went to spam

regards

Still trying to find a way forward. Not sure what to do to get the model on the sd card and get the code to read the model

Regards
Max

Sorry, will get back to you in a sec.

Hi, I downloaded those files from offline and range it with this script and it runs:

# TensorFlow Lite Mobilenet V1 Example
#
# Google's Mobilenet V1 detects 1000 classes of objects
#
# WARNING: Mobilenet is trained on ImageNet and isn't meant to classify anything
# in the real world. It's just designed to score well on the ImageNet dataset.
# This example just shows off running mobilenet on the OpenMV Cam. However, the
# default model is not really usable for anything. You have to use transfer
# learning to apply the model to a target problem by re-training the model.
#
# NOTE: This example only works on the OpenMV Cam H7 Pro (that has SDRAM) and better!
# To get the models please see the CNN Network library in OpenMV IDE under
# Tools -> Machine Vision. The labels are there too.
# You should insert a microSD card into your camera and copy-paste the mobilenet_labels.txt
# file and your chosen model into the root folder for ths script to work.
#
# In this example we slide the detector window over the image and get a list
# of activations. Note that use a CNN with a sliding window is extremely compute
# expensive so for an exhaustive search do not expect the CNN to be real-time.

import sensor, image, time, os, tf

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((240, 240))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.

mobilenet = "person_detection.tflite"
labels = [line.rstrip('\n') for line in open("person_detection.txt")]

clock = time.clock()
while(True):
    clock.tick()

    img = sensor.snapshot()

    # net.classify() will run the network on an roi in the image (or on the whole image if the roi is not
    # specified). A classification score output vector will be generated for each location. At each scale the
    # detection window is moved around in the ROI using x_overlap (0-1) and y_overlap (0-1) as a guide.
    # If you set the overlap to 0.5 then each detection window will overlap the previous one by 50%. Note
    # the computational work load goes WAY up the more overlap. Finally, for multi-scale matching after
    # sliding the network around in the x/y dimensions the detection window will shrink by scale_mul (0-1)
    # down to min_scale (0-1). For example, if scale_mul is 0.5 the detection window will shrink by 50%.
    # Note that at a lower scale there's even more area to search if x_overlap and y_overlap are small...

    # default settings just do one detection... change them to search the image...
    # Setting x_overlap=-1 forces the window to stay centered in the ROI in the x direction always. If
    # y_overlap is not -1 the method will search in all vertical positions.
    # Setting y_overlap=-1 forces the window to stay centered in the ROI in the y direction always. If
    # x_overlap is not -1 the method will serach in all horizontal positions.

    for obj in tf.classify(mobilenet, img, min_scale=1.0, scale_mul=0.5, x_overlap=0.0, y_overlap=0.0):
        print("**********\nDetections at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
        img.draw_rectangle(obj.rect())
        # This combines the labels and confidence values into a list of tuples
        # and then sorts that list by the confidence values.
        sorted_list = sorted(zip(labels, obj.output()), key = lambda x: x[1], reverse = False)
        print(sorted_list)
    print(clock.fps(), "fps")

However, while the model is fast it sucks now. It looks like when it’s unsure it will return 50% about for both classes. It now longer has 3 outputs. Also, it appears to return the wrong values… when there’s a person it increases the no_person confidence to 95%.

Anyway, it looks like is possible to use though if you just reverse the labels and then put a threshold on the person output:

# TensorFlow Lite Mobilenet V1 Example
#
# Google's Mobilenet V1 detects 1000 classes of objects
#
# WARNING: Mobilenet is trained on ImageNet and isn't meant to classify anything
# in the real world. It's just designed to score well on the ImageNet dataset.
# This example just shows off running mobilenet on the OpenMV Cam. However, the
# default model is not really usable for anything. You have to use transfer
# learning to apply the model to a target problem by re-training the model.
#
# NOTE: This example only works on the OpenMV Cam H7 Pro (that has SDRAM) and better!
# To get the models please see the CNN Network library in OpenMV IDE under
# Tools -> Machine Vision. The labels are there too.
# You should insert a microSD card into your camera and copy-paste the mobilenet_labels.txt
# file and your chosen model into the root folder for ths script to work.
#
# In this example we slide the detector window over the image and get a list
# of activations. Note that use a CNN with a sliding window is extremely compute
# expensive so for an exhaustive search do not expect the CNN to be real-time.

import sensor, image, time, os, tf

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((240, 240))       # Set 240x240 window.
sensor.skip_frames(time=2000)          # Let the camera adjust.

mobilenet = "person_detection.tflite"
net = tf.load(mobilenet, load_to_fb=True)
labels = [line.rstrip('\n') for line in open("person_detection.txt")]
labels.reverse()

clock = time.clock()
while(True):
    clock.tick()

    img = sensor.snapshot()

    # net.classify() will run the network on an roi in the image (or on the whole image if the roi is not
    # specified). A classification score output vector will be generated for each location. At each scale the
    # detection window is moved around in the ROI using x_overlap (0-1) and y_overlap (0-1) as a guide.
    # If you set the overlap to 0.5 then each detection window will overlap the previous one by 50%. Note
    # the computational work load goes WAY up the more overlap. Finally, for multi-scale matching after
    # sliding the network around in the x/y dimensions the detection window will shrink by scale_mul (0-1)
    # down to min_scale (0-1). For example, if scale_mul is 0.5 the detection window will shrink by 50%.
    # Note that at a lower scale there's even more area to search if x_overlap and y_overlap are small...

    # default settings just do one detection... change them to search the image...
    # Setting x_overlap=-1 forces the window to stay centered in the ROI in the x direction always. If
    # y_overlap is not -1 the method will search in all vertical positions.
    # Setting y_overlap=-1 forces the window to stay centered in the ROI in the y direction always. If
    # x_overlap is not -1 the method will serach in all horizontal positions.

    for obj in net.classify(img, min_scale=1.0, scale_mul=0.5, x_overlap=0.0, y_overlap=0.0):
        print("**********\nDetections at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
        img.draw_rectangle(obj.rect())
        # This combines the labels and confidence values into a list of tuples
        # and then sorts that list by the confidence values.
        combined = list(zip(labels, obj.output()))
        print(combined)
        if (combined[1][1] > 0.9):
            print("FOUND A PERSON")
    print(clock.fps(), "fps")

I’m getting 20 FPS on the H7 Plus at 240x240.

person_detection.zip (225.4 KB)

Very solid reply. Most appreciated on a Friday night.
I will try this out in the morning.
Many taks for your efforts
Max

1 Like

Good news

Its working @19.7 FPS

Many thanks for your help

Max

Does this code and model also work on the OpenMV Cam RT1062?

Yes it does.