img_in = np.pad(np.rot90(img_lr, 2), ((0,1), (0,1), (0,0)), mode='reflect').transpose((2,0,1)) out_r2 = FourSimplexInterp(LUT, img_in, h, w, q, 2, upscale=UPSCALE) img_in = np.pad(np.rot90(img_lr, 3), ((0,1), (0,1), (0,0)), mode='reflect').transpose((2,0,1)) out_r3 = FourSimplexInterp(LUT, img_in, w, h, q, 1, upscale=UPSCALE) img_out = (out_r0/1.0 + out_r1/1.0 + out_r2/1.0 + out_r3/1.0) / 255.0 img_out = img_out.transpose((1,2,0)) img_out = np.round(np.clip(img_out, 0, 1) * 255).astype(np.uint8) # Matching image sizes if img_gt.shape[0] < img_out.shape[0]: img_out = img_out[:img_gt.shape[0]] if img_gt.shape[1] < img_out.shape[1]: img_out = img_out[:, :img_gt.shape[1]] if img_gt.shape[0] > img_out.shape[0]: img_out = np.pad(img_out, ((0,img_gt.shape[0]-img_out.shape[0]),(0,0),(0,0))) if img_gt.shape[1] > img_out.shape[1]: img_out = np.pad(img_out, ((0,0),(0,img_gt.shape[1]-img_out.shape[1]),(0,0))) # Save to file Image.fromarray(img_out).save('./output_S_x{}_{}bit/{}_LUT_interp_{}bit.png'.format(UPSCALE, SAMPLING_INTERVAL, fn.split('/')[-1][:-4], SAMPLING_INTERVAL)) CROP_S = 4 psnr = PSNR(_rgb2ycbcr(img_gt)[:,:,0], _rgb2ycbcr(img_out)[:,:,0], CROP_S) psnrs.append(psnr) print('AVG PSNR: {}'.format(np.mean(np.asarray(psnrs))))
if img_gt.shape[1] < batch_out.shape[1]: batch_out = batch_out[:, :img_gt.shape[1]] elif img_gt.shape[1] > batch_out.shape[1]: batch_out = np.pad(batch_out, ((0, 0), (0, img_gt.shape[1] - batch_out.shape[1]), (0, 0))) # handling single channel images if len(img_gt.shape) < 3: img_gt = np.tile(img_gt[:, :, np.newaxis], [1, 1, 3]) img_gt_y = np.copy(img_gt)[:, :, 0] batch_out_y = np.copy(batch_out)[:, :, 0] # RGB to Y else: img_gt_y = _rgb2ycbcr(np.copy(img_gt))[:, :, 0] batch_out_y = _rgb2ycbcr(np.copy(batch_out))[:, :, 0] # Save to file out_fn = files_gt[i].split("/")[-1][:-4] Image.fromarray(batch_out).save('./output/Bic/{}/{}.png'.format( testset, out_fn)) # Evaluation CROP_S = 4 # PSNR psnrs.append(PSNR(img_gt_y, batch_out_y, CROP_S)) # SSIM ssims.append(
batch_S3 = model_G(F.pad(torch.rot90(val_L, 2, [2,3]), (0,1,0,1), mode='reflect')) batch_S3 = torch.rot90(batch_S3, 2, [2,3]) batch_S4 = model_G(F.pad(torch.rot90(val_L, 3, [2,3]), (0,1,0,1), mode='reflect')) batch_S4 = torch.rot90(batch_S4, 1, [2,3]) batch_S = ( torch.clamp(batch_S1,-1,1)*127 + torch.clamp(batch_S2,-1,1)*127 ) batch_S += ( torch.clamp(batch_S3,-1,1)*127 + torch.clamp(batch_S4,-1,1)*127 ) batch_S /= 255.0 # Output image_out = (batch_S).cpu().data.numpy() image_out = np.clip(image_out[0], 0. , 1.) # CxHxW image_out = np.transpose(image_out, [1, 2, 0]) # HxWxC # Save to file image_out = ((image_out)*255).astype(np.uint8) Image.fromarray(image_out).save('result/{}/{}.png'.format(str(VERSION), fn.split('/')[-1])) # PSNR on Y channel img_gt = (val_H*255).astype(np.uint8) CROP_S = 4 psnrs.append(PSNR(_rgb2ycbcr(img_gt)[:,:,0], _rgb2ycbcr(image_out)[:,:,0], CROP_S)) print('AVG PSNR: Validation: {}'.format(np.mean(np.asarray(psnrs)))) writer.add_scalar('PSNR_valid', np.mean(np.asarray(psnrs)), i) writer.flush()
np.uint8)).save('{}/result/v{}/{}.png'.format( EXP_NAME, str(VERSION), fn.split('/')[-1])) # PSNR img_gt = (val_H * 255).astype(np.uint8) img_target = ((batch_Out) * 255).astype(np.uint8) CROP_S = 16 if CROP_S > 0: img_gt = img_gt[CROP_S:-CROP_S, CROP_S:-CROP_S] img_target = img_target[CROP_S:-CROP_S, CROP_S:-CROP_S] psnrs.append( PSNR( _rgb2ycbcr(img_gt)[:, :, 0], _rgb2ycbcr(img_target)[:, :, 0], 0)) # LPIPS dist = model_LPIPS.forward( im2tensor(img_target), im2tensor(img_gt)) # RGB image from [0,255] to [-1,1] lpips.append(dist) print('AVG PSNR/LPIPS: Validation: {}/{}'.format( np.mean(np.asarray(psnrs)), np.mean(np.asarray(lpips)))) # Save best model if i % I_SAVE == 0: if np.mean(np.asarray(lpips)) < best_avg_lpips: best_avg_lpips = np.mean(np.asarray(lpips))
img_out = img_out.transpose((1, 2, 0)) img_out = np.round(np.clip(img_out, 0, 1) * 255).astype(np.uint8) # Matching image sizes if img_gt.shape[0] < img_out.shape[0]: img_target = img_out[:img_gt.shape[0]] if img_gt.shape[1] < img_out.shape[1]: img_target = img_out[:, :img_gt.shape[1]] if img_gt.shape[0] > img_out.shape[0]: img_target = np.pad(img_out, ((0, img_gt.shape[0] - img_out.shape[0]), (0, 0), (0, 0))) if img_gt.shape[1] > img_out.shape[1]: img_target = np.pad(img_out, ((0, 0), (0, img_gt.shape[1] - img_out.shape[1]), (0, 0))) # Save to file Image.fromarray(img_out).save( './output_F_x{}_{}bit/{}_LUT_interp_{}bit.png'.format( UPSCALE, SAMPLING_INTERVAL, fn.split('/')[-1][:-4], SAMPLING_INTERVAL)) CROP_S = 4 psnr = PSNR( _rgb2ycbcr(img_gt)[:, :, 0], _rgb2ycbcr(img_out)[:, :, 0], CROP_S) psnrs.append(psnr) print('AVG PSNR: {}'.format(np.mean(np.asarray(psnrs))))