Gray Scale Segmentation on Android

I have trained a segmentation model and the segmentation accuracy is satisfying. The issues am having is that I can’t get any results in Android TensorFlow Lite model. I also tested the converted in Python to a certain that the results are similar to the trained Keras model and they are. I followed the segmentation example in the on tflite examples and am just getting a blank segmentation. I thought it is an issue with normalization but I made sure I included it when adding metadata to the model. Is there anyway I can work around it

Hi @Evans_Kiplagat

What error logs are you getting on the console? Can you provide them?

1 Like

Hi @George_Soloupis
Am not getting any error only that the results am getting from the segmentation model aren’t useful. The colored pixels returned from the segmentation in only black. If I get a working example of image segmentation on Android applied to gray medical images it would really help.

Check the metadata following this link:

Is everything OK?

This is the metadata. It shows here in that for the output the values range from 1 to 2, which is not true. It should be 0.0 to 1.0.
{
“name”: “ImageSegmenter”,
“description”: “Semantic image segmentation predicts whether each pixel of an image is associated with a certain class.”,
“subgraph_metadata”: [
{
“input_tensor_metadata”: [
{
“name”: “image”,
“description”: “Input image to be segmented.”,
“content”: {
“content_properties_type”: “ImageProperties”,
“content_properties”: {
“color_space”: “RGB”
}
},
“stats”: {
}
}
],
“output_tensor_metadata”: [
{
“name”: “segmentation_masks”,
“description”: “Masks over the target objects with high accuracy.”,
“content”: {
“content_properties_type”: “ImageProperties”,
“content_properties”: {
“color_space”: “GRAYSCALE”
},
“range”: {
“min”: 1,
“max”: 2
}
},
“stats”: {
}
}
]
}
],
“min_parser_version”: “1.0.0”
}

So for starters there is something wrong with your metadata. Fix the input of the metadata inside the tfite file and proceed to next step.

I added the metadata with image segmenter metadata writer TensorFlow Lite Metadata Writer API script provided in TensorFlow docs and then later imported the model with Android studio model binding which generated the code for running inference and everything works fine.
Thanks.

1 Like