forked from Naver-AI-Hackathon/AI-Vision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_loader.py
53 lines (42 loc) · 1.5 KB
/
data_loader.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
# -*- coding: utf_8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import cv2
import pickle
def train_data_loader(data_path, img_size, output_path):
label_list = []
img_list = []
label_idx = 0
for root, dirs, files in os.walk(data_path):
if not files:
continue
for filename in files:
img_path = os.path.join(root, filename)
try:
img = cv2.imread(img_path, 1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, img_size)
except:
continue
label_list.append(label_idx)
img_list.append(img)
label_idx += 1
# write output file for caching
with open(output_path[0], 'wb') as img_f:
pickle.dump(img_list, img_f)
with open(output_path[1], 'wb') as label_f:
pickle.dump(label_list, label_f)
# nsml test_data_loader
def test_data_loader(data_path):
data_path = os.path.join(data_path, 'test', 'test_data')
# return full path
queries_path = [os.path.join(data_path, 'query', path) for path in os.listdir(os.path.join(data_path, 'query'))]
references_path = [os.path.join(data_path, 'reference', path) for path in
os.listdir(os.path.join(data_path, 'reference'))]
return queries_path, references_path
if __name__ == '__main__':
query, refer = test_data_loader('./')
print(query)
print(refer)