forked from kuaikuaikim/dface
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kuaikuaikim#6 from jwz-ecust/master
use scipy to replace h5py loading mat file
- Loading branch information
Showing
1 changed file
with
19 additions
and
27 deletions.
There are no files selected for viewing
46 changes: 19 additions & 27 deletions
46
dface/prepare_data/widerface_annotation_gen/wider_loader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,34 @@ | ||
import h5py | ||
import os | ||
from scipy.io import loadmat | ||
|
||
|
||
class DATA(object): | ||
class DATA: | ||
def __init__(self, image_name, bboxes): | ||
self.image_name = image_name | ||
self.bboxes = bboxes | ||
|
||
|
||
class WIDER(object): | ||
def __init__(self, file_to_label, path_to_image): | ||
def __init__(self, file_to_label, path_to_image=None): | ||
self.file_to_label = file_to_label | ||
self.path_to_image = path_to_image | ||
|
||
self.f = h5py.File(file_to_label, 'r') | ||
self.event_list = self.f.get('event_list') | ||
self.file_list = self.f.get('file_list') | ||
self.face_bbx_list = self.f.get('face_bbx_list') | ||
self.f = loadmat(file_to_label) | ||
self.event_list = self.f['event_list'] | ||
self.file_list = self.f['file_list'] | ||
self.face_bbx_list = self.f['face_bbx_list'] | ||
|
||
def next(self): | ||
|
||
for event_idx, event in enumerate(self.event_list.value[0]): | ||
directory = self.f[event].value.tostring().decode('utf-16') | ||
for im_idx, im in enumerate( | ||
self.f[self.file_list.value[0][event_idx]].value[0]): | ||
|
||
im_name = self.f[im].value.tostring().decode('utf-16') | ||
face_bbx = self.f[self.f[self.face_bbx_list.value | ||
[0][event_idx]].value[0][im_idx]].value | ||
for event_idx, event in enumerate(self.event_list): | ||
e = event[0][0].encode('utf-8') | ||
for file, bbx in zip(self.file_list[event_idx][0], | ||
self.face_bbx_list[event_idx][0]): | ||
f = file[0][0].encode('utf-8') | ||
path_of_image = os.path.join(self.path_to_image, e, f) + ".jpg" | ||
|
||
bboxes = [] | ||
|
||
for i in range(face_bbx.shape[1]): | ||
xmin = int(face_bbx[0][i]) | ||
ymin = int(face_bbx[1][i]) | ||
xmax = int(face_bbx[0][i] + face_bbx[2][i]) | ||
ymax = int(face_bbx[1][i] + face_bbx[3][i]) | ||
bboxes.append((xmin, ymin, xmax, ymax)) | ||
|
||
yield DATA(os.path.join(self.path_to_image, directory, | ||
im_name + '.jpg'), bboxes) | ||
bbx0 = bbx[0] | ||
for i in range(bbx0.shape[0]): | ||
xmin, ymin, xmax, ymax = bbx0[i] | ||
bboxes.append((int(xmin), int(ymin), int(xmax), int(ymax))) | ||
yield DATA(path_of_image, bboxes) | ||
|