Transforms and ImageClassifierData

Is it possible to use ImageClassifierData without defining any transforms? For example, if I just want to quick and dirty play around with the functions, can I leave tfms=(None, None) as the default parameter to ImageClassifierData? If I try to do that I get an attribute error AttributeError: 'NoneType' object has no attribute 'sz'

Is there a reason why data augmentation seems to be required? Is there a way to not augment your data?

What does the sz parameter do? It seems to only be relevant to transforms. I tried putting in arbitrary numbers for sz and everything still works, although I get slightly worse accuracy. What does sz represent?

1 Like

Harry, you need to get the data “ready” for training so it needs some basic transforms. If you use this you don’t get data augmentation. sz x sz x 3 is the size of the images that you will be training on.

tfms = tfms_from_model(f_model, sz)

Here is an example on why you need basic transformations. You may have images of different sizes but you need training batches to a consistent size. In order to get that your images need to have all the same size. In this library they all get transform into a square. The library has different ways of doing that.

3 Likes

Thank you!

what if my data is already of the same size, all images are rectangular and can’t be cropped w/o losing the information (this is a multi label classification problem).

The default cropping is “center crop” you will not lose any information if you don’t do data augmentation.

1 Like

the images are 70X140 where the object are spread pretty much from one side to the other (it’s an OCR type problem) - so a square crop would def cut the labeled pixels and invalidate the labels. Is there a particular reason for input to be square?

Sorry I misread your post. One possibility is to use CropType.NO. I will find an example and post it here.

sz = 350
tfms = tfms_from_model(resnet34, sz, crop_type=CropType.NO)
data = ImageClassifierData.from_csv(PATH, "images", csv_fname, bs, tfms, val_idxs)

This will resize your image.
Here is an example in this topic. Look for the pictures.

2 Likes

perfect, thank you for clarifying!

My takeaway from this question is:
transformation <> augmentation
but:
augmentation (if any) is done during transformation.