Import Labels from CSV can find my Images

Hello,

I have the Stanford Cars Dataset. My labels are in a csv file

name,label
train/000001.jpg,AM General Hummer SUV 2000
train/000002.jpg,AM General Hummer SUV 2000
train/000003.jpg,AM General Hummer SUV 2000
train/000004.jpg,AM General Hummer SUV 2000

when I run this

tfms = get_transforms(do_flip=False)
data = ImageDataBunch.from_csv(path, ds_tfms=tfms, size=28)
data.show_batch(rows=3, figsize=(5,5))

I got an file not found error
FileNotFoundError: Traceback (most recent call last):
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py”, line 138, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py”, line 138, in
samples = collate_fn([dataset[i] for i in batch_indices])
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/fastai/data_block.py”, line 483, in getitem
if self.item is None: x,y = self.x[idxs],self.y[idxs]
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/fastai/data_block.py”, line 92, in getitem
if isinstance(try_int(idxs), int): return self.get(idxs)
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/fastai/vision/data.py”, line 266, in get
res = self.open(fn)
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/fastai/vision/data.py”, line 262, in open
return open_image(fn, convert_mode=self.convert_mode)
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/fastai/vision/image.py”, line 376, in open_image
x = PIL.Image.open(fn).convert(convert_mode)
File “/home/nbuser/.anaconda3/lib/python3.7/site-packages/PIL/Image.py”, line 2580, in open
fp = builtins.open(filename, “rb”)
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/nbuser/courses/fast-ai/course-v3/nbs/data/Cars/./valid/002774.jpg’

Here is as ‘/.’ too much between Cars/ and /valid

Where does it come from? I have no idea? Cant find something in the doc of https://docs.fast.ai/vision.data.html#ImageDataBunch

Please give me a thought-provoked

Thanks

Olaf

You need to specify folder and csv file

Path = path to the root folder
It should has arch like
Path
/train
/*.csv
/test

You can use whatever names you like.

Then
.from_csv(path, folder=‘train’,label_csv=‘your.csv’…)

You can take a close look of the Image databunch API, I didn’t use much of the factory method, data block API gives you more control of the steps :slight_smile: Apology if I didn’t get the name right…

Did it.

same result bei ImageImageList.from_csv