-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy patheval.py
87 lines (75 loc) · 2.77 KB
/
eval.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import argparse
import logging
import time
import os
import cv2
import numpy as np
from tf_pose.estimator import TfPoseEstimator
from tf_pose.networks import get_graph_path, model_wh
import scripts.label_image as label_img
import scripts.label_image_scene as label_img_scene
logger = logging.getLogger('Pose_Action_and_Scene_Understanding')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
fps_time = 0
address = '/home/caffemodel/coursework/CVPR/pose-estimation-detection/images-3/'
file_list = os.listdir(address)
true_label_pose = []
true_label_scene = []
img_name = []
img_count = 0
total_time = 0
if __name__ == '__main__':
for file in file_list:
parser = argparse.ArgumentParser(description='tf-pose-estimation realtime webcam')
parser.add_argument('--show-process', type=bool, default=False,
help='for debug purpose, if enabled, speed for inference is dropped.')
args = parser.parse_args()
logger.debug('initialization %s : %s' % ('mobilenet_thin', get_graph_path('mobilenet_thin')))
e = TfPoseEstimator(get_graph_path('mobilenet_thin'), target_size=(432, 368))
image = cv2.imread(address+file)
logger.info('cam image=%dx%d' % (image.shape[1], image.shape[0]))
# count = 0
logger.debug('+image processing+')
logger.debug('+postprocessing+')
start_time = time.time()
humans = e.inference(image, upsample_size=4.0)
img = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
logger.debug('+classification+')
# Getting only the skeletal structure (with white background) of the actual image
image = np.zeros(image.shape,dtype=np.uint8)
image.fill(255)
image = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
# Classification
pose_class = label_img.classify(image)
scene_class = label_img_scene.classify(address+file)
end_time = time.time()
img_count += 1
total_time = total_time + (end_time-start_time)
logger.debug('+Completed image: {}+'.format(img_count))
true_label_pose.append(pose_class)
true_label_scene.append(scene_class)
img_name.append(file)
outF = open("pose.txt", "w")
for line in true_label_pose:
outF.write(line)
outF.write("\n")
outF.close()
outF = open("scene.txt", "w")
for line in true_label_scene:
outF.write(line)
outF.write("\n")
outF.close()
outF = open("img.txt", "w")
for line in img_name:
outF.write(line)
outF.write("\n")
outF.close()
# =============================================================================
# For running the script simply run the following in the cmd prompt/terminal :
# python3 run_image.py --image=test.png
# =============================================================================