How can I get the total number of images when doing "batch_tfms= aug_transforms(mult=2)"

I’m trying to find the number of images used to train the model, but using dls.train_ds only let me get the images in the train set but with no augmentation.

dls = DataBlock(
blocks = (ImageBlock, CategoryBlock),
get_items = get_image_files,
splitter = RandomSplitter(valid_pct=0.2, seed=42),
get_y = parent_label,
item_tfms = Resize(200),
batch_tfms= aug_transforms(mult=2)
).dataloaders(path)

len(dls.train_ds)

1 Like

With augmentation the number of training images doesn’t change. What happens is that a random set of image augmentation transforms is applied to each image during training. So if you train for say two epochs. The network will see each image twice but each time the image will be transformed randomly, that is rotated, flipped, changed brightness, etc. See here for full list of default transforms Data augmentation in computer vision | fastai

From fastbook:

Data Augmentation

Data augmentation refers to creating random variations of our input data, such that they appear different, but do not actually change the meaning of the data. Examples of common data augmentation techniques for images are rotation, flipping, perspective warping, brightness changes and contrast changes. For natural photo images such as the ones we are using here, a standard set of augmentations that we have found work pretty well are provided with the aug_transforms function.

4 Likes

So if you train for more than 1 epoch, each full rotation the model is going to see a “different image”. So for example, if your accuracy is 99% in the first 2 epochs it’s a waste to augment the data? I’m having trouble running a vision model that it needs more than 3 epochs to plateau itself and doesn’t get any better.

yes, each time the image is fed to network, a different (random) set of transforms are applied to that image.
augmentation can improve the accuracy.

2 Likes

Thank you!!

1 Like

Hi @miwojc! do you know what’s meant for “natural photo images” in this context? thanks!

They are images of bears

Thanks, I was searching around, and thought it was smtg more aling these lines and dont’ know if we can then apply these transformations to other types of images i.e. sensors, spectrums, etc.?