-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_data.py
110 lines (84 loc) · 2.81 KB
/
read_data.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import pandas as pd
import numpy as np
import shutil
import os
from pathlib import Path
from tqdm import tqdm
import cv2
#%%
src_im_fd = '/home/minjie/dataset/ISIC/ISIC2018_Task3_Training_Input/'
tar_im_fd = './data/ISIC/train18/'
df = pd.read_csv('./data/ISIC/ISIC2018_Task3_Training_GroundTruth.csv')
df_v = df.values
img_name = df_v[:,0]
label_np = df_v[:,1:]
#labels = np.zeros_like(img_name)
#
#for idx,v in enumerate(label_np):
# labels[idx] = np.where(label_np[1]==1)[0][0]
#
labels = [ np.where(v==1)[0][0] for v in label_np]
dict_label = dict()
for i in range(7):
dict_label[i] = df.columns[1:][i]
for val,key in dict_label.items():
os.makedirs(tar_im_fd +key, exist_ok =True)
for idx,fn in enumerate(tqdm(img_name)):
src_fn = Path(src_im_fd)/(fn + '.jpg')
tar_fn = Path(tar_im_fd)/ dict_label[labels[idx]]/(fn + '.jpg')
if os.path.exists(str(src_fn)):
shutil.copyfile(src_fn,tar_fn)
else:
print(f'filename {str(src_fn)} not exist')
#%% write test
df = pd.read_csv('./data/ISIC/ISIC2018_Task3_Testing_Score_imb.csv')
tar_im_fd = './data/ISIC/test18/'
src_im_fd = '/home/minjie/dataset/ISIC/ISIC2018_Task3_Test_Input/'
for val,key in dict_label.items():
os.makedirs(tar_im_fd +key, exist_ok =True)
df_v = df.values
img_name = df_v[:,0]
label_np = df_v[:,1:]
labels = [ np.where(v==v.max())[0][0] for v in label_np]
for idx,fn in enumerate(tqdm(img_name)):
src_fn = Path(src_im_fd)/(fn + '.jpg')
tar_fn = Path(tar_im_fd)/ dict_label[labels[idx]]/(fn + '.jpg')
if os.path.exists(str(src_fn)):
shutil.copyfile(src_fn,tar_fn)
else:
print(f'filename {str(src_fn)} not exist')
#%% read ISIC19 data
src_im_fd = '/home/minjie/dataset/ISIC/ISIC_2019_Training_Input/'
tar_im_fd = './data/ISIC/train19/'
df = pd.read_csv('./data/ISIC/ISIC_2019_Training_GroundTruth.csv')
df_v = df.values
img_name = df_v[:,0]
label_np = df_v[:,1:]
#labels = np.zeros_like(img_name)
#
#for idx,v in enumerate(label_np):
# labels[idx] = np.where(label_np[1]==1)[0][0]
#
labels = [ np.where(v==1)[0][0] for v in label_np]
dict_label = dict()
n_label = len(df.columns)-2
for i in range(n_label):
dict_label[i] = df.columns[1:][i]
dict_label[3]= 'AKIEC'
for val,key in dict_label.items():
os.makedirs(tar_im_fd +key, exist_ok =True)
for idx,fn in enumerate(tqdm(img_name)):
src_fn = Path(src_im_fd)/(fn + '.jpg')
tar_fn = Path(tar_im_fd)/ dict_label[labels[idx]]/(fn + '.jpg')
if os.path.exists(str(src_fn)):
#img = cv2.imread(str(src_fn))
#img_resize = cv2.resize(img,(600,450))
#cv2.imwrite(str(tar_fn),img_resize)
shutil.copyfile(src_fn,tar_fn)
else:
print(f'filename {str(src_fn)} not exist')