# training strides = [8, 16, 32, 64, 128] limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512], [512, 999999]] # inference score_threshold = 0.3 nms_iou_threshold = 0.2 max_detection_boxes_num = 20 model = FCOSDetector(mode="inference", config=Config) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model = torch.nn.DataParallel(model) model.load_state_dict( torch.load("./checkpoint/coco_37.2.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.eval() print("===>success loading model") import os root = "./out_images/" names = os.listdir(root) for name in names: img_bgr = cv2.imread(root + name) img_pad = preprocess_img(img_bgr, [800, 1333]) img = cv2.cvtColor(img_pad.copy(), cv2.COLOR_BGR2RGB) img1 = transforms.ToTensor()(img)
from dataset.VOC_dataset import VOCDataset from model.config import DefaultConfig config = DefaultConfig eval_dataset = VOCDataset(root_dir='/data/Datasets/voc/VOCdevkit/VOC2007', resize_size=[640, 800], split='test', use_difficult=False, is_train=False, augment=None, mean=config.mean, std=config.std) print("INFO===>eval dataset has %d imgs"%len(eval_dataset)) eval_loader=torch.utils.data.DataLoader(eval_dataset,batch_size=1,shuffle=False,collate_fn=eval_dataset.collate_fn) model=FCOSDetector(mode="inference") # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model = torch.nn.DataParallel(model) #model.load_state_dict(torch.load("./darknet19_ms_60epochs/model_59.pth",map_location=torch.device('cpu'))) #model.load_state_dict(torch.load("./finetune_darknet_lasso0.3/model_slim_10.pth", map_location=torch.device('cpu'))) model.load_state_dict(torch.load("./darknet19_ms_2x_lasso_v1_lambda5e_1_from_scratch/model_21.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model=model.cuda().eval() print("===>success loading model") gt_boxes=[] gt_classes=[] pred_boxes=[] pred_classes=[] pred_scores=[] num=0 for img,boxes,classes in eval_loader: with torch.no_grad(): out=model(img.cuda()) pred_boxes.append(out[2][0].cpu().numpy())
#training strides = [8, 16, 32, 64, 128] limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512], [512, 999999]] #inference score_threshold = 0.2 nms_iou_threshold = 0.5 max_detection_boxes_num = 150 model = FCOSDetector(mode="inference", config=Config) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/fcos/voc2012_512x800_epoch59_loss0.5531.pth",map_location=torch.device('cpu'))) model.load_state_dict( torch.load( "/mnt/hdd1/benkebishe01/fcos/voc2012_512x800_epoch59_loss0.5531.pth" )) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") import os root = "./test_images/" names = os.listdir(root) for name in names: img_bgr = cv2.imread(root + name) img_pad = preprocess_img(img_bgr, [512, 512]) img_rgb = cv2.cvtColor(img_pad.copy(), cv2.COLOR_BGR2RGB) img1 = transforms.ToTensor()(img_rgb) # img=img_pad.copy().transpose(2, 0, 1)
# write output json.dump(results, open('coco_bbox_results.json', 'w'), indent=4) # json.dump(image_ids, open('{}_processed_image_ids.json'.format(generator.set_name), 'w'), indent=4) # load results in COCO evaluation tool coco_true = generator.coco coco_pred = coco_true.loadRes('coco_bbox_results.json') # run COCO evaluation coco_eval = COCOeval(coco_true, coco_pred, 'bbox') coco_eval.params.imgIds = image_ids coco_eval.evaluate() coco_eval.accumulate() coco_eval.summarize() return coco_eval.stats if __name__ == "__main__": generator = COCOGenerator( "./data/coco/coco2017/val2017", "./data/coco/coco2017/annotations/instances_val2017.json") model = FCOSDetector(mode="inference") model = torch.nn.DataParallel(model) model = model.cuda().eval() mode_path = './checkpoint/coco_37.2.pth' mode_path = './checkpoint/coco2017/model_10.pth' model.load_state_dict( torch.load(mode_path, map_location=torch.device('cpu'))) evaluate_coco(generator, model)
# lr = lr*warmup_factor lr = float(GLOBAL_STEPS / WARMPUP_STEPS * LR_INIT) else: for i in range(len(lr_schedule)): if step < lr_schedule[i]: break lr *= 0.1 return float(lr) model.train() init_epoch = 0 if opt.resume: checkpoint = torch.load(opt.resumed_path) model.load_state_dict(checkpoint['model_state_dict']) optimizer.load_state_dict(checkpoint['optimizer_state_dict']) initepoch = checkpoint['epoch'] + 1 GLOBAL_STEPS = checkpoint['GLOBAL_STEPS'] for epoch in range(init_epoch, EPOCHS): base = 0.1 lr = LR_INIT def update_lr(lr, base): lr = LR_INIT * base for param in optimizer.param_groups: param['lr'] = lr base *= 0.1 return lr, base
from model.fcos import FCOSDetector from demo import convertSyncBNtoBN from dataloader.VOC_dataset import VOCDataset eval_dataset = VOCDataset(cfg.dataset_dir, resize_size=cfg.image_scale, split='val') print("INFO===>eval dataset has %d imgs" % len(eval_dataset)) eval_loader = torch.utils.data.DataLoader( eval_dataset, batch_size=1, shuffle=False, collate_fn=eval_dataset.collate_fn) model = FCOSDetector(mode="inference") model.load_state_dict( torch.load("voc2012_512x800_epoch61_loss0.7096.pth", map_location=torch.device('cpu'))) model = model.cuda().eval() print("===>success loading model") gt_boxes = [] gt_classes = [] pred_boxes = [] pred_classes = [] pred_scores = [] num = 0 for img, boxes, classes in eval_loader: with torch.no_grad(): out = model(img.cuda()) pred_boxes.append(out[2][0].cpu().numpy()) pred_classes.append(out[1][0].cpu().numpy())
import cv2 from model.fcos import FCOSDetector import torch from torchvision import transforms import numpy as np from dataloader.VOC_dataset import VOCDataset import time import os from model.config import DefaultConfig as cfg if __name__ == "__main__": model = FCOSDetector(mode="inference", config=cfg) model.load_state_dict( torch.load("FCOSMASK_epoch61_loss1.0623.pth", map_location=torch.device('cpu'))) model = model.cuda().eval() print("===>success loading model") root = cfg.inference_dir names = os.listdir(root) for name in names: img_pad = cv2.imread(root + name) img = img_pad.copy() img_t = torch.from_numpy(img).float().permute(2, 0, 1) img1 = transforms.Normalize([102.9801, 115.9465, 122.7717], [1., 1., 1.])(img_t) img1 = img1.cuda() start_t = time.time() with torch.no_grad(): out = model(img1.unsqueeze_(dim=0)) end_t = time.time()
eval_dataset = VOCDataset("/home/data/voc2007_2012/VOCdevkit/VOC2012", resize_size=[800, 1024], split='val2007') print("INFO===>eval dataset has %d imgs" % len(eval_dataset)) eval_loader = torch.utils.data.DataLoader( eval_dataset, batch_size=1, shuffle=False, collate_fn=eval_dataset.collate_fn) model = FCOSDetector(mode="inference") # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model.load_state_dict( torch.load( "./logs/voc20172012_multigpu_800x1024_epoch27_loss0.5987.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") gt_boxes = [] gt_classes = [] pred_boxes = [] pred_classes = [] pred_scores = [] num = 0 for img, boxes, classes in eval_loader: with torch.no_grad(): out = model(img.cuda())
nms_iou_threshold = 0.5 max_detection_boxes_num = 500 transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)) ]) model = FCOSDetector(mode="inference", config=Config) # model = torch.nn.DataParallel(model) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/fcos_val/voc2012_epoch80_loss1.1556.pth")) # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/diou/new_voc3/voc_epoch25_loss1.1657.pth")) model.load_state_dict( torch.load( "/mnt/hdd1/benkebishe01/dianwang/five/new1.0/voc_epoch29_loss0.3873.pth" )) # retinanet_kmean_ml/voc_epoch20_loss0.1154.pth # retinanet_ml_new/voc_epoch24_loss0.1074.pth # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/fcos_without_sample/voc2012_epoch74_loss0.9278.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.to(device).eval() print("===>success loading model") import os root = "./images/test_new/" names = os.listdir(root) for name in names: img_in = cv2.imread(root + name)
from model.fcos import FCOSDetector import torch from dataloader.VOC_dataset import VOCDataset import math,time from torch.utils.tensorboard import SummaryWriter from model.config import DefaultConfig as cfg train_dataset=VOCDataset(cfg.dataset_dir,resize_size=cfg.image_scale,split='train') val_dataset=VOCDataset(cfg.dataset_dir,resize_size=[512,800],split='val') model=FCOSDetector(mode="training").cuda() if cfg.resume_path: model.load_state_dict(torch.load(cfg.resume_path)) optimizer=torch.optim.Adam(model.parameters(),lr=1e-4) BATCH_SIZE=cfg.BATCH_SIZE EPOCHS=cfg.EPOCHS WARMPUP_STEPS_RATIO=cfg.WARMPUP_STEPS_RATIO train_loader=torch.utils.data.DataLoader(train_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=train_dataset.collate_fn) val_loader=torch.utils.data.DataLoader(val_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=val_dataset.collate_fn) steps_per_epoch=len(train_dataset)//BATCH_SIZE TOTAL_STEPS=steps_per_epoch*EPOCHS WARMPUP_STEPS=TOTAL_STEPS*WARMPUP_STEPS_RATIO GLOBAL_STEPS=cfg.GLOBAL_STEPS LR_INIT=cfg.LR_INIT LR_END=cfg.LR_END writer=SummaryWriter(log_dir="./logs")
# ##scene_head_para # input_channel=512 # output_channel=512 # pooling_size=3 # output_class=10 # from model.config import DefaultConfig # DefaultConfig.score_threshold=0.3 model = FCOSDetector(mode="inference").cuda() model = torch.nn.DataParallel(model) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model.load_state_dict( torch.load( "shidudi1e4Diormixupmuti_label_simgoid0.4_0.0001_50_C3_C4_C5_conc_max_pooling_192fcos_8001024_epoch60_loss0.0774.pth", map_location=torch.device('cuda')), False) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") import os root = "./test_images/" names = os.listdir(root) for name in names: img_bgr = cv2.imread(root + name) img_pad = preprocess_img(img_bgr, [800, 1024]) # img=cv2.cvtColor(img_pad.copy(),cv2.COLOR_BGR2RGB) img = img_pad.copy()
#training strides = [8, 16, 32, 64, 128] limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512], [512, 999999]] #inference score_threshold = 0.2 nms_iou_threshold = 0.5 max_detection_boxes_num = 150 model = FCOSDetector(mode="inference", config=Config) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model.load_state_dict( torch.load("./convert_weights/FCOS_R_50_FPN_1x_my.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") import os root = "./test_images/" names = os.listdir(root) for name in names: img_bgr = cv2.imread(root + name) img_pad = preprocess_img(img_bgr, [800, 1024]) # img=cv2.cvtColor(img_pad.copy(),cv2.COLOR_BGR2RGB) img = img_pad.copy() img_t = torch.from_numpy(img).float().permute(2, 0, 1)
"global_steps:%d epoch:%d steps:%d/%d cls_loss:%.4f cnt_loss:%.4f reg_loss:%.4f cost_time:%dms lr=%.4e total_loss:%.4f" % \ (GLOBAL_STEPS, epoch + 1, epoch_step + 1, steps_per_epoch, losses[0].mean(), losses[1].mean(), losses[2].mean(), cost_time, lr, loss.mean())) GLOBAL_STEPS += 1 for idx in range(4): summary.add_scalar(loss_list[idx], losses[idx][0], epoch) torch.save(model.state_dict(), "./checkpoint2/model_{}.pth".format(epoch + 1)) # if epoch + 1 > 23: model2 = FCOSDetector(mode="inference") model2 = torch.nn.DataParallel(model2) model2 = model2.cuda().eval() model2.load_state_dict(torch.load( "./checkpoint2/model_{}.pth".format(epoch + 1), map_location=torch.device('cuda:1')), strict=False) tt = coco_eval.evaluate_coco(val_dataset, model2) m_acc = tt[4].astype(float) if m_acc > best_acc: best_acc = m_acc best_ep = epoch + 1 data_ = dict() for idx, key in enumerate(eval_list): summary.add_scalar(key, tt[idx].astype(float), epoch) print("Best Acc of Medium : {0}, Best Ep of Medium : {1}".format( best_acc, best_ep)) summary.close()
img_size=512, transform=transform, train=False), batch_size=64, shuffle=False) # eval_dataset=VOCDataset("/home/data/voc2007_2012/VOCdevkit/VOC2012",resize_size=[800,1024],split='val2007') # print("INFO===>eval dataset has %d imgs"%len(eval_dataset)) # eval_loader=torch.utils.data.DataLoader(eval_dataset,batch_size=1,shuffle=False,collate_fn=eval_dataset.collate_fn) model = FCOSDetector(mode="inference") # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") # model.load_state_dict(torch.load("./logs/voc20172012_multigpu_800x1024_epoch27_loss0.5987.pth", map_location=torch.device('cpu'))) model.load_state_dict( torch.load( "/mnt/hdd1/benkebishe01/FCOS/diou/60epoch/9nocnt_norm/voc_epoch51_loss0.2903.pth" )) # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/diou/new_voc3/voc_epoch80_loss0.8905.pth")) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") # model = model.cuda().eval() model = model.to(device).eval() print("===>success loading model") gt_boxes = [] gt_classes = [] pred_boxes = [] pred_classes = [] pred_scores = [] num = 0 for img, boxes, classes, _, _ in val_loader:
# append detection to results results.append(image_result) # append image to list of processed images # image_ids.append(generator.ids[index]) if not len(results): return # write output json.dump(results, open('coco_bbox_results.json', 'w'), indent=4) # json.dump(image_ids, open('{}_processed_image_ids.json'.format(generator.set_name), 'w'), indent=4) # load results in COCO evaluation tool coco_true = generator.coco coco_pred = coco_true.loadRes('coco_bbox_results.json') # run COCO evaluation coco_eval = COCOeval(coco_true, coco_pred, 'bbox') coco_eval.params.imgIds = image_ids coco_eval.evaluate() coco_eval.accumulate() coco_eval.summarize() return coco_eval.stats if __name__ == "__main__": generator=COCOGenerator("/home/data/coco2017/val2017","/home/data/coco2017/instances_val2017.json") model=FCOSDetector(mode="inference") model.load_state_dict(torch.load("./logs/1121/coco2017_multigpu_800x1024_epoch4_loss1.2863.pth",map_location=torch.device('cpu'))) evaluate_coco(generator,model)
@Author: xxxmy @Github: github.com/VectXmy @Date: 2019-09-26 @Email: [email protected] ''' from model.fcos import FCOSDetector import torch from dataloader.VOC_dataset import VOCDataset import math,time from torch.utils.tensorboard import SummaryWriter train_dataset=VOCDataset("/home/xht/voc2012/VOCdevkit/VOC2012",resize_size=[512,800],split='train') val_dataset=VOCDataset("/home/xht/voc2012/VOCdevkit/VOC2012",resize_size=[512,800],split='val') model=FCOSDetector(mode="training").cuda() model.load_state_dict(torch.load("./checkpoints/voc_512x800_loss2.0635.pth")) optimizer=torch.optim.Adam(model.parameters(),lr=1e-4) BATCH_SIZE=6 EPOCHS=30 WARMPUP_STEPS_RATIO=0.12 train_loader=torch.utils.data.DataLoader(train_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=train_dataset.collate_fn) val_loader=torch.utils.data.DataLoader(val_dataset,batch_size=BATCH_SIZE,shuffle=True,collate_fn=val_dataset.collate_fn) steps_per_epoch=len(train_dataset)//BATCH_SIZE TOTAL_STEPS=steps_per_epoch*EPOCHS WARMPUP_STEPS=TOTAL_STEPS*WARMPUP_STEPS_RATIO GLOBAL_STEPS=1 LR_INIT=5e-5 LR_END=1e-6
#training strides = [8, 16, 32, 64, 128] limit_range = [[-1, 64], [64, 128], [128, 256], [256, 512], [512, 999999]] #inference score_threshold = 0.3 nms_iou_threshold = 0.4 max_detection_boxes_num = 300 model = FCOSDetector(mode="inference", config=Config) # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") model = torch.nn.DataParallel(model) model.load_state_dict( torch.load("./checkpoint/voc_78.7.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.eval() print("===>success loading model") import os root = "./test_images/" names = os.listdir(root) for name in names: img_bgr = cv2.imread(root + name) img_pad = preprocess_img(img_bgr, [800, 1333]) img = cv2.cvtColor(img_pad.copy(), cv2.COLOR_BGR2RGB) img1 = transforms.ToTensor()(img) img1 = transforms.Normalize([0.485, 0.456, 0.406],
model_path = './checkpoint/simo/model_8_800_1200_45.pth' model_path = './checkpoint/simo_asff/model_8_800_1200_50.pth' model_path = './checkpoint/effi_lite_simo/model_8_512_512_45.pth' model_path = './checkpoint/effi_lite_mimo/model_8_512_512_41.pth' model_path = './checkpoint/effi_lite_mimo/model_8_608_608_45.pth' model_path = './checkpoint/effi_lite_mimo/model_8_640_640_60.pth' model_path = './checkpoint/simo_dcn/model_8_720_1024_50.pth' model_path = './checkpoint/simo_fpn_dcn/model_8_720_1024_50.pth' model_path = './checkpoint/simo_fpn_dcn_focal/model_8_720_1024_45.pth' model_path = './checkpoint/dcn_simo/model_8_720_1024_60.pth' model_path = './checkpoint/simo_3d_maxf/model_8_720_1024_45.pth' if opt.checkpoint: model_path = opt.checkpoint # model_path = './checkpoint/simo_ircnn/model_8_720_1024_45.pth' # model_path = './checkpoint/voc_77.8.pth' model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')), strict=opt.strict) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") gt_boxes=[] gt_classes=[] pred_boxes=[] pred_classes=[] pred_scores=[] num=0 for img,boxes,classes in eval_loader: with torch.no_grad(): out=model(img.cuda()) pred_boxes.append(out[2][0].cpu().numpy())
shuffle=False) draw = False if draw: writer = SummaryWriter(comment='voc_mAP') model = FCOSDetector(mode="inference") # model.load_state_dict(torch.load("/mnt/hdd1/benkebishe01/FCOS/80epoch/fcos_voc_3/voc_epoch80_loss0.8893.pth")) model = model.to(device).eval() print("===>success loading model") names = os.listdir(model_root) names = sorted(names, key=functools.cmp_to_key(compare)) for name in names: # print(name) model.load_state_dict(torch.load(os.path.join(model_root + "/" + name))) gt_boxes = [] gt_classes = [] pred_boxes = [] pred_classes = [] pred_scores = [] num = 0 for img, boxes, classes, _, _ in val_loader: with torch.no_grad(): # out = model(img.cuda()) out = model(img.to(device)) # xxx = out[2][0] # yyy = out[1][0] for i in range(boxes.shape[0]): pred_boxes.append(out[2][i].cpu().numpy())
"D:\\Research\\My_tamper_detect_dataset_train_val_test\\voc_dataset_tmp", resize_size=[800, 1024], split='test') print("INFO===>eval dataset has %d imgs" % len(eval_dataset)) eval_loader = torch.utils.data.DataLoader( eval_dataset, batch_size=1, shuffle=False, collate_fn=eval_dataset.collate_fn) model = FCOSDetector(mode="inference") # model=torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) # print("INFO===>success convert BN to SyncBN") ## model.load_state_dict(torch.load("./logs/voc20172012_multigpu_800x1024_epoch27_loss0.5987.pth",map_location=torch.device('cpu'))) model.load_state_dict( torch.load( "./checkPoints/checkPointsTmp/voc2012_512x800_epoch25_loss0.9422.pth", map_location=torch.device('cpu'))) # model=convertSyncBNtoBN(model) # print("INFO===>success convert SyncBN to BN") model = model.cuda().eval() print("===>success loading model") gt_boxes = [] gt_classes = [] pred_boxes = [] pred_classes = [] pred_scores = [] num = 0 for img, boxes, classes in eval_loader: with torch.no_grad(): out = model(img.cuda())
"person", "pottedplant", "sheep", "sofa", "train", "tvmonitor", ) model = FCOSDetector(mode="inference", config=Config) # model = torch.nn.DataParallel(model) ckpt = torch.load('/mnt/hdd1/benkebishe01/FCOS/fcos_fusion/voc2012_512x512_epoch71_loss0.7739.pth') # ckpt = torch.load('/mnt/hdd1/benkebishe01/fcos_anchor/voc2012_512x512_epoch68_loss0.7201.pth') model.load_state_dict(ckpt) model.to(device).eval() print('loading weights successfully...') transform = transforms.Compose([ transforms.ToTensor(), transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)) ]) def preprocess_img(img, img_size=416): # img = np.array(img) # h w img = img[..., :3] # pdb.set_trace() h, w, _ = img.shape dim_diff = np.abs(h - w) # Upper (left) and lower (right) padding
json.dump(results, open('coco_bbox_results.json', 'w'), indent=4) # json.dump(image_ids, open('{}_processed_image_ids.json'.format(generator.set_name), 'w'), indent=4) # load results in COCO evaluation tool coco_true = generator.coco coco_pred = coco_true.loadRes('coco_bbox_results.json') # run COCO evaluation coco_eval = COCOeval(coco_true, coco_pred, 'bbox') coco_eval.params.imgIds = image_ids coco_eval.evaluate() coco_eval.accumulate() coco_eval.summarize() return coco_eval.stats if __name__ == "__main__": resize_ = [600, 600] generator = COCOGenerator( "/HDD/jaeha/dataset/COCO/2017/val2017", '/HDD/jaeha/dataset/COCO/2017/annotations/changed_instances_val2017.json', resize_size=resize_) model = FCOSDetector(mode="inference") model = torch.nn.DataParallel(model) model = model.cuda().eval() model.load_state_dict(torch.load("./checkpoint_dilation_300/model_48.pth", map_location=torch.device('cuda:0')), strict=False) tmp = evaluate_coco(generator, model)