Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save deblur image in eval phase #11

Closed
YellowOrz opened this issue Nov 4, 2021 · 1 comment
Closed

save deblur image in eval phase #11

YellowOrz opened this issue Nov 4, 2021 · 1 comment

Comments

@YellowOrz
Copy link

In line 53 of eval.py(show as below), the output tensor is turned to PIL image after adding 0.5/255, then is saved. Why is this? This tensor has already been clipped to 0-1. I can't find the same processing way in the official document of torchvision

if args.save_image:
    save_name = os.path.join(args.result_dir, name[0])
    pred_clip += 0.5 / 255
    pred = F.to_pil_image(pred_clip.squeeze(0).cpu(), 'RGB')
    pred.save(save_name)
@chosj95
Copy link
Owner

chosj95 commented Nov 9, 2021

Hi,
I intended to round off the float numbers before multiplying by 255.

In the F.to_pil_image() , the clipped image is multiplied by 255 and applied floor operation as follows:

if isinstance(pic, torch.Tensor):
    if pic.is_floating_point() and mode != 'F':
        pic = pic.mul(255).byte()
    npimg = np.transpose(pic.cpu().numpy(), (1, 2, 0))

I think it needs an additional clip function to make it exactly as we intended because the range of the input of byte() function is 0-255 (8bit).

The correct saving code should be as follows:

if args.save_image:
    save_name = os.path.join(args.result_dir, name[0])
    pred_clip += 0.5 / 255
    pred_clip = torch.clamp(pred_clip, 0, 1)
    pred = F.to_pil_image(pred_clip.squeeze(0).cpu(), 'RGB')
    pred.save(save_name)

This code will be reflected soon, and I hope I have answered all of your questions.

@chosj95 chosj95 closed this as completed Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants