-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
38 lines (31 loc) · 1.2 KB
/
demo.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
# ---------------------------------------------------------
# CNNClassificationTensorRT
# Copyright (c) 2019
# Licensed under The MIT License [see LICENSE for details]
# Written by Rudy Nurhadi
# ---------------------------------------------------------
import os
import sys
import cv2
import time
import numpy as np
from CNNClassificationTensorRT import CNNClassificationTensorRT
CWD_PATH = os.path.dirname(os.path.realpath(__file__))
cnnClassificationTensorRT = CNNClassificationTensorRT(os.path.join(CWD_PATH, 'model'), 'gender_recog', 12, rebuild_engine=False)
def main():
imgs = []
for filename in os.listdir('female'):
if filename.endswith(".jpg") or filename.endswith(".png"):
imgs.append(cv2.imread(os.path.join('female', filename)))
now = time.time()
predict_results = cnnClassificationTensorRT.return_predict(imgs)
for i, result in enumerate(predict_results):
if result["confidences"][0] > result["confidences"][1]:
print(result["labels"][0])
else:
print(result["labels"][1])
print("Inference Time: %f" % (time.time() - now))
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
main()