I have completed Part 1 of the 2019 course and am trying out a few image classification tasks to get some practice. I am trying out the classification of this dataset in Kaggle.
When I create the DataBunch object this way, it works fine and I am able to see the images through show_batch() function:
data = (ImageList.from_folder(path = TRAIN_PATH)
.transform(get_transforms(), size = size)
.databunch(bs = 32)).normalize(imagenet_stats)
But when I do the same in the below manner, the DataBunch object gets created but show_batch() throws an error.
data = ImageDataBunch.from_folder(path = TRAIN_PATH
, test = None
, valid_pct = 0.2
, dl_tfms = get_transforms()
, size = size
, bs = 32).normalize(imagenet_stats)
I think I might be missing something in the DataBunch creation using the second method or is the issue somewhere else? Could anyone please help me with this? Please let me know if some other detail is required in the question. Thanks in advance!
Thanks for the reply and the notebook!
I went through the notebook and I am having the same structure as well, but I’m still facing the same issue, any particular reason it’s not working for me?
See the Test folder and Train folder are both under the happy_sugar_life folder under the data folder?
That is because I use these code:
path = Path('data/happy_sugar_life') #Step 1, set a path varble to store the path
Step 2, put the path varible into the object’s function “ImageDataBunch.from_folder()”
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,
ds_tfms=get_transforms(), size=256, num_workers=4).normalize(imagenet_stats)
Step3: data.show_batch(rows=3, figsize=(7,8)) #you got it.
Please tag me if you still have question. Otherwise, I don’t know you are trying to reply me.
I got your example, so the function is by default looking for a “train” folder within the base path that we send in the argument. But, yesterday when I gave the “Train” specific path in the ImageDataBunch folder it did not throw any error specifically so I got a little confused. Only in the show_batch function I faced an error.
Today, when I try the same thing, ImageDataBunch creation itself throws the error when I give the “Train” specifc path.
But, both seems to work fine for the DataBlock API. Anyway, thanks a lot for your inputs. I think it is working as expected now.