|
|
@@ -4,14 +4,15 @@ import math
|
|
|
from scipy.ndimage.filters import gaussian_filter
|
|
|
import torch
|
|
|
|
|
|
-from service.aiutil import util
|
|
|
-from service.aiutil.model import bodypose_model,bodypose_25_model
|
|
|
+from service.ai.util import util
|
|
|
+from service.ai.util.model import bodypose_model, bodypose_25_model
|
|
|
import logging
|
|
|
|
|
|
model_coco = 'model/body_coco.pth'
|
|
|
model_body25 = 'model/body_25.pth'
|
|
|
np.seterr(divide='ignore', invalid='ignore')
|
|
|
|
|
|
+
|
|
|
class torch_openpose(object):
|
|
|
def __init__(self, model_type):
|
|
|
if model_type == 'body_25':
|
|
|
@@ -29,21 +30,20 @@ class torch_openpose(object):
|
|
|
self.model = self.model.cuda()
|
|
|
self.model.eval()
|
|
|
|
|
|
- if self.njoint == 19: #coco
|
|
|
+ if self.njoint == 19: # coco
|
|
|
self.limbSeq = [[1, 2], [1, 5], [2, 3], [3, 4], [5, 6], [6, 7], [1, 8], [8, 9], \
|
|
|
- [9, 10], [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 16], \
|
|
|
- [0, 15], [15, 17]]
|
|
|
- self.mapIdx = [[12, 13],[20, 21],[14, 15],[16, 17],[22, 23],[24, 25],[0, 1],[2, 3],\
|
|
|
- [4, 5],[6, 7],[8, 9],[10, 11],[28, 29],[30, 31],[34, 35],[32, 33],\
|
|
|
- [36, 37]]
|
|
|
- elif self.njoint == 26: #body_25
|
|
|
- self.limbSeq = [[1,0],[1,2],[2,3],[3,4],[1,5],[5,6],[6,7],[1,8],[8,9],[9,10],\
|
|
|
- [10,11],[8,12],[12,13],[13,14],[0,15],[0,16],[15,17],[16,18],\
|
|
|
- [11,24],[11,22],[14,21],[14,19],[22,23],[19,20]]
|
|
|
- self.mapIdx = [[30, 31],[14, 15],[16, 17],[18, 19],[22, 23],[24, 25],[26, 27],[0, 1],[6, 7],\
|
|
|
- [2, 3],[4, 5], [8, 9],[10, 11],[12, 13],[32, 33],[34, 35],[36,37],[38,39],\
|
|
|
- [50,51],[46,47],[44,45],[40,41],[48,49],[42,43]]
|
|
|
-
|
|
|
+ [9, 10], [1, 11], [11, 12], [12, 13], [1, 0], [0, 14], [14, 16], \
|
|
|
+ [0, 15], [15, 17]]
|
|
|
+ self.mapIdx = [[12, 13], [20, 21], [14, 15], [16, 17], [22, 23], [24, 25], [0, 1], [2, 3], \
|
|
|
+ [4, 5], [6, 7], [8, 9], [10, 11], [28, 29], [30, 31], [34, 35], [32, 33], \
|
|
|
+ [36, 37]]
|
|
|
+ elif self.njoint == 26: # body_25
|
|
|
+ self.limbSeq = [[1, 0], [1, 2], [2, 3], [3, 4], [1, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], \
|
|
|
+ [10, 11], [8, 12], [12, 13], [13, 14], [0, 15], [0, 16], [15, 17], [16, 18], \
|
|
|
+ [11, 24], [11, 22], [14, 21], [14, 19], [22, 23], [19, 20]]
|
|
|
+ self.mapIdx = [[30, 31], [14, 15], [16, 17], [18, 19], [22, 23], [24, 25], [26, 27], [0, 1], [6, 7], \
|
|
|
+ [2, 3], [4, 5], [8, 9], [10, 11], [12, 13], [32, 33], [34, 35], [36, 37], [38, 39], \
|
|
|
+ [50, 51], [46, 47], [44, 45], [40, 41], [48, 49], [42, 43]]
|
|
|
|
|
|
def __call__(self, oriImg):
|
|
|
# scale_search = [0.5, 1.0, 1.5, 2.0]
|
|
|
@@ -107,7 +107,8 @@ class torch_openpose(object):
|
|
|
map_down[:, :-1] = one_heatmap[:, 1:]
|
|
|
|
|
|
peaks_binary = np.logical_and.reduce(
|
|
|
- (one_heatmap >= map_left, one_heatmap >= map_right, one_heatmap >= map_up, one_heatmap >= map_down, one_heatmap > thre1))
|
|
|
+ (one_heatmap >= map_left, one_heatmap >= map_right, one_heatmap >= map_up, one_heatmap >= map_down,
|
|
|
+ one_heatmap > thre1))
|
|
|
peaks = list(zip(np.nonzero(peaks_binary)[1], np.nonzero(peaks_binary)[0])) # note reverse
|
|
|
peaks_with_score = [x + (map_ori[x[1], x[0]],) for x in peaks]
|
|
|
peak_id = range(peak_counter, peak_counter + len(peaks))
|
|
|
@@ -232,10 +233,8 @@ class torch_openpose(object):
|
|
|
if po >= 0:
|
|
|
joint = list(candidate[int(po)][:3])
|
|
|
else:
|
|
|
- joint = [0.,0.,0.]
|
|
|
+ joint = [0., 0., 0.]
|
|
|
pose.append(joint)
|
|
|
poses.append(pose)
|
|
|
|
|
|
return poses
|
|
|
-
|
|
|
-
|