-
Notifications
You must be signed in to change notification settings - Fork 858
Expand file tree
/
Copy pathvalid_loader.py
More file actions
32 lines (28 loc) · 1.12 KB
/
valid_loader.py
File metadata and controls
32 lines (28 loc) · 1.12 KB
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
import cv2
import numpy as np
import openpyxl
from .transform_img import transform_img
def valid_data_loader(datadir, annotiondir):
labeldir = annotiondir
def reader(batch_size=50):
images = []
labels = []
workbook = openpyxl.load_workbook(labeldir, data_only=True)
worksheet = workbook.active
for row in worksheet.iter_rows(min_row=2, max_row=worksheet.max_row):
image = cv2.imread(datadir + '/' + row[1].value)
image = transform_img(image)
images.append(image)
label = float(row[2].value)
labels.append(label)
if len(images) == batch_size:
images_array = np.array(images).astype('float32')
labels_array = np.array(labels).astype('float32').reshape(-1, 1)
yield images_array, labels_array
images = []
labels = []
if len(images) > 0:
images_array = np.array(images).astype('float32')
labels_array = np.array(labels).astype('float32').reshape(-1, 1)
yield images_array, labels_array
return reader