Can't do binary segmentation result

You said, that you’ve multiplied it with 255 to get the same range.

However, if you’ve converted it to uint8 and calculated the error after it, you might get some over or underflows.
Could you make sure to subtract the prediction and target as floats and later convert it back to an image?

EDIT:
I’ve loaded your images and it seems to be the case with the under-overflow.
Here are the error stats using floats:

(array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]),
 array([279106,  14069,   7218,   3872,   1769,    825,    261,     64,
            10,      6]))

It doesn’t look that bad anymore.

Now you could scale up your training and try to fit the whole training set.
Note, that you might have a highly imbalanced dataset, i.e. more background than objects, so that you might have a look at weighting the loss function.

Thx! so how to solve this over/underflow issue? can we totally eliminate the digit not 0 or 1? categorize them to nearest digit,0 or 1?
I do the test process like this111
and still the previous question: what’s the meaning of ‘make the layer bigger’?
thx! how kindness u r!

When comparing the images and calculating the error, you would have to cast the images to int64 or float first, as np.uint8(1) - np.uint8(2) results in 255.
I’ve just used this:

err = np.abs(imageA[:, :, 0].astype(np.float64) - imageB.astype(np.float64))

Generally, just add more parameters into your layer, i.e. more out_channels for conv layers or more out_features for linear layers.
Currently I doubt it will help, as the results looks good without the wrong error image.

sry for just went outside to have dinner.
it means for error, use the formula mentioned above is enough, for result image generating, cast into uint8 directly?

I don’t quite understand the question.
You can cast the resulting error image into uint8 again and display it accordingly.

I mean, when I get result,it should be a float tensor in Pytorch,first I should avoid the under/overflow’s influence in error calculation, those 2,3,4,254,253,252, they just vary around the 0 and 255,so they should be 0 or 255, Am I right? or stil wrong?
then how to cut down those calculation over/underflow, such as 2,3,4, 254,253,252 and so on, just do the as type(np.uint8) directly? It’s these digits that cause the error image not so good.
after error calculation,I should save the result as image, so transform the float64 result to uint8 directly?

No. They should be low values, since 255 would be the max possible error.
Don’t cast the prediction and target to uint8 before calculating the error image.
If you want to save the error image, you can scale it up to 255 and cast it to uint8.

Sure !Excellent! I’m very excited to finish the model with your accompany and guidance by my lame English communication.I’m a graduate freshman from China.So kindness and warm-hearted you are!
I’ve solved the problem.Thank you!

1 Like

will this case occur? for one sample and overfitting badly,the np.mean(err) is zero, while the training loss is not zero?(although descenting,but step seems really small,seems hardly to converge to zero in same epoch as before)

This might happen, if err are not absolute values, thus summing to near zero.
On the other hand, your model might have a 100% accuracy, but the output might still have a small loss.
I.e. you call argmax on your logits, which might yield no error pixels, but the “probability” is not necessarily 0% and 100% for each output pixel.