title: Loading images with labels in a csv file OR with their filenames
body: <p>I have a dataset of 500k+ images. All images are in a single folder. The labels are in a csv file with column1 = filename and column2 = class.</p>
  <p>I know there is .flow_from_dataframe however I need to make additional changes before using it in a CNN. I have not been able to find a way of converting the DataFrameIterator object that results from it into either a numpy array or pandas dataframe - unless someone knows how which would solve my issues.</p>
  <p>My alternative is to load the images and labels into 2 different dataframes and then merge them by using the image filename.</p>
  <p>I've used this but can't figure out how to also add the filenames:</p>
  <pre><code>import glob
  cv_img = []
  for img in glob.glob(&quot;foo_test/*.jpg&quot;):
      n= cv2.imread(img)
      cv_img.append(n)
  </code></pre>
  <p>I've also used this:</p>
  <pre><code>import os
  from PIL import Image
  
  path = 'foo_test'
  images = [f for f in os.listdir(path) if os.path.splitext(f)[-1] == '.jpg']
  
  for image in images:
      Image.open(image)
  </code></pre>
  <p>which gives me:</p>
  <pre><code>FileNotFoundError: [Errno 2] No such file or directory: '0.jpg'
  </code></pre>
  <p>although 0.jpg is very much there. I don't see why that would fail.</p>
  <p>I've gone through over 30 posts on Stack Overflow and can't find a simple way of doing this.</p>
  <p>My only other alternative is to move each image into separate folders with the name as class and then load them by folder name for which I already have a code that will 100% work. But with half a million images that's just not feasible.</p>
  <p>Anyone have a better idea?</p>