InvDN
InvDN copied to clipboard
Test on a single image
How do i try it on a single rgb image without any dataset?
Just load the image and the pretrained model to test.
Could you please provide the code to test with an image in normal format? (.jpg or .png, use cv2.imread for examples)
def my_test(model, opt):
dataset_dir = opt['name']
out_dir = os.path.join( "..", "experiments", dataset_dir)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
out_dir = os.path.join(out_dir, 'my_test')
if not os.path.exists(out_dir):
os.mkdir(out_dir)
# load info
filePath = os.path.join(opt['datasets']['test_1']['dataroot_Noisy'], 'NOISY_SRGB_010.png')
Nimg = cv2.imread(filePath)[:256,:256,:]
print(Nimg.shape)
DenoisedBlocksSrgb = np.empty_like(Nimg)
# process data
Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor)
data = Nimg.unsqueeze(dim=0)
model.feed_test_data(data)
if opt['self_ensemble']:
model.test(opt['self_ensemble'])
elif opt['mc_ensemble']:
model.MC_test()
else:
model.test()
img = model.fake_H.detach().float().cpu()
Idenoised_crop = util.tensor2img_Real(img) # uint8
Idenoised_crop = np.transpose(Idenoised_crop, (1, 2, 0))
DenoisedBlocksSrgb = Idenoised_crop
save_file = os.path.join(out_dir, 'my_test.PNG')
cv2.imwrite(save_file, cv2.cvtColor(Idenoised_crop, cv2.COLOR_RGB2BGR))
print('Executed sucessfully is done\n')
Added this function to test_Real.py to test for a single image But when trying out a single image, I am unable to retrieve the correct denoised image. I have included both my input image and output image. Could anyone tell me what might be causing this ?
Essentially, the image that is passed in, should be normalised. Pixel values should fall between 0 & 1 Afterwhich, it works well. One thing to note would be the size of the input image, it cannot be too large depending on your computer specifications.
def my_test(model, opt): dataset_dir = opt['name'] out_dir = os.path.join( "..", "experiments", dataset_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) out_dir = os.path.join(out_dir, 'my_test') if not os.path.exists(out_dir): os.mkdir(out_dir) # load info filePath = os.path.join(opt['datasets']['test_1']['dataroot_Noisy'], 'NOISY_SRGB_010.png') Nimg = cv2.imread(filePath)[:256,:256,:] print(Nimg.shape) DenoisedBlocksSrgb = np.empty_like(Nimg) # process data Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor) data = Nimg.unsqueeze(dim=0) model.feed_test_data(data) if opt['self_ensemble']: model.test(opt['self_ensemble']) elif opt['mc_ensemble']: model.MC_test() else: model.test() img = model.fake_H.detach().float().cpu() Idenoised_crop = util.tensor2img_Real(img) # uint8 Idenoised_crop = np.transpose(Idenoised_crop, (1, 2, 0)) DenoisedBlocksSrgb = Idenoised_crop save_file = os.path.join(out_dir, 'my_test.PNG') cv2.imwrite(save_file, cv2.cvtColor(Idenoised_crop, cv2.COLOR_RGB2BGR)) print('Executed sucessfully is done\n')
Added this function to test_Real.py to test for a single image But when trying out a single image, I am unable to retrieve the correct denoised image. I have included both my input image and output image. Could anyone tell me what might be causing this ?
您好,我和您出现了一样的问题,请问您是如何解决的呢?
Have to add this line
# process data
Nimg = Nimg / 255.0 # Normalisation
Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor)
Hope it works for you
The problem has been resolved. Thank you for your help.
The problem has been resolved. Thank you for your help.
Can you help me how to use the my_test fun above to test on a single img
def my_test(model, opt): dataset_dir = opt['name'] out_dir = os.path.join( "..", "experiments", dataset_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) out_dir = os.path.join(out_dir, 'my_test') if not os.path.exists(out_dir): os.mkdir(out_dir) # load info filePath = os.path.join(opt['datasets']['test_1']['dataroot_Noisy'], 'NOISY_SRGB_010.png') Nimg = cv2.imread(filePath)[:256,:256,:] print(Nimg.shape) DenoisedBlocksSrgb = np.empty_like(Nimg) # process data Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor) data = Nimg.unsqueeze(dim=0) model.feed_test_data(data) if opt['self_ensemble']: model.test(opt['self_ensemble']) elif opt['mc_ensemble']: model.MC_test() else: model.test() img = model.fake_H.detach().float().cpu() Idenoised_crop = util.tensor2img_Real(img) # uint8 Idenoised_crop = np.transpose(Idenoised_crop, (1, 2, 0)) DenoisedBlocksSrgb = Idenoised_crop save_file = os.path.join(out_dir, 'my_test.PNG') cv2.imwrite(save_file, cv2.cvtColor(Idenoised_crop, cv2.COLOR_RGB2BGR)) print('Executed sucessfully is done\n')
Added this function to test_Real.py to test for a single image But when trying out a single image, I am unable to retrieve the correct denoised image. I have included both my input image and output image. Could anyone tell me what might be causing this ?
can you tell me how to run your codes to test single image, whats you env?
def my_test(model, opt): dataset_dir = opt['name'] out_dir = os.path.join( "..", "experiments", dataset_dir) if not os.path.exists(out_dir): os.makedirs(out_dir) out_dir = os.path.join(out_dir, 'my_test') if not os.path.exists(out_dir): os.mkdir(out_dir) # load info filePath = os.path.join(opt['datasets']['test_1']['dataroot_Noisy'], 'NOISY_SRGB_010.png') Nimg = cv2.imread(filePath)[:256,:256,:] print(Nimg.shape) DenoisedBlocksSrgb = np.empty_like(Nimg) # process data Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor) data = Nimg.unsqueeze(dim=0) model.feed_test_data(data) if opt['self_ensemble']: model.test(opt['self_ensemble']) elif opt['mc_ensemble']: model.MC_test() else: model.test() img = model.fake_H.detach().float().cpu() Idenoised_crop = util.tensor2img_Real(img) # uint8 Idenoised_crop = np.transpose(Idenoised_crop, (1, 2, 0)) DenoisedBlocksSrgb = Idenoised_crop save_file = os.path.join(out_dir, 'my_test.PNG') cv2.imwrite(save_file, cv2.cvtColor(Idenoised_crop, cv2.COLOR_RGB2BGR)) print('Executed sucessfully is done\n')
Added this function to test_Real.py to test for a single image But when trying out a single image, I am unable to retrieve the correct denoised image. I have included both my input image and output image. Could anyone tell me what might be causing this ?
can you tell me how to run your codes to test single image, whats you env?
Have to add this line
# process data Nimg = Nimg / 255.0 # Normalisation Nimg = torch.from_numpy(np.transpose(Nimg, (2, 0, 1))).type(torch.FloatTensor)
Hope it works for you
everything is done thank you for your nice code