File not found error in custom dataset

username: cookiemonsterT
cooked: <p>I’m trying to train a CNN in PyTorch to recognise road signs from the GTSRB dataset. I keep getting this error:</p>
<pre><code class="lang-auto">FileNotFoundError                         Traceback (most recent call last)
&lt;ipython-input-7-6a0d3ee5f434&gt; in &lt;module&gt;
      2 
      3 #roadSignTrain = torchvision.datasets.ImageFolder(root='/Users/username/Downloads/roadSigns/train', transform = transform)
----&gt; 4 roadSignTrain = RoadSignDataset(csv_path=r'/Users/username/Downloads/GTSRB/Train/*/*.csv')
      5 trainloader = t.utils.data.DataLoader(roadSignTrain, batch_size=10, shuffle=True, num_workers=0)
      6 
&lt;ipython-input-5-a0c6c7375def&gt; in __init__(self, csv_path)
     22         self.to_tensor = transforms.ToTensor()
     23         #read the CSV file
---&gt; 24         self.data_info = pd.read_csv(csv_path, header=None)
     25         #first column contains the image paths
     26         self.image_arr = np.asarray(self.data_info.iloc[:, 0])
~/opt/anaconda3/lib/python3.8/site-packages/pandas/io/parsers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
    684     )
    685 
--&gt; 686     return _read(filepath_or_buffer, kwds)
    687 
    688 
~/opt/anaconda3/lib/python3.8/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
    450 
    451     # Create the parser.
--&gt; 452     parser = TextFileReader(fp_or_buf, **kwds)
    453 
    454     if chunksize or iterator:
~/opt/anaconda3/lib/python3.8/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
    944             self.options["has_index_names"] = kwds["has_index_names"]
    945 
--&gt; 946         self._make_engine(self.engine)
    947 
    948     def close(self):
~/opt/anaconda3/lib/python3.8/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
   1176     def _make_engine(self, engine="c"):
   1177         if engine == "c":
-&gt; 1178             self._engine = CParserWrapper(self.f, **self.options)
   1179         else:
   1180             if engine == "python":
~/opt/anaconda3/lib/python3.8/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   2006         kwds["usecols"] = self.usecols
   2007 
-&gt; 2008         self._reader = parsers.TextReader(src, **kwds)
   2009         self.unnamed_cols = self._reader.unnamed_cols
   2010 
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()
FileNotFoundError: [Errno 2] No such file or directory: '/Users/username/Downloads/GTSRB/Train/*/*.csv'
</code></pre>
<p>The thing is, I’ve got the images and CSV in the right place. My GTSRB folder is in the downloads, and there are Train and Test folders (yes, spelled correctly).<br>
The Train folder contains subfolders containing all of the images from a certain class, with a CSV file with their filename (within the folder, no path) and class.<br>
The Test folder contains all of the test images, with a CSV file with their filename (within the folder, no path) and class.<br>
Can someone let me know what’s going wrong?</p>
<pre><code class="lang-auto">transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5), (0.5,)), transforms.Resize((48,48))])

roadSignTrain = RoadSignDataset(csv_path='/Users/username/Downloads/GTSRB/Train/*/*.csv')
trainloader = t.utils.data.DataLoader(roadSignTrain, batch_size=10, shuffle=True, num_workers=0)

roadSignTest = RoadSignDataset(csv_path='/Users/username/Downloads/GTSRB/Test/*.csv')
testloader = t.utils.data.DataLoader(roadSignTest, batch_size=10, shuffle=True, num_workers=0)
</code></pre>

username: cookiemonsterT
cooked: <p>Realised I forgot to add the code for the custom dataset. Here it is:</p>
<pre><code class="lang-auto">class RoadSignDataset(Dataset):

    def __init__(self, csv_path):
        self.to_tensor = transforms.ToTensor()
        #read the CSV file
        self.data_info = pd.read_csv(csv_path, header=None)
        #first column contains the image paths
        self.image_arr = np.asarray(self.data_info.iloc[:, 0])
        #second column is the labels
        self.label_arr = np.asarray(self.data_info.iloc[:, 7])
        #calculate len
        self.data_len = len(self.data_info.index)

    def __getitem__(self, index):
        #get image name from the pandas df
        single_image_name = '' + self.image_arr[index]
        #open image
        img_as_img = Image.open(single_image_name)

        #transform image to tensor
        img_as_tensor = self.to_tensor(img_as_img)

        #get label of the image based on the cropped pandas column
        single_image_label = self.label_arr[index]
        return(img_as_tensor, single_image_label)

    def __len__(self):
        return self.data_len

</code></pre>

username: ptrblck
cooked: <p><code>pd.read_csv</code> expects a path to a valid csv file, while you are trying to pass a path containing wildcards.</p>