Git Product home page Git Product logo

Comments (1)

stefanopini avatar stefanopini commented on June 24, 2024

Hi,

To evaluate the accuracy on COCO, I used the official cocoapi and mirrored the code used in the official HRNet repository.
If you want to change the default behaviour, you can take a look at them and update the functions

  • evaluate_overall_accuracy
    def evaluate_overall_accuracy(self, predictions, bounding_boxes, image_paths, output_dir, rank=0.):
    res_folder = os.path.join(output_dir, 'results')
    if not os.path.exists(res_folder):
    os.makedirs(res_folder, 0o755, exist_ok=True)
    res_file = os.path.join(res_folder, 'keypoints_{}_results_{}.json'.format(self.data_version, rank))
    # person x (keypoints)
    _kpts = []
    for idx, kpt in enumerate(predictions):
    _kpts.append({
    'keypoints': kpt,
    'center': bounding_boxes[idx][0:2],
    'scale': bounding_boxes[idx][2:4],
    'area': bounding_boxes[idx][4],
    'score': bounding_boxes[idx][5],
    'image': int(image_paths[idx][-16:-4])
    })
    # image x person x (keypoints)
    kpts = defaultdict(list)
    for kpt in _kpts:
    kpts[kpt['image']].append(kpt)
    # rescoring and oks nms
    num_joints = self.nof_joints
    in_vis_thre = self.in_vis_thre
    oks_thre = self.oks_thre
    oks_nmsed_kpts = []
    for img in kpts.keys():
    img_kpts = kpts[img]
    for n_p in img_kpts:
    box_score = n_p['score']
    kpt_score = 0
    valid_num = 0
    for n_jt in range(0, num_joints):
    t_s = n_p['keypoints'][n_jt][2]
    if t_s > in_vis_thre:
    kpt_score = kpt_score + t_s
    valid_num = valid_num + 1
    if valid_num != 0:
    kpt_score = kpt_score / valid_num
    # rescoring
    n_p['score'] = kpt_score * box_score
    if self.soft_nms:
    keep = soft_oks_nms([img_kpts[i] for i in range(len(img_kpts))], oks_thre)
    else:
    keep = oks_nms([img_kpts[i] for i in range(len(img_kpts))], oks_thre)
    if len(keep) == 0:
    oks_nmsed_kpts.append(img_kpts)
    else:
    oks_nmsed_kpts.append([img_kpts[_keep] for _keep in keep])
    self._write_coco_keypoint_results(oks_nmsed_kpts, res_file)
    if 'test' not in self.data_version:
    info_str = self._do_python_keypoint_eval(res_file)
    name_value = OrderedDict(info_str)
    return name_value, name_value['AP']
    else:
    return {'Null': 0}, 0
  • _do_python_keypoint_eval
    def _do_python_keypoint_eval(self, res_file):
    coco_dt = self.coco.loadRes(res_file)
    coco_eval = COCOeval(self.coco, coco_dt, 'keypoints')
    coco_eval.params.useSegm = None
    coco_eval.evaluate()
    coco_eval.accumulate()
    coco_eval.summarize()
    stats_names = ['AP', 'Ap .5', 'AP .75', 'AP (M)', 'AP (L)', 'AR', 'AR .5', 'AR .75', 'AR (M)', 'AR (L)']
    info_str = []
    for ind, name in enumerate(stats_names):
    info_str.append((name, coco_eval.stats[ind]))
    return info_str

from simple-hrnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.