bonlime / pytorch-tools

Tool box for PyTorch
MIT License
186 stars 16 forks source link

Use psnr.py #61

Closed CBD88 closed 4 years ago

CBD88 commented 4 years ago

I want to use psnr.py in my project. I downloaded the file and put in my project folder. I import it using " from . import psnr ". Now how can i pass the two image and calculate PSNR and SSIM?

zakajd commented 4 years ago

Hi, see example below:


psnr = PSNR()
ssim = SSIM() # creates a class object
score = psnr(img1, img2)
score_ssim = ssim(img1, img2)
CBD88 commented 4 years ago

Hi, see example below:

psnr = PSNR()
ssim = SSIM() # creates a class object
score = psnr(img1, img2)
score_ssim = ssim(img1, img2)

It shows the error that NameError: name 'PSNR' is not defined I am calling it from another class forward function.

zakajd commented 4 years ago

This error has nothing to do with content of psnr.py file. It's states, that something is wrong with the way you import function. Try: from .psnr import PSNR, SSIM, but generally just make sure that your module is visible

CBD88 commented 4 years ago

This error has nothing to do with content of psnr.py file. It's states, that something is wrong with the way you import function. Try: from .psnr import PSNR, SSIM, but generally just make sure that your module is visible

It works. But for SSIM it gives the value None. PSNR works fine.

bonlime commented 4 years ago

@CBD88 I'm not using PSNR and SSIM and because of that they are not tested and may not work :c Here you can find well-tested implementations of both SSIM and PSNR: https://github.com/photosynthesis-team/photosynthesis.metrics