Having program 'wait' a few seconds upon detecting background class (Image Classification)

i am doing a simple image classification of 4 classes (Class1,2,3 and background)

This is snippet of the code

cond = True

if confidence_value >= 0.98:
            ##print only the class i.e. index 0 is the class and index 1 gives the value
            top_class = top_value[0]
            #stops the while loop
            cond = False
            print('While loop stopped, class detected as:', top_class)
            print('Unable to decide')
            cond = True

Now the code runs in principle but since the background class is the easiest to detect, and the data is constantly pulling, there’s a chance it’ll detect the background class first before the image is in view. For this i have a simple if brutalistic solution of having the device ‘sleep’ for about 3s while the image gets into view however is this the best method? or is there a more ‘elegant’ way of doing it

The 2nd bit which pertains to this question is sometimes even if e.g. class 1 is in view, it’ll detect background class for awhile. I plan to get more data to make it more robust too but for now, is it possible where if it detects the background class, for the code to ‘ignore’ this class for about maybe 5s before it outputs as background class just in case that the other classes are detected in the meantime. If so, any suggestions on how it would be done?

Hi, have you tried re-training your model using the new FOMO algorithm from Edge Impulse? You can now track objects which will help with this issue.

Anyway, your model should be able to detect and output a confidence score for all 4 classes at once. Given that… I would just short the class output list and find the highest one which is the most likely right?