-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrepareImages.py
41 lines (33 loc) · 1.35 KB
/
PrepareImages.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
36
37
38
39
40
import os
import timeit
import cv2
import pandas as pd
import visdom
import torch
from torch.utils.data import Dataset, DataLoader
from tqdm import tqdm
import Preprocessing
from Startup import *
FOLDER_NAME = 'train_images_t3_512'
if __name__ == '__main__':
train_csv = pd.read_csv(os.path.join(INPUT_ROOT, 'trainLabels19.csv'))
if not os.path.exists(os.path.join(INPUT_ROOT, FOLDER_NAME)):
os.makedirs(os.path.join(INPUT_ROOT, FOLDER_NAME))
# run this part first
#ds = PrepareImages(train_csv)
#dl = DataLoader(ds, batch_size=16, num_workers=8)
#with tqdm(range(len(dl))) as pbar:
# for x in dl:
# pbar.update()
# then run this part
vis = visdom.Visdom()
heartbeat_plot = vis.line(Y=[0], X=[0])
for i in tqdm(range(len(train_csv))):
time1 = timeit.default_timer()
id = train_csv.iat[i, 0]
if not os.path.isfile(os.path.join(INPUT_ROOT, FOLDER_NAME, id + '.png')):
img_name = os.path.join(INPUT_ROOT, 'train_images', train_csv.iat[i, 0] + '.png')
image = Preprocessing.load_twangy_color(img_name, image_size=512)
cv2.imwrite(os.path.join(INPUT_ROOT, FOLDER_NAME, train_csv.iat[i, 0] + '.png'), image)
vis.line(Y=[(timeit.default_timer() - time1)], X=[i], win=heartbeat_plot,
update=('append' if i else 'replace'))