'Show image mask tensor model

I am working on a tensor model. I have trained it and now testing and evaluating it. Img_score with the prediction is working correctly. I want also to print the seg_mask image (seg_out in the code), but plt.imshow does not work, even if I permute it. Moreover if I print the values of the seg_out image they are all negatives which I don't understand how to handle them in images.

Here is what I am using.

INPUT_WIDTH = 232  
INPUT_HEIGHT = 640  
INPUT_CHANNELS = 3 

device = "cpu"  

model = SegDecNet(device, INPUT_WIDTH, INPUT_HEIGHT, INPUT_CHANNELS)
model.set_gradient_multipliers(0)
model_path = "/final_state_dict.pth"
model.load_state_dict(torch.load(model_path, map_location=device))

# %%
img_path = '/20118.png'
img = cv2.imread(img_path) if INPUT_CHANNELS == 3 else cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
img = cv2.resize(img, (INPUT_WIDTH, INPUT_HEIGHT))
print(img.shape) 
img = np.transpose(img, (2, 0, 1)) if INPUT_CHANNELS == 3 else img[np.newaxis]
img_t = torch.from_numpy(img)[np.newaxis].float() / 445400  # must be [BATCH_SIZE x CHANNELS x HEIGHT x WIDTH]

dec_out, seg_out = model(img_t)
img_score = torch.sigmoid(dec_out)
print(img_score) 

print(seg_out[0][0].shape)  
print(seg_out[0][0].permute(0, 1))
#plt.imshow(seg_out[0].permute(2, 0, 1))


thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source