# ImageAugmentationLayer on image and target mask

Posted 7 months ago
832 Views
|
2 Replies
|
3 Total Likes
|
 Hi, I'd like to use ImageAugmentationLayer in my binary image segmentation neural network. However, it seems like I can't get the ImageSegmentationLayer to do exactly the same transform on my input image as on my target mask. Is there a hidden way to do this that's not mentioned in the docs? It seems like every invocation of the layer will use a new random crop, but I need to do the exact same random crop on pairs of images. Cheers!
2 Replies
Sort By:
Posted 7 months ago
 In the meantime I'm using this function to do it. randomCrop[is_, sz_] := Module[{x = RandomReal[{-1, 1}], y = RandomReal[{-1, 1}]}, ImageCrop[#, sz, {x, y}] & /@ is ] 
 Hi Carl, unfortunately there is no way to link two ImageAugmentationLayers currently. NetMapOperator will also give you two different crops. You will have to perform the augmentation outside the Neural Net as a pre-processing step. You can either pre-compute you augmented dataset before traning, or you can have online augmentation during training (as ImageAugmentationLayer would give you) by using the "generator" syntax of NetTrain: NetTrain[net, f], as in the 5th signature of the NetTrain doc page: https://reference.wolfram.com/language/ref/NetTrain.htmlInside the generator function you will have to take the current minibatch, apply your linked random cropping and return the cropped minibatch.