Visualizing output of a tflite segmentation model

Hello, I have created and loaded a fully quantized TFLite segmentation model using net = tf.load(“my_quantized_model.tflite”, load_to_fb=True) on the OpenMV CAM RT1060. The model loads successfully. However, when I try to test with a static image, the model segments but I am not able to print out and visualize the output. Is there some way I can be able to print out this output??

load an image from a file

img = image.Image(‘cat.jpg’)

#make a sample prediction
predictions = net.segment(img)

#save resulting output
predictions.save(“pred.jpg”)

Hi, segment returns a list of images.

So, you need to do:

for i, im in enumerate(net.segment(img))
   im.save("pred-%d.jpg" % i)

Thanks Kwagyeman,

I updated my code and I get these three image outputs in greyscale. How should I generate a binary mask and what are these images?, why are they three?. Thank you

Hi, they are the segmentation results of your network.

For every channel in the final output we generate a grayscale image based on the output width/height.

So, if you had 3 classes each image is a different class.

Note, we make an assumption that you organized the output of the network as [h][w][c] (organizing model output this way is very standard). [c == channel which is the class]

If this is not how your segmentation network outputs its data, then it won’t be handled correctly with the current firmware. We only use the segmentation output to power the FOMO algorithm. However, it can be used for any generic segmentation network.

As for binarizing the images. See the binary() and it’s examples in the IDE under Image Processing → Image Filters.

This is very helpful, thank you