Skip to content

Commit f96e810

Browse files
committed
优化计算过程
1 parent c6d6b2e commit f96e810

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

angle.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ def cal(coords, confidence, keypoint_thresh=0.2):
6161
# 角度对比
6262
def compare(self, angles):
6363
stdAngle = self.stdAngles[self.pos] # 每次读取一行标准角度
64-
scores = []
64+
scores = np.empty(len(angles))
6565
visibles = ~np.isnan(stdAngle) # 样本中没有缺失值的
6666
stdAngle = stdAngle[visibles] # 过滤掉样本中的缺失值
67-
for angle in angles:
67+
for i, angle in enumerate(angles):
6868
angle_v = angle[visibles] # 过滤样本中也有缺失值的点
6969
if np.isnan(angle_v).any(): # 还有缺失值
70-
scores.append('NaN')
70+
scores[i] = np.nan
7171
else:
72-
score = 1 - np.tanh(mean_squared_error(angle_v, stdAngle))
73-
scores.append('{:.4f}'.format(score))
72+
score = 100 * (1 - np.tanh(mean_squared_error(angle_v, stdAngle)))
73+
scores[i] = score
7474
self.pos += 1
7575

7676
return scores

run.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,15 @@
4141
pose_input, upscale_bbox = detector_to_simple_pose(img, class_IDs, scores, bounding_boxs, ctx=ctx)
4242

4343
# 姿态识别
44+
results = None
4445
if len(upscale_bbox) > 0:
4546
predicted_heatmap = estimator(pose_input)
4647
pred_coords, confidence = heatmap_to_coord(predicted_heatmap, upscale_bbox)
4748
img = cv_plot_keypoints(img, pred_coords, confidence, class_IDs, bounding_boxs, scores)
4849

4950
# 动作对比
5051
angles = AngeleCal.cal(pred_coords, confidence)
51-
results = angeleCal.compare(angles)
52-
else:
53-
results = ['NaN']
52+
results = angeleCal.compare(angles).astype('U5')
5453

5554
# 缩放示例视频并合并显示
5655
height = int(img.shape[0])

0 commit comments

Comments
 (0)