NameError: name 'ImageDataBunch' is not defined

I am trying to use the below syntax on Colab but it returns NameError: name 'ImageDataBunch' is not defined

from fastai.vision import *

data = ImageDataBunch.from_folder('Kather_texture_2016_image_tiles_5000', valid_pct=0.2, seed=123)

I tried to install it manually using !pip install -Uq fastai but it did not solve the issue.

Hi @neda1, welcome to Fastai!

The reason you are unable to use ImageDataBunch is because this is something that was available in the previous version of Fastai (v1), but has been replaced with ImageDataLoaders.from_folder – you can find the documentation here: fastai - Vision data

This tutorial should help in making sense of how to utilize this functionality: fastai - Training Imagenette

*As a side note, you will want to use from fastai.vision.all import * instead of from fastai.vision import *

Additionally, the new version of the library just had a full course released that is definitely worth checking out: https://course.fast.ai

Not sure if it’s needed, but here’s a link to the docs of the deprecated functionality: vision.data | fastai

Hope this helps and let me know if you happen to have any other questions!

2 Likes

Thanks @ali_baba. It was very helpful.

1 Like

I just have a quick question regarding the training model. After loading the data as you guided. would that be fine if I use the following snippet or this one is deprecated? Would be grateful if you please guide me. Thanks


learn = cnn_learner(data, models.resnet18, metrics=accuracy, pretrained=False)
learn.fit(5)  # Train for 5 epochs (passes through all of the training data)

Hi @neda1 cnn_learner is indeed deprecated, the new name is vision_learner

Here are the docs for this: fastai - Vision learner

Additionally, here’s a tutorial that walks you through how to use this learner: fastai - Computer vision intro

Hope this helps