Lesson 3 In-Class Discussion ✅

When I run the following code, I get an error.

Code:

data = (src.datasets().transform(get_transforms(), size=128).databunch().normalize(imagenet_stats))

Error:

/opt/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in datasets(self, dataset_cls, **kwargs)
    232         "Create datasets from the underlying data using `dataset_cls` and passing along the `kwargs`."
    233         if dataset_cls is None: dataset_cls = self.dataset_cls()
--> 234         train = dataset_cls(*self.train.items.T, **kwargs)
    235         dss = [train]
    236         dss += [train.new(*o.items.T, **kwargs) for o in self.lists[1:]]

TypeError: __init__() missing 2 required positional arguments: 'x' and 'y'

Which arguments am I missing?

I am not smart enough to keep track of the tensors’ dimensions and ranks on the fly :slight_smile: . So, when something is not working, I start by checking tensors’ shapes.
In this particular case, it seems that the open_mask function converters the mask in a regular 3-channel image (rank-3 tensor), but since the mask is 1-channel, the batch shape is [bs, 1, h, w]. If you are using the standard fastai pipeline, you don’t have to worry about it, since its loss functions flatten the preds and target tensors. However, when defining customs metrics, a good practice should be checking tensors’ shapes.

2 Likes

learningrate

Hello,
I was wondering what this type of graph means since it seems to have a pretty flat slot in the beginning which seems to be a problem for finding a learning rate accurately. I’m using a dataset comparing images of different types of architecture towers:

According to some of the images there is maybe a classification issue due to the similarity of towers between like an office tower or a residential. Perhaps I have to do better seperation between the images. I was just wondering if there’s a better way to approach this since I’m getting this for training:

Total time: 11:51
epoch train_loss valid_loss error_rate
1 1.866207 1.394691 0.533537 (02:55)
2 1.614861 1.335335 0.524390 (02:59)
3 1.439242 1.272921 0.500000 (02:58)
4 1.305421 1.266789 0.496951 (02:57)

any help is appreciated. Thank you.

Jeremy mentioned this type of graph in the lecture, and you can see an example in the planets notebook. He suggested you find the point where it starts rising and then divide that learning rate by 10, so in your case I’d try 1e-4.

1 Like

error rate is going down, and val loss is still above train loss, which mean that you are still underfitting. There’s no reason to stop at 4 epochs. You should increase the number of epochs until you find that error rate plateaus or starts to go up, and train loss is lower than val loss.

Run

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Before bring up the jupyter notebook

1 Like

Could someone help me with how to read a .json file? It has the labels for an image dataset. I tried using:

pd.read_json(path_anno/‘file.json’)

But I get the error: ValueError: arrays must all be same length

I may be misunderstanding your question, but only the filenames in the ImageFileList that match an entry in labels.csv will be kept (from the docs: “Note: This method will only keep the filenames that are both present in the csv file and in self.items.”)

1 Like

This is a deep learning course. GBMs are not deep learning.

@safekidda there is an ML course as well from fastai which covered random forest in detail…was inquiring if there is gonna be a part 2 for ML course covering other ML algos (like we have now for DL) when Jeremy suggested looking into ML course during lesson 3

I’m not on colab, but I’m running on a server at work using docker and I had the same issue.

It’s a locale issue in the environment. I solved mine by updating the locale in the docker build file. But if you’re in colab try something like this:

!locale-gen en_US.UTF-8
!export LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8

Ah right, fair enough. I suspect they’ll do the deep learning part 2 (v3) next. So, if they do, I think it’ll be a way off.

As an aside, I think near enough everything is better in deep learning these days. The only example I’ve seen (first hand) where non DL models were better was a tiny, very sparse tabular dataset. Even then it’s a pain compared to deep learning because the data prep is much more onerous and less forgiving. Much easier to just stick all your continuous variables as-is and your categorical variables though embeddings in a DL model.

Hi,

I’m trying to use image segmentation to predict single image but the following code throws error:

src = (ImageFileList.from_folder(path)
       .label_from_func(get_y_fn)
       .random_split_by_pct(0.2))

data = (src.datasets(SegmentationDataset, classes=codes, div=True)
        .transform(get_transforms(), size=128, tfm_y=True)
        .databunch(bs=1, num_workers=0)
        .normalize(imagenet_stats))

predictor = Learner.create_unet(data, models.resnet18)
predictor.predict(img)

and error is:

/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py in __getitem__(self, idx)
    237         x,y = self.ds[idx]
    238         x = apply_tfms(self.tfms, x, **self.kwargs)
--> 239         if self.tfm_y: y = apply_tfms(self.tfms, y, **self.y_kwargs)
    240         return x, y
    241 

/usr/local/lib/python3.6/dist-packages/fastai/vision/image.py in apply_tfms(tfms, x, do_resolve, xtra, size, mult, resize_method, padding_mode, **kwargs)
    578         tfms = sorted(listify(tfms), key=lambda o: o.tfm.order)
    579         if do_resolve: _resolve_tfms(tfms)
--> 580         x = x.clone()
    581         x.set_sample(padding_mode=padding_mode, **kwargs)
    582         if size is not None:

AttributeError: 'int' object has no attribute 'clone'

Did anyone try to predict a single image for segmentation?

where do we get lesson 4 youtube link to the live stream? Cant find it on the forum, I am subscribed to the class for lesson 1,2 received emails from Jeremy. Cannot seem to find an announcement in this forum, can someone point me into the right direction please?

thx

I keep getting the error ImageFileList not defined. Even though I have imported the vision module using from fastai.vision import *.

I am trying to run the camvid notebook

Which version are you running? I think you need at least 1.0.21.

How do I update it? I am running the notebook on AWS

you are right. my version is fastai==1.0.15. How do I update it?

I am no running on AWS, but according to this post conda update -c fastai fastai should work.

I did conda update --all and hoped it would work. Apologize for such a newb question.