(Rik de Deken)
January 11, 2018, 3:37pm
Preamble/disclaimer: I am not a seasoned Python coder. The following serves to show that.
When I try to create a data object for my ConvLearner model like this:
data1608 = fastai.dataset.ImageClassifierData.from_paths(PATH)
without any tfms transformations, I get errors like these:
~/fastai/courses/dl1/fastai/dataset.py in get_sz(self)
143 def get_n(self): return len(self.y)
--> 144 def get_sz(self): return self.transform.sz
145 def get_x(self, i): return open_image(os.path.join(self.path, self.fnames[i]))
AttributeError: 'NoneType' object has no attribute 'sz'
Putting the tfms=tfms argument back in resolves this.
Here’s my confusion;
The signature in
.from_paths() says that the default value for
(None, None) which suggests to me that it can be omitted during initialization of the object.
Signature: fastai.dataset.ImageClassifierData.from_paths(path, bs=64, tfms=(None, None), trn_name='train', val_name='valid', test_name=None, num_workers=8)
Am I misinterpreting this?
In short: is the transformations argument
required and must it refer to a proper
fastai.transforms.tfms_from_model(arch, sz) object ?
January 11, 2018, 5:51pm
You need to use transforms even if you are not doing data augmentation.
Here is the most basic example
data = ImageClassifierData.from_paths(PATH, tfms=tfms_from_model(arch, sz))
learn = ConvLearner.pretrained(arch, data, precompute=True)
(Rik de Deken)
January 11, 2018, 7:27pm
Thanks yinterian. That confirms I am trying to do something that I am not supposed to. The whole reason for me to try using a transformation-less data object is to learn the fastai library.
So allow me a follow-up question: why?
Why do I need transforms if not for data augmentation? Is it because the training images all have dimensions that do not conform to the
sz * sz format? Is this the way to inform pytorch how to pre-condition my data?
(Rik de Deken)
January 11, 2018, 8:08pm
Just found a duplicate post here:
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 t…
and also the answer to my question:
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.
So thanks again