Add_tfms error

Hey Gods of fastai,

I’ve made it - thanks to some great members here - to finally load the data, find the missing files, and now I’m ready to run the trainning.

But now, I got this error: “add_tfms”. What does it mean?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-64fc6a634eaa> in <module>()
----> 1 learn = cnn_learner(dls, resnet18, n_out=1, pretrained=True,loss_func=L1LossFlat, metrics=accuracy)

3 frames
/usr/local/lib/python3.7/dist-packages/fastai/vision/learner.py in cnn_learner(dls, arch, normalize, n_out, pretrained, config, loss_func, opt_func, lr, splitter, cbs, metrics, path, model_dir, wd, wd_bn_bias, train_bn, moms, **kwargs)
    172 
    173     meta = model_meta.get(arch, _default_meta)
--> 174     if normalize: _add_norm(dls, meta, pretrained)
    175 
    176     if n_out is None: n_out = get_c(dls)

/usr/local/lib/python3.7/dist-packages/fastai/vision/learner.py in _add_norm(dls, meta, pretrained)
    155     stats = meta.get('stats')
    156     if stats is None: return
--> 157     dls.add_tfms([Normalize.from_stats(*stats)],'after_batch')
    158 
    159 # Cell

/usr/local/lib/python3.7/dist-packages/fastai/data/core.py in __getattr__(self, k)
    334         return res if is_indexer(it) else list(zip(*res))
    335 
--> 336     def __getattr__(self,k): return gather_attrs(self, k, 'tls')
    337     def __dir__(self): return super().__dir__() + gather_attr_names(self, 'tls')
    338     def __len__(self): return len(self.tls[0])

/usr/local/lib/python3.7/dist-packages/fastcore/transform.py in gather_attrs(o, k, nm)
    163     att = getattr(o,nm)
    164     res = [t for t in att.attrgot(k) if t is not None]
--> 165     if not res: raise AttributeError(k)
    166     return res[0] if len(res)==1 else L(res)
    167 

AttributeError: add_tfms

Thing is, I don’t need much to make transformations of the data. It’s simple a GAN as it’s supposed to look here:

Plus, this is the code I’m working on:

Probably would have something to do with how your dls is created, but need permissions to get into your notebook to look at your code

1 Like

Sorry! Just fixed the persmission thing:

It looks like you are putting your dataset into the dls variable. I think that would explain why you are having issues passing it tfms.

2 Likes

I wonder if this tutorial would be helpful for your task as well:

1 Like

Thanks. Seems like the issue here.
But now, after intializing more of the dataset, and then initializing the dataloader - I still can’t even show one_batch.

It asys:

ValueError: This DataLoader does not contain any batches

I actually couldn’t find a good solution in the tutorial that you sent me, but I actually followed this tutorial instead:

Only problem there is that even when I tried to follow the Regression block there, the tutorial uses “PointBlock” instead of RegressionBlock.

I tried it myself, and it didn’t work:

Hi, I guess the input of your model is an image. What is the output? A single number? If so a cnn and a RegressionBlock for the target should be fine.
If you output is another image, then you need a Imageblock as target and a unet

Thanks Mann!
Yes, you’re right. The input of the model is images.
The output should be another image, which is a reconstruction of the input-image.
The concept is taking a dark (low light) image input of an object, and train it as compared to a bright image of the same object. The model will be then able to get another dark image as input and reconstruct it itself.
More explanation is here:

Somewhere else I was told that the kind of training I need is Regression, but maybe I’m wrong.

I kinda tried to follow this tutorial as well:

Here it doesn’t mention whether there is needed an ImageBlock or RegressionBlock, because the tutorial uses an old version of fastai.

I think that I suddenly somehow fixed this by adding bs=1 here:

dblock = DataBlock(blocks=(ImageBlock, ImageBlock),
                   splitter=RandomSplitter(),
                   get_x = get_input, 
                   get_y= get_target)
dls = dblock.dataloaders(df,bs=1)

I have no idea if it actually works out or not. Will continue working this out.

this is the same notebook but with the current version of fastai

1 Like

Thanks man! I desprately looked up for this. Beautiful.
Btw, do you know what this stands for?

dls.c = 3

It’s inside:
def get_dls(bs,size):

I think it sets the number of classes/outputs. Usually (if the output is a CategoryBlock for example) fastai infers it from data, but in this case I think should be manually set.

1 Like

I think you’re right. When I tried to look up at the documentation for this argument “c” of dataloaders method, it didn’t appear anywhere. But later on, an error appeared when the unet_learner function didn’t get any n_out argument. The error suggesed to add that dls.c value. And the n_out sounded like what you explained.