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 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 import * instead of from import *

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

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

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


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)  # 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