Hi i’m trying a code from CSNet and i have the next problem…when i a use torch.load there’s an error, now i changed it for torch.tensor and there’s another problem
def PSNR(pred, gt, shave_border=0):
height, width = pred.shape[:2]
pred = pred[shave_border:height - shave_border, shave_border:width - shave_border]
gt = gt[shave_border:height - shave_border, shave_border:width - shave_border]
imdff = pred - gt
rmse = math.sqrt(np.mean(imdff ** 2))
if rmse == 0:
return 100
return 20 * math.log10(255.0 / rmse)
#opt = parser.parse_args()
cuda = cuda
if cuda and not torch.cuda.is_available():
raise Exception(“No GPU found, please run without --cuda”)
model = CSNet(block_size,sub_rate)
if model != ‘’:
model.load_state_dict(torch.tensor(model))
image_list = glob.glob(opt.dataset+"/.")
avg_psnr_predicted = 0.0
avg_elapsed_time = 0.0
for image_name in image_list:
print("Processing ", image_name)
im_gt_y = sio.loadmat(image_name)[‘im_gt_y’]
im_gt_y = im_gt_y.astype(float)

im_input = im_gt_y/255.

im_input = Variable(torch.from_numpy(im_input).float()).view(1, -1, im_input.shape[0], im_input.shape[1])

if cuda:
    model = model.cuda()
    im_input = im_input.cuda()
else:
    model = model.cpu()

start_time = time.time()
res = model(im_input)
elapsed_time = time.time() - start_time
avg_elapsed_time += elapsed_time

res = res.cpu()

im_res_y = res.data[0].numpy().astype(np.float32)

im_res_y = im_res_y*255.
im_res_y[im_res_y<0] = 0
im_res_y[im_res_y>255.] = 255.
im_res_y = im_res_y[0,:,:]

psnr_predicted = PSNR(im_gt_y, im_res_y,shave_border=0)
print(psnr_predicted)
avg_psnr_predicted += psnr_predicted

print(“Dataset=”, opt.dataset)
print(“PSNR_predicted=”, avg_psnr_predicted/len(image_list))
print(“It takes average {}s for processing”.format(avg_elapsed_time/len(image_list)))