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.
- Loading branch information
1 parent
07467fb
commit 08efdf2
Showing
6 changed files
with
187 additions
and
51 deletions.
There are no files selected for viewing
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from dface.prepare_data.widerface_annotation_gen.wider_loader import WIDER | ||
import cv2 | ||
import time | ||
|
||
#wider face original images path | ||
path_to_image = '/idata/data/wider_face/WIDER_train/images' | ||
|
||
#matlab file path | ||
file_to_label = './wider_face_train.mat' | ||
|
||
#target file path | ||
target_file = './anno.txt' | ||
|
||
wider = WIDER(file_to_label, path_to_image) | ||
|
||
|
||
line_count = 0 | ||
box_count = 0 | ||
|
||
print('start transforming....') | ||
t = time.time() | ||
|
||
with open(target_file, 'w+') as f: | ||
# press ctrl-C to stop the process | ||
for data in wider.next(): | ||
line = [] | ||
line.append(str(data.image_name)) | ||
line_count += 1 | ||
for i,box in enumerate(data.bboxes): | ||
box_count += 1 | ||
for j,bvalue in enumerate(box): | ||
line.append(str(bvalue)) | ||
|
||
line.append('\n') | ||
|
||
line_str = ' '.join(line) | ||
f.write(line_str) | ||
|
||
st = time.time()-t | ||
print('end transforming') | ||
|
||
print('spend time:%ld'%st) | ||
print('total line(images):%d'%line_count) | ||
print('total boxes(faces):%d'%box_count) | ||
|
||
|
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import h5py | ||
import os | ||
|
||
|
||
class DATA(object): | ||
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): | ||
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') | ||
|
||
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 | ||
|
||
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) |