Predict an clasified image

I build a lawn mover
useing openmv to find and avoid trees and lamppost Label Round
walls Label TURN
A horizontal “barcode” Label STOP

the code:

from machine import UART
import csi
import time
import ml

camera = csi.CSI()
camera.reset()
camera.pixformat(csi.RGB565)
camera.framesize(csi.QVGA)  # QVGA 320x240

uart = UART(1, 19200)

model = ml.Model("trained.tflite", load_to_fb=True)
print(model)
labels = \["ROUND", "STOP", "TURN"\]

clock = time.clock()
while True:
    clock.tick()
    img = camera.snapshot().gamma_corr(gamma=1, contrast=1.3, brightness=0.3)
    scores = model.predict([img])[0].flatten().tolist()
    max_score = max(scores)
    max_index = scores.index(max_score)
    print(f"Prediction: ({labels[max_index]} {max_score:.2f})")
    time.sleep(0.5)    # Pause 0.5 seconds

I am using Edge Impulse to clasify my objects
It’s work fine but:
When the camera is directed to a blank wal or the screen or any unclasied objects its indicating randow ROUND, STOP TURN.
The score is often 0.7 or more

I want it to indicate only the lable objects

What to do??

Hi, you need to give it examples of not the object you are looking for. A simple classifier model cannot not detect something. It has to generate an output. As such, you need to give it examples that have nothing in it to learn.

Thanks for a quick reply

I have give it tree, lamppost (ROUND), and I have giving it walls (TURN) and horizontal stripes (STOP). All of this have I tryed with differet backgrounds white, black transparent and original background.

What do you recommend?

“nothing in it to learn” how and what, white, black, grass?

if so can it have a common label.

You need to add images with no objects in them so it knows what the null class is. So, just pictures without the objects you are looking for, but the same background.

Thanks I will try that

It works fine now

Thanks