text stringlengths 1 93.6k |
|---|
elif opt.model_type == 'FBPNSR_RBPN_V2':
|
model = FBPNSR_RBPN_V2(base_filter=256, feat = 64, num_stages=3, n_resblock=5, scale_factor=opt.upscale_factor)
|
elif opt.model_type == 'FBPNSR_RBPN_V3':
|
model = FBPNSR_RBPN_V3(base_filter=256, feat = 64, num_stages=3, n_resblock=5, scale_factor=opt.upscale_factor)
|
elif opt.model_type == 'FBPNSR_RBPN_V4':
|
model = FBPNSR_RBPN_V4(base_filter=256, feat = 64, num_stages=3, n_resblock=5, scale_factor=opt.upscale_factor)
|
if cuda:
|
model = torch.nn.DataParallel(model, device_ids=gpus_list)
|
def print_network(net):
|
num_params = 0
|
for param in net.parameters():
|
num_params += param.numel()
|
print(net)
|
print('Total number of parameters: %d' % num_params)
|
print('---------- Networks architecture -------------')
|
print_network(model)
|
print('----------------------------------------------')
|
model.load_state_dict(torch.load(opt.model, map_location=lambda storage, loc: storage))
|
print('Pre-trained SR model is loaded.')
|
if cuda:
|
model = model.cuda(gpus_list[0])
|
def eval():
|
model.eval()
|
avg_psnr_predicted = 0.0
|
for batch in testing_data_loader:
|
input, flow_f, flow_b, filename, d_dir = batch[0], batch[1], batch[2], batch[3], batch[4]
|
with torch.no_grad():
|
t_im1 = Variable(input[0]).cuda(gpus_list[0])
|
t_im2 = Variable(input[1]).cuda(gpus_list[0])
|
t_flow_f = Variable(flow_f).cuda(gpus_list[0]).float()
|
t_flow_b = Variable(flow_b).cuda(gpus_list[0]).float()
|
t0 = time.time()
|
if opt.chop_forward:
|
with torch.no_grad():
|
pred_l = chop_forward(t_im1, t_im2, t_flow_f, t_flow_b, model)
|
else:
|
with torch.no_grad():
|
_, _, _, pred_l = model(t_im1, t_im2, t_flow_f, t_flow_b, train=False)
|
t1 = time.time()
|
print("===> Processing: %s || Timer: %.4f sec." % (d_dir[0]+'/frame10i11.png', (t1 - t0)))
|
pred_l = utils.denorm(pred_l[0].cpu().data, vgg=True)
|
pred_1 = utils.denorm(t_im1[0].cpu().data, vgg=True)
|
pred_2 = utils.denorm(t_im2[0].cpu().data, vgg=True)
|
if opt.data_dir == 'ucf101_interp_ours':
|
save_img(pred_1, d_dir[0],'frame_00.png', False)
|
save_img(pred_l, d_dir[0],'frame_01_gt.png', False)
|
save_img(pred_2, d_dir[0],'frame_02.png', False)
|
else:
|
save_img(pred_1, d_dir[0],'im1.png', False)
|
save_img(pred_l, d_dir[0],'im2.png', False)
|
save_img(pred_2, d_dir[0],'im3.png', False)
|
def save_img(img, d_dir,img_name, pred_flag):
|
save_img = img.squeeze().clamp(0, 1).numpy().transpose(1,2,0)
|
filename = os.path.splitext(img_name)
|
# save img
|
save_dir=os.path.join(opt.output, d_dir)
|
if not os.path.exists(save_dir):
|
os.makedirs(save_dir)
|
if pred_flag:
|
save_fn = save_dir +'/'+ filename[0]+'_'+opt.model_type+filename[1]
|
else:
|
save_fn = save_dir +'/'+ img_name
|
cv2.imwrite(save_fn, cv2.cvtColor(save_img*255, cv2.COLOR_BGR2RGB), [cv2.IMWRITE_PNG_COMPRESSION, 0])
|
def chop_forward(t_im1, t_im2, t_flow_f, t_flow_b, model, shave=8, min_size=200000, nGPUs=opt.gpus):
|
b, c, h, w = t_im1.size()
|
h_half, w_half = h // 2, w // 2
|
h_size, w_size = h_half + shave, w_half + shave
|
if h_size%2:
|
h_size = h_size + 1
|
if w_size%2:
|
w_size = w_size + 1
|
inputlist = [
|
[t_im1[:, :, 0:h_size, 0:w_size], t_im2[:, :, 0:h_size, 0:w_size], t_flow_f[:, :, 0:h_size, 0:w_size], t_flow_b[:, :, 0:h_size, 0:w_size]],
|
[t_im1[:, :, 0:h_size, (w - w_size):w],t_im2[:, :, 0:h_size, (w - w_size):w],t_flow_f[:, :, 0:h_size, (w - w_size):w],t_flow_b[:, :, 0:h_size, (w - w_size):w] ],
|
[t_im1[:, :, (h - h_size):h, 0:w_size],t_im2[:, :, (h - h_size):h, 0:w_size],t_flow_f[:, :, (h - h_size):h, 0:w_size],t_flow_b[:, :, (h - h_size):h, 0:w_size] ],
|
[t_im1[:, :, (h - h_size):h, (w - w_size):w],t_im2[:, :, (h - h_size):h, (w - w_size):w],t_flow_f[:, :, (h - h_size):h, (w - w_size):w],t_flow_b[:, :, (h - h_size):h, (w - w_size):w] ]]
|
if w_size * h_size < min_size:
|
outputlist = []
|
for i in range(0, 4, nGPUs):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.