Could you post the image source or upload one target image?
Somehow you have two values in the first target image: [0, 40].
You could try to call Relable(40, 1), but maybe the next image has a different value, so that’s not the solution.
If it’s possible, I would like to load one image and see, what kind of values are stored there.
Also, the output does not match the code exactly. I’m still wondering about the shape of targets.