From a segmentation mask, I am trying to retrieve what labels are being represented in the mask.
This is the image I am running through a semantic segmentation model in AWS Sagemaker.
Code for making prediction and displaying mask.
from sagemaker.predictor import json_serializer, json_deserializer, RealTimePredictor
from sagemaker.content_types import CONTENT_TYPE_CSV, CONTENT_TYPE_JSON
%%time
ss_predict = sagemaker.RealTimePredictor(endpoint=ss_model.endpoint_name,
sagemaker_session=sess,
content_type = 'image/jpeg',
accept = 'image/png')
return_img = ss_predict.predict(img)
from PIL import Image
import numpy as np
import io
num_labels = 21
mask = np.array(Image.open(io.BytesIO(return_img)))
plt.imshow(mask, vmin=0, vmax=num_labels-1, cmap='jet')
plt.show()
This image is the segmentation mask that was created and it represents the motorbike and everything else is the background.
[
As you can see from the code there are 21 possible labels and 2 were used in the mask, one for the motorbike and another for the background. What I would like to figure out now is how to print which labels were actually used in this mask out of the 21 possible options?
Please let me know if you need any further information and any help is much appreciated.