MCPcopy Create free account
hub / github.com/MooreThreads/Moore-AnimateAnyone / DWposeDetector

Class DWposeDetector

src/dwpose/__init__.py:39–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38
39class DWposeDetector:
40 def __init__(self):
41 pass
42
43 def to(self, device):
44 self.pose_estimation = Wholebody(device)
45 return self
46
47 def cal_height(self, input_image):
48 input_image = cv2.cvtColor(
49 np.array(input_image, dtype=np.uint8), cv2.COLOR_RGB2BGR
50 )
51
52 input_image = HWC3(input_image)
53 H, W, C = input_image.shape
54 with torch.no_grad():
55 candidate, subset = self.pose_estimation(input_image)
56 nums, keys, locs = candidate.shape
57 # candidate[..., 0] /= float(W)
58 # candidate[..., 1] /= float(H)
59 body = candidate
60 return body[0, ..., 1].min(), body[..., 1].max() - body[..., 1].min()
61
62 def __call__(
63 self,
64 input_image,
65 detect_resolution=512,
66 image_resolution=512,
67 output_type="pil",
68 **kwargs,
69 ):
70 input_image = cv2.cvtColor(
71 np.array(input_image, dtype=np.uint8), cv2.COLOR_RGB2BGR
72 )
73
74 input_image = HWC3(input_image)
75 input_image = resize_image(input_image, detect_resolution)
76 H, W, C = input_image.shape
77 with torch.no_grad():
78 candidate, subset = self.pose_estimation(input_image)
79 nums, keys, locs = candidate.shape
80 candidate[..., 0] /= float(W)
81 candidate[..., 1] /= float(H)
82 score = subset[:, :18]
83 max_ind = np.mean(score, axis=-1).argmax(axis=0)
84 score = score[[max_ind]]
85 body = candidate[:, :18].copy()
86 body = body[[max_ind]]
87 nums = 1
88 body = body.reshape(nums * 18, locs)
89 body_score = copy.deepcopy(score)
90 for i in range(len(score)):
91 for j in range(len(score[i])):
92 if score[i][j] > 0.3:
93 score[i][j] = int(18 * i + j)
94 else:
95 score[i][j] = -1
96

Callers 3

log_validationFunction · 0.90
vid2pose.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected