Skip to content

Commit c115c59

Browse files
hkzhang95zisianw
authored andcommitted
Add visualization (zisianw#51)
* add visualization for test.py and update README.md
1 parent 79d6466 commit c115c59

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ $FaceBoxes_ROOT/data/FDDB/images/
7777
python3 test.py --dataset FDDB
7878
# evaluate using cpu
7979
python3 test.py --cpu
80+
# visualize detection results
81+
python3 test.py -s --vis_thres 0.3
8082
```
8183

8284
3. Download [eval_tool](https://bitbucket.org/marcopede/face-eval) to evaluate the performance.

test.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
parser.add_argument('--top_k', default=5000, type=int, help='top_k')
2525
parser.add_argument('--nms_threshold', default=0.3, type=float, help='nms_threshold')
2626
parser.add_argument('--keep_top_k', default=750, type=int, help='keep_top_k')
27+
parser.add_argument('-s', '--show_image', action="store_true", default=False, help='show detection results')
28+
parser.add_argument('--vis_thres', default=0.5, type=float, help='visualization_threshold')
2729
args = parser.parse_args()
2830

2931

@@ -101,7 +103,8 @@ def load_model(model, pretrained_path, load_to_cpu):
101103
# testing begin
102104
for i, img_name in enumerate(test_dataset):
103105
image_path = testset_folder + img_name + '.jpg'
104-
img = np.float32(cv2.imread(image_path, cv2.IMREAD_COLOR))
106+
img_raw = cv2.imread(image_path, cv2.IMREAD_COLOR)
107+
img = np.float32(img_raw)
105108
if resize != 1:
106109
img = cv2.resize(img, None, None, fx=resize, fy=resize, interpolation=cv2.INTER_LINEAR)
107110
im_height, im_width, _ = img.shape
@@ -168,4 +171,20 @@ def load_model(model, pretrained_path, load_to_cpu):
168171
score = dets[k, 4]
169172
fw.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format(img_name, score, xmin, ymin, xmax, ymax))
170173
print('im_detect: {:d}/{:d} forward_pass_time: {:.4f}s misc: {:.4f}s'.format(i + 1, num_images, _t['forward_pass'].average_time, _t['misc'].average_time))
174+
175+
# show image
176+
if args.show_image:
177+
for b in dets:
178+
if b[4] < args.vis_thres:
179+
continue
180+
text = "{:.4f}".format(b[4])
181+
b = list(map(int, b))
182+
cv2.rectangle(img_raw, (b[0], b[1]), (b[2], b[3]), (0, 0, 255), 2)
183+
cx = b[0]
184+
cy = b[1] + 12
185+
cv2.putText(img_raw, text, (cx, cy),
186+
cv2.FONT_HERSHEY_DUPLEX, 0.5, (255, 255, 255))
187+
cv2.imshow('res', img_raw)
188+
cv2.waitKey(0)
189+
171190
fw.close()

0 commit comments

Comments
 (0)