Real-ESRGAN icon indicating copy to clipboard operation
Real-ESRGAN copied to clipboard

ValueError: ('Scale mismatches. GT (3078, 5472) is not 4x ', 'multiplication of LQ (1080, 1624).')

Open koihoo opened this issue 1 year ago • 3 comments

Thanks for the great projects!

i have a problem with training finetune paired data using finetune_realesrgan_x4plus_pairdata.yml. and i don't know how to solve this problem. image

koihoo avatar May 29 '23 05:05 koihoo

Note that in the config file ( finetune_realesrgan_x4plus_pairdata.yml) that is present under the options folder, the scale is set as 4 by default. In your case, the dimensions of GT are not 4 times the dimensions of LQ. Dimensions of GT should be (1080 x 4 = 4320, 1624 x 4 = 6496) i.e. (4320,6496). Try using the below code to modify the dimensions of GT: -

import os from PIL import Image

GT_folder = 'Path/to/GT' output_folder = 'Path/to/GT_resized' target_width = 4320 target_height = 6496

Create the output folder if it doesn't exist

os.makedirs(output_folder, exist_ok=True)

Iterate over the images in the LR folder

for filename in os.listdir(lr_folder): # Open the image image_path = os.path.join(lr_folder, filename) image = Image.open(image_path)

    # Resize the image
    resized_image = image.resize((target_width, target_height), Image.BICUBIC)
    
    # Save the resized image to the output folder
    output_path = os.path.join(output_folder, filename)
    resized_image.save(output_path)

    print(f"Resized image saved: {output_path}")

Hope this helps!

atishay2411 avatar Jun 06 '23 09:06 atishay2411

Note that in the config file ( finetune_realesrgan_x4plus_pairdata.yml) that is present under the options folder, the scale is set as 4 by default. In your case, the dimensions of GT are not 4 times the dimensions of LQ. Dimensions of GT should be (1080 x 4 = 4320, 1624 x 4 = 6496) i.e. (4320,6496). Try using the below code to modify the dimensions of GT: -

import os from PIL import Image

GT_folder = 'Path/to/GT' output_folder = 'Path/to/GT_resized' target_width = 4320 target_height = 6496

Create the output folder if it doesn't exist

os.makedirs(output_folder, exist_ok=True)

Iterate over the images in the LR folder

for filename in os.listdir(lr_folder): # Open the image image_path = os.path.join(lr_folder, filename) image = Image.open(image_path)

    # Resize the image
    resized_image = image.resize((target_width, target_height), Image.BICUBIC)
    
    # Save the resized image to the output folder
    output_path = os.path.join(output_folder, filename)
    resized_image.save(output_path)

    print(f"Resized image saved: {output_path}")

Hope this helps!

thanks! I already solved this problem.

koihoo avatar Jun 09 '23 02:06 koihoo

Note that in the config file ( finetune_realesrgan_x4plus_pairdata.yml) that is present under the options folder, the scale is set as 4 by default. In your case, the dimensions of GT are not 4 times the dimensions of LQ. Dimensions of GT should be (1080 x 4 = 4320, 1624 x 4 = 6496) i.e. (4320,6496). Try using the below code to modify the dimensions of GT: - import os from PIL import Image GT_folder = 'Path/to/GT' output_folder = 'Path/to/GT_resized' target_width = 4320 target_height = 6496

Create the output folder if it doesn't exist

os.makedirs(output_folder, exist_ok=True)

Iterate over the images in the LR folder

for filename in os.listdir(lr_folder): # Open the image image_path = os.path.join(lr_folder, filename) image = Image.open(image_path)

    # Resize the image
    resized_image = image.resize((target_width, target_height), Image.BICUBIC)
    
    # Save the resized image to the output folder
    output_path = os.path.join(output_folder, filename)
    resized_image.save(output_path)

    print(f"Resized image saved: {output_path}")

Hope this helps!

thanks! I already solved this problem.

can i ask how?

kl402401 avatar Mar 13 '24 07:03 kl402401