forked from qq523529576/CVPR_SSF-RGBD
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
56 lines (54 loc) · 1.99 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import torch
import torch.nn.functional as F
import time
import numpy as np
import pdb, os, argparse
from scipy import misc
from model.model import model_VGG
from data import test_dataset
from torch.autograd import Variable
parser = argparse.ArgumentParser()
parser.add_argument('--testsize', type=int, default=256, help='testing size')
opt = parser.parse_args()
dataset_path = ''
model = model_VGG()
model.load_state_dict(torch.load(''))
model.cuda()
model.eval()
test_datasets = [ '\\DUT-RGBD\\test_data']
#test_datasets = [ '\\LFSD']
#test_datasets = [ '\\NJUD\\test_data']
#test_datasets = [ '\\NLPR\\test_data']
#test_datasets = [ '\\RGBD135']
#test_datasets = [ '\\SSD']
#test_datasets = [ '\\STEREO']
#test_datasets = [ '\\DUTS-TEST']
#time_start=time.time()
for dataset in test_datasets:
save_path = '' + dataset + '\\results\\'
if not os.path.exists(save_path):
os.makedirs(save_path)
image_root = dataset_path + dataset + '\\images\\'
gt_root = dataset_path + dataset + '\\gts\\'
depth_root = dataset_path + dataset + '\\depths\\'
test_loader = test_dataset(image_root, gt_root,depth_root, opt.testsize)
for i in range(test_loader.size):
image, gt,depth, name = test_loader.load_data()
gt = np.asarray(gt, np.float32)
gt /= (gt.max() + 1e-8)
depth /= (depth.max() + 1e-8)
image = Variable(image).cuda()
depth = Variable(depth).cuda()
n,c, h, w = image.size()
depth1 = depth.view(n,h, w, 1).repeat(1,1, 1, c)
depth1 = depth1.transpose(3, 2)
depth1 = depth1.transpose(2, 1)
time_start = time.time()
_, res, _, _ = model(image, depth1, depth)
res = F.upsample(res, size=gt.shape, mode='bilinear', align_corners=False)
time_end = time.time()
res = res.data.sigmoid().cpu().numpy().squeeze()
res = (res - res.min()) / (res.max() - res.min() + 1e-8)
print(name)
misc.imsave(save_path + name, res)
print('totally cost:',time_end-time_start,'s')