Write CSV file for a dataset
1 import numpy as np 2 import cv2 as cv2 3 import os 4 import csv 5 6 7 dataste_path = 'datasets/pascal-parts/pascal/data' 8 dirs= os.listdir(dataste_path) 9 with open("datasets/pascal-parts/pascal/test.csv","w") as csvfile: 10 writer = csv.writer(csvfile) 11 writer.writerow(["source_image","target_image"]) 12 for direc in dirs: 13 if not direc.startswith('.'): 14 print('666') 15 file_list = list() 16 files = os.listdir(os.path.join(dataste_path,direc)) 17 for file in files: 18 if file.endswith('.jpg') and not file.startswith('.') and file[0].isdigit(): 19 file_name = os.path.join('pascal/data',direc,file) 20 file_list.append(file_name) 21 for i in range(len(file_list)): 22 for j in range(len(file_list)): 23 if(i == j): 24 continue 25 else: 26 writer.writerow([file_list[i],file_list[j]]) 27 else: print('888')