Ejemplo n.º 1
0
    def evaluate(self, eval_loader):
        mAP, aps, pr_curves = eval_fcos_det(self.cfg,
                                            self.criterion,
                                            eval_loader,
                                            self.model,
                                            rescale=None)

        logging.info(f"score_threshold:{self.cfg.TEST.SCORE_THRESHOLD}, "
                     f"nms_iou:{self.cfg.TEST.NMS_THRESHOLD}")
        logging.info(f'mean Average Precision Across All Classes:{mAP}')

        if mAP > self.best_performance or True:
            # save PR curve
            if self.cfg.TEST.PR_CURVE:
                for class_idx, pr_curve in enumerate(pr_curves):
                    self.writer.add_figure(f'PR_curve/class_{class_idx + 1}',
                                           pr_curve, self.iter)
                logging.info('PR curves saved')
            # save detected result
            if self.cfg.TEST.IMAGE_DIR != '':
                transform = PredictionTransform(resize=cfg.TEST.TEST_SIZE)
                run_fcos_det_example(self.cfg, self.criterion,
                                     self.cfg.TEST.IMAGE_DIR, transform,
                                     self.model)
                logging.info('test detected result saved')

        return mAP
    emb = InceptionResnetV1(pretrained='vggface2', classify=False)
    assert cfg.MODEL.APPEARANCE.WEIGHTS != ''
    load_eval_model(cfg.MODEL.APPEARANCE.WEIGHTS, emb)
    emb.cuda().eval()

    # read test frame images
    if osp.isdir(args.frame_dir):
        file_names = os.listdir(args.frame_dir)
        jpg_paths = [
            osp.join(args.frame_dir, file_name) for file_name in file_names
        ]
    else:
        raise FileNotFoundError

    criterion = FCOSLoss(cfg, cfg.DATASET.NUM_CLASSES)
    det_transform = PredictionTransform(size=cfg.TEST.TEST_SIZE)
    ap_transform = TNTTransform(size=(cfg.TEST.CROP_SZIE))
    crop_transform = FacenetInferenceTransform(size=(cfg.TEST.CROP_SZIE))

    # get det result dict using the detector
    det_result = {}
    crop_im = {}
    class_dict = {
        0: 'DontCare',
        1: 'Pedestrian',
        2: 'Car',
        3: 'Cyclist',
        4: 'Van',
        5: 'Truck',
        6: 'Person',
        7: 'Tram',
Ejemplo n.º 3
0
    model.cuda()
    model.eval()

    if cfg.MODEL.RESUME_PATH != '':
        if osp.exists(cfg.MODEL.RESUME_PATH):
            print(f'==> model load from {cfg.MODEL.RESUME_PATH}')
            checkpoint = torch.load(cfg.MODEL.RESUME_PATH)
            if 'state_dict' in checkpoint:
                model.load_state_dict(checkpoint['state_dict'])
            else:
                model.load_state_dict(checkpoint)
        else:
            print(f"==> checkpoint do not exists: \"{cfg.MODEL.RESUME_PATH}\"")
            raise FileNotFoundError

    transform = PredictionTransform(size=(352, 1216))

    if not osp.exists('crop_det'):
        os.mkdir('crop_det')

    video_list = os.listdir(args.videos_root)
    for video_name in video_list:
        video_crop_path = osp.join('crop_det', video_name)
        if not osp.exists(video_crop_path):
            os.mkdir(video_crop_path)
        video_path = osp.join(args.videos_root, video_name)
        jpg_paths = []
        # read test images
        if osp.isfile(video_path):
            jpg_paths = [video_path]
        elif osp.isdir(video_path):