Exemplo n.º 1
0
model.load_state_dict(torch.load(opt.model_path, map_location=torch.device('cpu')))
model.eval()

close = False
for dataset in ['COD10K-v3', 'MYTEST', 'CAMO', 'CHAMELEON', 'COD10K']:
    if close:
        break
    save_path = opt.test_save + dataset + '/'
    os.makedirs(save_path, exist_ok=True)

    imgpath = './Dataset/TestDataset/{}/Imgs/'.format(dataset)
    gtpath = './Dataset/TestDataset/{}/GT/'.format(dataset)
    if dataset == 'COD10K-v3':
        imgpath = './Dataset/TestDataset/{}/Image/'.format(dataset)
        gtpath = './Dataset/TestDataset/{}/GT_Instance/'.format(dataset)
    test_loader = test_dataset(imgpath, gtpath, opt.testsize)

    img_count = 1
    for iteration in range(test_loader.size):
        start_time = time.time()
        image, gt, name = test_loader.load_data()

        gt = np.asarray(gt, np.float32)
        gt /= (gt.max() + 1e-8)

        _, cam = model(image)
        cam = F.interpolate(cam, size=gt.shape, mode='bilinear', align_corners=True)
        cam = cam.sigmoid().data.cpu().numpy().squeeze()
        # normalize
        cam = (cam - cam.min()) / (cam.max() - cam.min() + 1e-8)
Exemplo n.º 2
0
parser.add_argument('--model_path',
                    type=str,
                    default='./Snapshot/FeaNet/SINet_Final.pth')
parser.add_argument('--test_save', type=str, default='./Result/FeaNet/')
opt = parser.parse_args()

model = SINet_ResNet50().cuda()
model.load_state_dict(torch.load(opt.model_path))
model.eval()

for dataset in ['COD10K', 'CAMO', 'CHAMELEON']:
    save_path = opt.test_save + dataset + '/'
    os.makedirs(save_path, exist_ok=True)

    test_loader = test_dataset(
        './Dataset/TestDataset/{}/Image/'.format(dataset),
        './Dataset/TestDataset/{}/GT/'.format(dataset), opt.testsize)
    img_count = 0
    totalMae = 0
    for iteration in range(test_loader.size):
        image, gt, name = test_loader.load_data()

        gt = np.asarray(gt, np.float32)
        gt /= (gt.max() + 1e-8)
        image = image.cuda()

        cam, _ = model(image)

        cam = F.upsample(cam,
                         size=gt.shape,
                         mode='bilinear',
Exemplo n.º 3
0
                    default='/content/drive/MyDrive/SINet_40.pth')
parser.add_argument('--test_save',
                    type=str,
                    default='/content/drive/MyDrive/Test/')
opt = parser.parse_args()

model = SINet_ResNet50().cuda()
model.load_state_dict(torch.load(opt.model_path))
model.eval()

for dataset in ['Test10']:
    save_path = opt.test_save + dataset + '/'
    os.makedirs(save_path, exist_ok=True)

    test_loader = test_dataset(
        image_root='/content/drive/MyDrive/video10/'.format(dataset),
        gt_root='/content/drive/MyDrive/Tvideo10/'.format(dataset),
        testsize=opt.testsize)
    img_count = 1
    f = np.zeros(test_loader.size)
    for iteration in range(test_loader.size):
        # load data
        image, gt, name = test_loader.load_data()
        gt = np.asarray(gt, np.float32)
        gt /= (gt.max() + 1e-8)
        image = image.cuda()
        # inference

        _, cam = model(image)
        # reshape and squeeze
        cam = F.upsample(cam,
                         size=gt.shape,
Exemplo n.º 4
0
opt = parser.parse_args()

model = SINet_ResNet50().cuda()
model.load_state_dict(torch.load(opt.model_path))
model.eval()

for dataset in ['COD10K']:
    save_path = opt.test_save + dataset + '/'
    os.makedirs(save_path, exist_ok=True)
    # NOTES:
    #  if you plan to inference on your customized dataset without grouth-truth,
    #  you just modify the params (i.e., `image_root=your_test_img_path` and `gt_root=your_test_img_path`)
    #  with the same filepath. We recover the original size according to the shape of grouth-truth, and thus,
    #  the grouth-truth map is unnecessary actually.
    test_loader = test_dataset(
        image_root='./Dataset/TestDataset/{}/Image/'.format(dataset),
        gt_root='./Dataset/TestDataset/{}/GT/'.format(dataset),
        testsize=opt.testsize)
    img_count = 1
    for iteration in range(test_loader.size):
        # load data
        image, gt, name = test_loader.load_data()
        gt = np.asarray(gt, np.float32)
        gt /= (gt.max() + 1e-8)
        image = image.cuda()
        # inference
        _, cam = model(image)
        # reshape and squeeze
        cam = F.upsample(cam,
                         size=gt.shape,
                         mode='bilinear',
                         align_corners=True)
Exemplo n.º 5
0
model = SINet_ResNet50().cuda()
model.load_state_dict(torch.load(opt.model_path))
model.eval()

for dataset in ['COD10K']:
    #for dataset in ['COD10K-v3/Test']:
    save_path = opt.test_save + dataset + '/'
    os.makedirs(save_path, exist_ok=True)

    # NOTES:
    #  if you plan to inference on your customized dataset without grouth-truth,
    #  you just modify the params (i.e., `image_root=your_test_img_path` and `gt_root=your_test_img_path`)
    #  with the same filepath. We recover the original size according to the shape of grouth-truth, and thus,
    #  the grouth-truth map is unnecessary actually.
    test_loader = test_dataset(image_root=image_root.format(dataset),
                               gt_root=gt_root.format(dataset),
                               testsize=opt.testsize)
    img_count = 1
    for iteration in range(test_loader.size):
        # load data
        image, gt, name = test_loader.load_data()
        gt = np.asarray(gt, np.float32)
        gt /= (gt.max() + 1e-8)
        image = image.cuda()
        # inference
        _, cam = model(image)
        # reshape and squeeze
        cam = F.upsample(cam,
                         size=gt.shape,
                         mode='bilinear',
                         align_corners=True)