Open Erotemic opened 5 years ago
The interpolation order was hard-coded to 3, because the heatmap outputs are intended for ground truth and are therefore deteriorated as little as possible. So in the case of affine with e.g. nearest neighbour interpolation, the model would get an (augmented) input image with some information lost due to the interpolation method, but would still be trained to guess the correct heatmap as if no information had been lost. I recall thinking about the correct interpolation order there quite a bit and not coming to a clear decision whether it should always be 3 or always be the corresponding image array's interpolation order. You can come up with arguments for both cases, but ultimately it was fixed to 3.
It is however surprising that this fails for heatmaps with more than 4 channels. Affine was particularly adapted to automatically fall back to scikit-image in these cases -- which isn't a very efficient way of solving this as you could just split up the array into chunks of 4 channels and then feed them into OpenCV, but at least it shouldn't crash here. I hope I have the time to look into the issue this weekend.
The channel-issue should now be fixed in master, thanks for reporting the problem.
Making order
configurable for heatmaps is left to a future patch.
It should now be possible to change the interpolation order of heatmaps in Affine
to "use the same as for images":
aug = Affine(...)
aug._order_heatmaps = None # or an integer to always use a fixed value
Not tested though.
This is a reasonable workaround. Thanks for adding that.
I'm getting an issue when I use
iaa.Affine
to warp segmentation masks or heat maps.This only happens when I force the cv2 backend and I have more than 3 classes in my heatmap / segmentation mask. For whatever reason opencv doesn't like to do cubic or lanczos resampling for many channel images (I don't see why it doesn't perhaps opencv needs a PR on this front).
Code to reproduce is as follows
It took me awhile to understand why this was happening (because I had set order explicitly to 1, which is linear interpolation). I found out that this happens because in
_augment_heatmaps
on line 717: the interpolation order is hard coded to 3 (which is cubic).I'm not sure why this isn't using the same order as the regular image augmentation. Perhaps there is a reason? I did a quick test and changed the hard coded 3 to a 1 and everything worked, but I haven't tried simply removing this line (which I think may be the correct fix).
Thoughts?