about psnr
Opened this issue · 4 comments
I tried introducing the sed discriminator into my realHatGan model, but the psnr index dropped by 1 db.
Hi,
Thanks for you interests in our works!
First of all, GAN training will reduce PSNR index somehow, while increasing perceptual index such as LPIPS.
Second of all, in real-world SR, ground-truth are commonly not available, how would you calculate the PSNR index?
Thank you for your answer. I am using the public remote sensing data set Google Aerial photo. I use sed instead of unet discriminator in my model to calculate psnr after training for 100epochs
Here is how I calculate psnr:
def resize_image(img, target_size):
return cv2.resize(img, target_size)
def calculate_psnr(img1, img2):
mse = np.mean((img1 - img2) ** 2)
if mse == 0:
return float('inf')
max_val = 255.0
psnr = 20 * np.log10(max_val / np.sqrt(mse))
return psnr, mse
Define the folder paths of the original image set and the reconstructed image set
original_folder_path = '/raid/chenhan/HAT-main/datasets/testA'
reconstructed_folder_path = '/raid/chenhan/HAT-main/results/HAT_GAN_Real_SRx4_archived_20240515_094341/visualization/custom'
total_psnr = 0
num_images = 0
max_psnr = float('-inf') # Initialize the maximum PSNR value to negative infinity
max_psnr_filename = '' # Initialize the image file name with the maximum PSNR value to an empty string
Traverse the image files in the original image folder
for filename in os.listdir(original_folder_path):
if filename.endswith('.jpg'):
img1 = cv2.imread(os.path.join(original_folder_path, filename))
#Build the reconstructed image file name
reconstructed_filename = f"{filename.split('.')[0]}_HAT_GAN_Real_SRx4.png"
img2 = cv2.imread(os.path.join(reconstructed_folder_path, reconstructed_filename))
if img1 is not None and img2 is not None:
#Resize images to the same size
img1 = resize_image(img1, (img2.shape[1], img2.shape[0]))
psnr, _ = calculate_psnr(img1, img2)
total_psnr += psnr
num_images += 1
# Update maximum PSNR value and image file name
if psnr > max_psnr:
max_psnr = psnr
max_psnr_filename = filename
print(f'Image file: {filename}')
print(f'PSNR value: {psnr}')
print('')
Calculate average PSNR value
average_psnr = total_psnr / num_images if num_images > 0 else 0
print(f'Average PSNR value: {average_psnr}')
print(f'Maximum PSNR value: {max_psnr}')
print(f'Image file with maximum PSNR value: {max_psnr_filename}')
Send feedback
Side panels
History
Saved
Hi,
This PSNR difference can be attributed to multiple reasons:
- Training iterations. 100 training epochs may not be enough for SeD training. The comparisons in our paper are under the same training iterations and settings.
- Training datasets. Are you using the public available HAT checkpoints? How would you train the model with SeD? On your own dataset or still on the DF2K dataset?
Thank you for your answer. I used hat checkpoints. I used my own dataset to train the model with SeD. I will try to train more epoches for evaluation.