MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / Database

Class Database

PATH/core/solvers/utils/peddet_tester_dev.py:484–624  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482 return scorelist
483
484class Database(object):
485 def __init__(self, gtpath=None, dtpath=None, body_key=None, head_key=None, mode=0):
486 """
487 mode=0: only body; mode=1: only head
488 """
489 self.images = dict()
490 self.eval_mode = mode
491 self.loadData(gtpath, body_key, head_key, if_gt=True)
492 self.loadData(dtpath, body_key, head_key, if_gt=False)
493
494 self._ignNum = sum([self.images[i]._ignNum for i in self.images])
495 self._gtNum = sum([self.images[i]._gtNum for i in self.images])
496 self._imageNum = len(self.images)
497 self.scorelist = None
498
499 def loadData(self, fpath, body_key=None, head_key=None, if_gt=True):
500 # assert os.path.isfile(fpath), fpath + " does not exist!"
501 with PetrelHelper.open(fpath) as f:
502 # with open(fpath, "r") as f:
503 lines = []
504 for line in f:
505 lines.append(line)
506 records = [json.loads(line.strip('\n')) for line in lines]
507 if if_gt:
508 records = records[0]
509 for record in records:
510 self.images[record["ID"]] = Image(self.eval_mode)
511 self.images[record["ID"]].load(record, body_key, head_key, PERSON_CLASSES, True)
512 else:
513 for record in records:
514 self.images[record["ID"]].load(record, body_key, head_key, PERSON_CLASSES, False)
515 self.images[record["ID"]].clip_all_boader()
516
517 def compare(self, thres=0.5, matching=None):
518 """
519 match the detection results with the groundtruth in the whole database
520 """
521 assert matching is None or matching == "VOC", matching
522 scorelist = list()
523 for ID in self.images:
524 if matching == "VOC":
525 result = self.images[ID].compare_voc(thres)
526 else:
527 result = self.images[ID].compare_caltech(thres)
528 scorelist.extend(result)
529 # In the descending sort of dtbox score.
530 scorelist.sort(key=lambda x: x[0][-1], reverse=True)
531 self.scorelist = scorelist
532
533 def eval_MR(self, ref="CALTECH_-2", fppiX=None, fppiY=None):
534 """
535 evaluate by Caltech-style log-average miss rate
536 ref: str - "CALTECH_-2"/"CALTECH_-4"
537 """
538 # find greater_than
539 def _find_gt(lst, target):
540 for idx, item in enumerate(lst):
541 if item >= target:

Calls

no outgoing calls

Tested by 1