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 when I save it with opencv or plot it is all black. The values of the seg_out image are all negatives which I think it is related to the normalization.
The seg_out shape is [1,80,29].
Here the seg_out values:
What can I do to show the correct image?
Here is what I am doing:
img = cv2.imread(img_path) if INPUT_CHANNELS == 3 else cv2.imread(img_path, cv2.IMREAD_GRAYSCALE) #original image
img = cv2.resize(img, (INPUT_WIDTH, INPUT_HEIGHT))
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)
seg_out2=seg_out.detach().numpy().transpose(1, 2, 0)
I guess the image is blackas the values are negative and OpenCV might map it to a black pixel value.
I don’t know what the values should represent but you might want to normalize them to
[0, 1] as floating point values or
[0, 255] as
uint8 values first before calling
@ptrblck Yes the image should be a black/white mask image, a one channel image. The white pixels should be in the area in which the scretch is.
How can I do to show the image in this way? Thanks
This doesn’t fit the posted values, as I would assume to see binary values (e.g. zeros and ones) for a black/white image while your current
seg_out tensor contains negative floating point values.
I’m unsure what this means.
You could try to normalize the tensor and then maybe binarize it (e.g. via a threshold), but since I’m ot familiar with your use case I’m unsure if this suggestion is valid.
Hi, I currently working on this paper too. (Mixed supervision for surface-defect detection_from weakly to fully supervised learning)
Maybe we can discuss some implementation detail future more
Here’s my email: email@example.com