def do_eval(evaluator, model, vcoco_set, save_dir, postfix=""): results = evaluator.evaluate_model(model, "vcoco_val", ld.COCO_IMGDIR) outfile = os.path.join(save_dir, "evaluation%s.pkl" % postfix) with open(outfile, "w") as f: pik.dump(results, f) vcocoeval = VCOCOeval(ld.get_vsrl_labels(vcoco_set), ld.COCO_VCOCO_ANN, ld.get_ids(vcoco_set)) vcocoeval._do_eval(outfile, ovr_thresh=0.5)
folder_name = '{}'.format(first_word) from vsrl_eval import VCOCOeval #vsrl_annot_file='/media/data/iftekhar/v-coco/data/vcoco/vcoco_val.json' #split_file='/media/data/iftekhar/v-coco/data/splits/vcoco_val.ids' if flag == 'train': vsrl_annot_file_s = path + '/data/vcoco/vcoco_train.json' split_file_s = path + '/data/splits/vcoco_train.ids' elif flag == 'test': vsrl_annot_file_s = path + '/data/vcoco/vcoco_test.json' split_file_s = path + '/data/splits/vcoco_test.ids' elif flag == 'val': vsrl_annot_file_s = path + '/data/vcoco/vcoco_val.json' split_file_s = path + '/data/splits/vcoco_val.ids' coco_file_s = path + '/data/instances_vcoco_all_2014.json' vcocoeval = VCOCOeval(vsrl_annot_file_s, coco_file_s, split_file_s) #try: # file_name='/home/iftekhar/object_interact/codes_object_interact/'+folder_name+'/'+'{}{}.pickle'.format(flag,saving_epoch) #except: file_name = '../' + folder_name + '/' + '{}{}.pickle'.format( flag, saving_epoch) print(file_name) with open(file_name, 'rb') as handle: b = pickle.load(handle) print(len(b)) vcocoeval._do_eval(b, ovr_thresh=0.5) #print(b[1]['person_box'])
human_thres = 0.3 object_thres = 0.1 action_thres = 0.05 np.random.seed(3) detection = [] DATA_DIR = '/home/wangtiancai/data/vcoco' with open(DATA_DIR + '/' + 'prior_mask.pkl', 'rb') as f: prior_mask = pickle.load(f, encoding='latin1') with open(DATA_DIR + '/' + 'Test_Faster_RCNN_R-50-PFN_2x_VCOCO.pkl', 'rb') as f: Test_RCNN = pickle.load(f, encoding='latin1') Action_dic = json.load(open(DATA_DIR + '/' + 'action_index.json')) Action_dic_inv = {y: x for x, y in Action_dic.items()} ROOT_DIR = '/home/wangtiancai/data/vcoco/' output_file = ROOT_DIR + '/Results/' + 'SS' + '_' + 'HOI' + '.pkl' vcocoeval = VCOCOeval(DATA_DIR + '/' + 'vcoco_test.json', DATA_DIR + '/' + 'instances_vcoco_all_2014.json', DATA_DIR + '/' + 'vcoco_test.ids') test(opt, Test_RCNN, prior_mask, Action_dic_inv, output_file, human_thres, object_thres, action_thres, detection) vcocoeval._do_eval(output_file, ovr_thresh=0.5)
model = LIGHTEN_image(spatial_subnet=cfg.SPATIAL_SUBNET, drop=0.0) res50 = torch.hub.load('pytorch/vision:v0.5.0', 'resnet50', pretrained=True) res50 = torch.nn.Sequential(*(list(res50.children())[:-1])) res50.cuda() res50.eval() sigmoid = nn.Sigmoid() model.float().cuda() model.eval() # set to true if test scores are already computed do_eval_only = False if do_eval_only: vcocoeval = VCOCOeval( os.path.join(cfg.VCOCO_EVAL_DIR, 'vcoco/vcoco_test.json'), os.path.join(cfg.VCOCO_EVAL_DIR, 'instances_vcoco_all_2014.json'), os.path.join(cfg.VCOCO_EVAL_DIR, 'splits/vcoco_test.ids')) vcocoeval._do_eval(save_path, ovr_thresh=0.5) print(save_path) exit(1) experiment_name = cfg.SPATIAL_SUBNET if cfg.TRAIN_VAL: experiment_name += '_trainVal' checkpoint_file = os.path.join(cfg.CHECKPOINT_DIR, 'checkpoint_' + experiment_name + '.pth') if os.path.exists(checkpoint_file): checkpoint = torch.load(checkpoint_file) model.load_state_dict(checkpoint['state_dict']) print('Loaded model from checkpoint')
action_kind][rn] if new_pred_dict[keytwo][4] > score: #print new_pred_dict[keytwo], obj_box continue new_pred_dict[keytwo] = obj_box elif score > 0.1: print action_dict[action_kind], score new_pred_dict['person_box'] = person_box new_pred_dict[keyone] = score new_pred_dict['image_id'] = imgid if not found: prediction_list.append(new_pred_dict) pickle_out = open("detections.pkl", "wb") pickle.dump(prediction_list, pickle_out) pickle_out.close() from vsrl_eval import VCOCOeval vsrl_annot_file = 'data/vcoco/vcoco_val.json' coco_file = 'data/instances_vcoco_all_2017.json' split_file = 'data/splits/vcoco_val.ids' det_file = 'detections.pkl' vcocoeval = VCOCOeval(vsrl_annot_file, coco_file, split_file) fp, fn = vcocoeval._do_eval(det_file, ovr_thresh=0.5) pickle_out = open("fp_fn_samples.pkl", "wb") pickle.dump([fp, fn], pickle_out) pickle_out.close()