Reputation: 117
There are two image folders names: bad_pictures and good_pictures. Two folders represent two different classes. I am trying to write a python script to make a CSV/JSON file which will contain two columns, one is CONTENT( full path of the images) and another one is LABEL( bad or good). Like:
As far I can remember that we may get the images from a single folder with:
from PIL import Image
import glob
image_list = []
for filename in glob.glob('yourpath/*.jpg'):
im=Image.open(filename)
image_list.append(im)
which is far from my goal. I am hopping your help to figure our the codes to reach my goal.
Upvotes: 0
Views: 860
Reputation: 717
Please check below to generate csv file:
import csv
import glob
path = "d:/so/good_pictures/*.*"
gp=glob.glob(path)
path = "d:/so/bad_pictures/*.*"
bp=glob.glob(path)
with open('test2.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["CONTENT", "LABEL"])
for element in gp:
writer.writerow([element, "good"])
for element in bp:
writer.writerow([element, "bad"])
Upvotes: 1