Thanks Marius and Stefano. I moved the labels.csv up a folder in the hierarchy so now that works.
I tried both of your approaches and I was able to use both to create a data frame. I encountered an error when I tried to create a Data Bunch though. Despite having the correct file path and checking manually that the file exists at the command line, the code returns a file not found error. The path in the error message is correct.
I don’t understand why the code cannot find the file when it has the correct path, and I can copy/paste that exact same path in the CLI and find the file without a problem…
path = ‘~/data/histo-cancer/’
df = pd.read_csv(’~/data/histo-cancer/train_labels.csv’)
data = ImageDataBunch.from_df(path, df, folder=“train”, fn_col=0, label_col=1)
data.normalize(imagenet_stats)
FileNotFoundError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
–> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
~/anaconda3/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
398 if cls is not object
399 and callable(cls.dict.get(‘repr’)):
–> 400 return _repr_pprint(obj, self, cycle)
401
402 return _default_pprint(obj, self, cycle)
~/anaconda3/lib/python3.6/site-packages/IPython/lib/pretty.py in repr_pprint(obj, p, cycle)
693 “”“A pprint that just redirects to the normal repr function.”""
694 # Find newlines and replace them with p.break()
–> 695 output = repr(obj)
696 for idx,output_line in enumerate(output.splitlines()):
697 if idx:
~/anaconda3/lib/python3.6/site-packages/fastai/basic_data.py in repr(self)
98
99 def repr(self)->str:
–> 100 return f’{self.class.name};\n\nTrain: {self.train_ds};\n\nValid: {self.valid_ds};\n\nTest: {self.test_ds}’
101
102 @classmethod
~/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in repr(self)
460
461 def repr(self)->str:
–> 462 x = f’{self.x}’ # force this to happen first
463 return f’{self.class.name}\ny: {self.y}\nx: {x}’
464 def predict(self, res):
~/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in repr(self)
58 return self.items[i]
59 def repr(self)->str:
—> 60 items = [self[i] for i in range(min(5,len(self.items)))]
61 return f’{self.class.name} ({len(self)} items)\n{items}…\nPath: {self.path}’
62
~/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in (.0)
58 return self.items[i]
59 def repr(self)->str:
—> 60 items = [self[i] for i in range(min(5,len(self.items)))]
61 return f’{self.class.name} ({len(self)} items)\n{items}…\nPath: {self.path}’
62
~/anaconda3/lib/python3.6/site-packages/fastai/data_block.py in getitem(self, idxs)
90
91 def getitem(self,idxs:int)->Any:
—> 92 if isinstance(try_int(idxs), int): return self.get(idxs)
93 else: return self.new(self.items[idxs], xtra=index_row(self.xtra, idxs))
94
~/anaconda3/lib/python3.6/site-packages/fastai/vision/data.py in get(self, i)
264 def get(self, i):
265 fn = super().get(i)
–> 266 res = self.open(fn)
267 self.sizes[i] = res.size
268 return res
~/anaconda3/lib/python3.6/site-packages/fastai/vision/data.py in open(self, fn)
260 def open(self, fn):
261 “Open image in fn
, subclass and overwrite for custom behavior.”
–> 262 return open_image(fn, convert_mode=self.convert_mode)
263
264 def get(self, i):
~/anaconda3/lib/python3.6/site-packages/fastai/vision/image.py in open_image(fn, div, convert_mode, cls)
374 with warnings.catch_warnings():
375 warnings.simplefilter(“ignore”, UserWarning) # EXIF warning from TiffPlugin
–> 376 x = PIL.Image.open(fn).convert(convert_mode)
377 x = pil2tensor(x,np.float32)
378 if div: x.div_(255)
~/anaconda3/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
2578
2579 if filename:
-> 2580 fp = builtins.open(filename, “rb”)
2581 exclusive_fp = True
2582
FileNotFoundError: [Errno 2] No such file or directory: ‘~/data/histo-cancer/train/c18f2d887b7ae4f6742ee445113fa1aef383ed77.tif’