Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pose prediction of result error #337

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions easycv/predictors/pose_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from easycv.utils.misc import deprecated
from .base import InputProcessor, OutputProcessor, PredictorV2

np.set_printoptions(suppress=True)


def _box2cs(image_size, box):
"""This encodes bbox(x,y,w,h) into (center, scale)
Expand Down Expand Up @@ -222,11 +224,12 @@ def process_single(self, input):
bboxes = bboxes[valid_idx]
person_results = [person_results[i] for i in valid_idx]

output_person_info = []
results = []
for person_result in person_results:
box = person_result['bbox'] # x,y,x,y
box = [box[0], box[1], box[2] - box[0], box[3] - box[1]] # x,y,w,h
center, scale = _box2cs(self.cfg.data_cfg['image_size'], box)
box = person_result['bbox'] # x,y,x,y,s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个s是什么

boxc = [box[0], box[1], box[2] - box[0],
box[3] - box[1]] # x,y,w,h
center, scale = _box2cs(self.cfg.data_cfg['image_size'], boxc)
data = {
'image_id':
0,
Expand Down Expand Up @@ -264,11 +267,10 @@ def process_single(self, input):
output['img_fields'],
}
box_id += 1
output_person_info.append(data)
data_processor = self.processor(data)
data_processor['bbox'] = box
results.append(data_processor)

results = []
for output in output_person_info:
results.append(self.processor(output))
return results

def __call__(self, inputs):
Expand Down Expand Up @@ -296,12 +298,7 @@ class PoseTopDownOutputProcessor(OutputProcessor):
def __call__(self, inputs):
output = {}
output['keypoints'] = inputs['preds']
output['bbox'] = inputs['boxes'] # c1, c2, s1, s2, area, core

for i, bbox in enumerate(output['bbox']):
center, scale = bbox[:2], bbox[2:4]
output['bbox'][i][:4] = bbox_cs2xyxy(center, scale)
output['bbox'] = output['bbox'][:, [0, 1, 2, 3, 5]]
output['bbox'] = np.array(inputs['boxes']) # x1, y1, x2, y2 score

return output

Expand Down Expand Up @@ -403,6 +400,7 @@ def prepare_model(self):
return model

def model_forward(self, inputs, return_heatmap=False):
boxes = inputs['bbox'].cpu().numpy()
if self.model_type == 'raw':
with torch.no_grad():
result = self.model(
Expand All @@ -423,6 +421,7 @@ def model_forward(self, inputs, return_heatmap=False):
result = decode_heatmap(output_heatmap, img_metas,
self.cfg.model.test_cfg)

result['boxes'] = np.array(boxes)
return result

def get_input_processor(self):
Expand Down
Loading