forked from sowei728/tensorflow_for_YOLOv3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_data.py
50 lines (40 loc) · 1.42 KB
/
load_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
import numpy as np
import h5py
import io
import PIL.Image as P
class load_data(object):
def __init__(self,batch,path):
self.batch = batch
self.h5file = h5py.File(path,'r')
self.start = 0
def handle(self,img,box):
im = P.open(io.BytesIO(img))
size = np.array([im.width, im.height])
size = np.expand_dims(size, axis=0)
image = im.resize((416, 416), P.BICUBIC)
image = np.array(image, np.float)
image /= 255.
image = np.expand_dims(image,axis=0)
boxes = box.reshape((-1, 5))
box_xy = .5 * (boxes[:, 3:5] + boxes[:, 1:3])
box_wh = boxes[:, 3:5] - boxes[:, 1:3]
box_xy = box_xy / size
box_wh = box_wh / size
boxes = np.concatenate((box_xy, box_wh, boxes[:, 0:1]), axis=1)
# boxes = np.expand_dims(boxes,axis=0)
# print("boxes",boxes)
# print(111)
return image,boxes
def get(self):
images = self.h5file['train/images'].value[self.start:self.start + self.batch]
boxes = self.h5file['train/boxes'].value[self.start:self.start + self.batch]
for i in range(self.batch):
im,box = self.handle(images[i],boxes[i])
self.start += self.batch
self.start = self.start % 39
return im,box
if __name__ == '__main__':
lo = load_data(1,'voc_apple.hdf5')
for i in range(10):
im,b = lo.get()
print(im.shape,b.shape)