一个随机变量的问题急求qwq求大神救救孩子万分感谢!!
2个回答
展开全部
import os import csv TRAIN_IMG_DIR = '/home/yourname/Documents/tensorflow/images/500pics2/train' TRAIN_CSV_DIR = '/home/yourname/Documents/tensorflow/images/500pics2/train_labels.csv' TEST_IMG_DIR = '/home/yourname/Documents/tensorflow/images/500pics2/test' TEST_CSV_DIR = '/home/yourname/Documents/tensorflow/images/500pics2/test_labels.csv' def mkcsv(img_dir, csv_dir): list = [] list.append(['File Name','Label']) for file_name in os.listdir(img_dir): if file_name[0] == '3': #bus item = [file_name, 0] elif file_name[0] == '4': #dinosaur item = [file_name, 1] elif file_name[0] == '5': #elephant item = [file_name, 2] elif file_name[0] == '6': #flower item = [file_name, 3] else: item = [file_name, 4] #horse list.append(item) print(list) f = open(csv_dir, 'w', newline='') writer = csv.writer(f) writer.writerows(list) mkcsv(TRAIN_IMG_DIR, TRAIN_CSV_DIR) mkcsv(TEST_IMG_DIR, TEST_CSV_DIR)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询