def recall(model, loader, args, it): split = loader.dataset.split keys = [] if args.dtp_only: features = edtp.extract_features(model, loader, args, args.numpy) res = postprocessing_dtp(features, loader, args) for ot in args.overlap_thresholds: keys += ['%d_total_recall_%d' % (i, ot * 100) for i in range(1, 4)] keys += ['%d_total_proposals' % i for i in range(1, 4)] else: features = et.extract_features(model, loader, args, args.numpy) res = postprocessing(features, loader, args) for i in range(1, 4): for ot in args.overlap_thresholds: keys += [ '%d_dtp_recall_%d' % (i, ot * 100), '%d_rpn_recall_%d' % (i, ot * 100), '%d_total_recall_%d' % (i, ot * 100) ] for i in range(1, 4): keys += [ '%d_total_proposals' % i, '%d_dtp_proposals' % i, '%d_rpn_proposals' % i ] avg = average_dictionary(res, keys, scale=True) log = '\n\n Fold %d\n' % loader.dataset.fold log += '--------------------------------\n' if args.dtp_only: for ot in args.overlap_thresholds: for i, rtype in enumerate(['a', 't', 'n']): total_recall = avg['%d_total_recall_%d' % (i + 1, ot * 100)] total_np = avg['%d_total_proposals' % (i + 1)] / 100 pargs = (rtype, total_recall, total_np, ot * 100) rs2 = '%s: total: %.2f, %.2f using %d%% overlap' % pargs log += '[%s set] %s\n' % ('test', rs2) else: for ot in args.overlap_thresholds: for i, rtype in enumerate(['a', 't', 'n']): rpn_recall = avg['%d_rpn_recall_%d' % (i + 1, ot * 100)] dtp_recall = avg['%d_dtp_recall_%d' % (i + 1, ot * 100)] total_recall = avg['%d_total_recall_%d' % (i + 1, ot * 100)] rpn_np = avg['%d_rpn_proposals' % (i + 1)] / 100 total_np = avg['%d_total_proposals' % (i + 1)] / 100 dtp_np = avg['%d_dtp_proposals' % (i + 1)] / 100 # pargs = (rtype, rpn_recall, dtp_recall, total_recall, ot*100) pargs = (rtype, rpn_recall, rpn_np, dtp_recall, dtp_np, total_recall, total_np, ot * 100) # rs2 = '%s: rpn_recall: %.2f, dtp_recall: %.2f, total recall: %.2f using %d%% overlap' % pargs rs2 = '%s: rpn: %.2f, %d, dtp: %.2f, %d, total: %.2f, %d using %d%% overlap' % pargs log += '[%s set] %s\n' % (split, rs2) log += '--------------------------------\n' return log, avg
def final_log(dicts, keys, title): res = average_dictionary(dicts, keys, False, True) pargs = (res.mAP_qbe_25, res.mAP_qbs_25, res.mR_qbe_25, res.mR_qbs_25) s1 = 'QbE mAP: %.1f, QbS mAP: %.1f, QbE mR: %.1f, QbS mR: %.1f, 25%% overlap' % pargs pargs = (res.mAP_qbe_50, res.mAP_qbs_50, res.mR_qbe_50, res.mR_qbs_50) s2 = 'QbE mAP: %.1f, QbS mAP: %.1f, QbE mR: %.1f, QbS mR: %.1f, 50%% overlap' % pargs log = '%s\n--------------------------------\n' % title log += '[test set] %s\n' % s1 log += '[test set] %s\n' % s2 log += '--------------------------------\n' return log
opt.weights = opt.weights[:s] + ('fold%d' % fold) + opt.weights[e:] opt.fold = fold if opt.h5: testset = h5_dataset.H5Dataset(opt, split=2) opt.num_workers = 0 else: testset = datasets.Dataset(opt, 'test') loader = DataLoader(testset, batch_size=1, shuffle=False, num_workers=0) model.load_weights(opt.weights) model.cuda() log, rf, rt = mAP(model, loader, args, 0) rt['log'] = average_dictionary(rt['log'], r_keys) copy_log(rt) print(log) rts.append(rt) else: log, _, avg = mAP(model, loader, args, 0) avg['log'] = average_dictionary(avg['log'], r_keys) copy_log(avg) rts = [avg] print(log) def final_log(dicts, keys, title): res = average_dictionary(dicts, keys, False, True) pargs = (res.mAP_qbe_25, res.mAP_qbs_25, res.mR_qbe_25, res.mR_qbs_25)
if opt.h5: testset = h5_dataset.H5Dataset(opt, split=2) opt.num_workers = 0 else: testset = datasets.Dataset(opt, 'test') loader = DataLoader(testset, batch_size=1, shuffle=False, num_workers=0) model = ctrlf.CtrlFNet(opt) model.load_state_dict(torch.load(opt.weights)) model.cuda() log, rf, rt = mAP(model, loader, args, 0) print(log) rt['log'] = average_dictionary(rt['log'], r_keys) rf['log'] = average_dictionary( rf['log'], ['3_total_recall_50', '3_total_recall_25']) copy_log(rt, rf) rts.append(rt) rfs.append(rf) avg_rts = average_dictionary(rts, keys + r_keys) avg_rfs = average_dictionary( rfs, keys + ['3_total_recall_50', '3_total_recall_25']) else: log, rf, rt = mAP(model, loader, args, 0) print(log) #average pagewise recalls rt['log'] = average_dictionary(rt['log'], r_keys)
testset = h5_dataset.H5Dataset(opt, split=2) opt.num_workers = 0 else: testset = datasets.Dataset(opt, 'test') loader = DataLoader(testset, batch_size=1, shuffle=False, num_workers=0) model.load_state_dict(torch.load(opt.weights)) model.cuda() log, avg = recall(model, loader, args, 0) avg.append(avg) avg = average_dictionary(avg, r_keys) else: if opt.h5: testset = h5_dataset.H5Dataset(opt, split=2) opt.num_workers = 0 else: testset = datasets.Dataset(opt, 'test') loader = DataLoader(testset, batch_size=1, shuffle=False, num_workers=0) log, avg = recall(model, loader, args, 0) log = '\n\n' log += 'Averaged over folds\n' log += '--------------------------------\n' if dtp_only or not args.use_external_proposals: for ot in args.overlap_thresholds: