Image segmentation with Unet. I make a Pandas dataframe with image and mask attributes. I create a DataBlock with getters and augmentation. Code excerpt:
def make_mask(row):
"""
Is called by DataBlock(getters=).
Takes a list of paths to mask files from a Pandas column.
Makes sure all masks are 8 bits per pixel.
If there are multiple masks, merges them.
Returns a PILMask.create() mask image.
"""
f = ColReader("mask")
# PILMask.create() probably forces 8 bits per pixel
all_images = [np.asarray(PILMask.create(x)) for x in f(row)]
image_stack = np.stack(all_images)
image_union = np.amax(image_stack, axis=0)
return PILMask.create(image_union)
src_datablock = DataBlock(
blocks=(ImageBlock, MaskBlock),
getters=[ColReader("image"), make_mask],
splitter=TrainTestSplitter(stratify=src_df["dataset"].to_list(), random_state=42),
item_tfms=Resize(size=input_image_size, method="squish"),
batch_tfms=aug_transforms(),
)
src_dataloader = src_datablock.dataloaders(src_df, bs=src_batch_size)
src_dataloader.train.show_batch()
src_dataloader.valid.show_batch()
The problem is, the same aug_transforms()
are applied to both training and validation images. This is definitely not what I want.
Is there a way to prevent aug_transforms()
from being applied in validation?