title: How to add labels when converting Image files to CSV?
body: <p>I was looking at the deep learning guide on Kaggle. I practiced with a few models with my test data stored in directories with the name of the label (ie TestData\Top and TestData\Bottom for training images to create a model that can tell the top vs the bottom of an item of interest).</p>
  
  <p>However for this lesson for creating your own model (<a href="https://www.kaggle.com/dansbecker/deep-learning-from-scratch" rel="nofollow noreferrer">https://www.kaggle.com/dansbecker/deep-learning-from-scratch</a>), the data needs to be stored in a CSV file with the first column as the label. I have this code which converts the images to grayscale and to a CSV file and grabs the labels:</p>
  
  <pre><code>from PIL import Image
  import numpy as np
  import sys
  import os
  import csv
  import glob
  
  from os import path
  
  TestPath = 'C:\...\outgoingbank'
  
  Labels = []
  myFileList = []
  
  
  for files in os.listdir(TestPath):
      Labels.append(files)
      os.chdir(TestPath)
      for images in os.listdir(files):
          fullName = os.path.join(files, images)
          myFileList.append(fullName)
  
  
  
  print (Labels)
  print(myFileList)
  
  
  for file in myFileList:
     print(file)
     Label = file.split('\\')
     Label = Label[0]
     print (Label)
     img_file = Image.open(file)
  
  
      # get original image parameters...
      width, height = img_file.size
      format = img_file.format
      mode = img_file.mode
  
      # Make image Greyscale
      img_grey = img_file.convert('L')
  
  
      value = np.asarray(img_grey.getdata(), dtype=np.int).reshape((img_grey.size[1], img_grey.size[0]))
      value = value.flatten()
      print(value)
      with open("C:\...\img_pixels.csv", 'a') as f:
          writer = csv.writer(f)
          writer.writerow(value)
  </code></pre>
  
  <p>So I have the labels and the images, and code that converts the images to a CSV, but how would I insert the label into the first row? Also, is it possible to do not convert them to greyscale? (I tried but got a sizing error)</p>
  
  <p>EDIT: I was able to add the labels via:</p>
  
  <pre><code>Test = []
  
  Test.append(Label)
  for i in value:
      Test.append(i)
  
  #print(Test)
  with open("C:\...\img_pixels.csv", 'a') as f:
      writer = csv.writer(f)
      writer.writerow(Test)
  </code></pre>
  
  <p>But I still don't see why this code is only writing to every other row, how do I fix that?</p>