-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_csv.py
36 lines (30 loc) · 754 Bytes
/
data_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
import csv
import numpy as np
from sklearn.preprocessing import LabelBinarizer
import glob
import os
from os.path import isfile, join, split
from os import rename, listdir, rename, makedirs
from random import shuffle
import random
import glob
import pickle
import matplotlib.pyplot as plt
train_dir = listdir("test")
# print(train_dir)
images = []
for sub_dir in train_dir:
images += glob.glob(join("test", sub_dir, '*.jpg\n'))
random.Random(64).shuffle(images)
# print(images[:50])
with open("test_image_paths.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(["image_id", "label"])
for i in images[:]:
img_path = i
# print(img_path)
label = i.split("/")[1]
# print(label)
# brd
writer.writerow([img_path, label])