XPixelGroup / BasicSR

Open Source Image and Video Restoration Toolbox for Super-resolution, Denoise, Deblurring, etc. Currently, it includes EDSR, RCAN, SRResNet, SRGAN, ESRGAN, EDVR, BasicVSR, SwinIR, ECBSR, etc. Also support StyleGAN2, DFDNet.
https://basicsr.readthedocs.io/en/latest/
Apache License 2.0
6.64k stars 1.17k forks source link

Test ESRGAN with niqe metric #382

Open MLDrago opened 3 years ago

MLDrago commented 3 years ago

Hello,

I'am trying to test my trained model and evaluate it on the niqe metric. In put this in my yaml file:

val:
  save_img: true
  suffix: ~  # add suffix to saved images, if None, use exp name

    niqe: # metric name, can be arbitrary
      type: calculate_niqe
      crop_border: 0
      input_order: 'HWC'
      convert_to: 'y'

Which gives me the following error:

2021-04-26 08:23:03,039 INFO: Testing Set5...
  0%|                                                                                                              | 0/5 [00:00<?, ?image/s]
Traceback (most recent call last):
  File "basicsr/test.py", line 58, in <module>
    main()
  File "basicsr/test.py", line 50, in main
    model.validation(
  File "e:\documents\tfe\gan\basicsr-master\basicsr\models\base_model.py", line 49, in validation
    self.nondist_validation(dataloader, current_iter, tb_logger,
  File "e:\documents\tfe\gan\basicsr-master\basicsr\models\sr_model.py", line 173, in nondist_validation
    self.metric_results[name] += getattr(
TypeError: calculate_niqe() got multiple values for argument 'crop_border'
  0%|                                                                                                              | 0/5 [00:04<?, ?image/s]

I also tried to pass: no parameters; only the crop_border but I have still this issue

Lotayou commented 3 years ago

niqe is not supported in METRIC_REGISTRY yet, since it's parameters are incompatible with other metrics (niqe is blind and doesn't need gt). The quickest fix is like this:

@METRIC_REGISTRY.register()
def calculate_niqe(img1, img2, crop_border, input_order='HWC', convert_to='y'):

img = img1.astype(np.float32)
vastech73 commented 1 year ago

I am trying to run the niqe.py script mapping to the results directory. I am getting this error : root@xsjatg1:/usr/local/lib/python3.8/dist-packages/basicsr/metrics# python niqe.py /workspace/Real-ESRGAN/APDrawingDB/mask/ALL/img_1585.png /workspace/Real-ESRGAN/results/img_1585_out.png niqe.py:5: DeprecationWarning: Please use convolve from the scipy.ndimage namespace, the scipy.ndimage.filters namespace is deprecated. from scipy.ndimage.filters import convolve Traceback (most recent call last): File "niqe.py", line 144, in def calculate_niqe(img, crop_border, input_order='HWC', convert_to='y', **kwargs): File "/usr/local/lib/python3.8/dist-packages/basicsr/utils/registry.py", line 56, in deco self._do_register(name, func_or_class, suffix) File "/usr/local/lib/python3.8/dist-packages/basicsr/utils/registry.py", line 42, in _do_register assert (name not in self._obj_map), (f"An object named '{name}' was already registered " AssertionError: An object named 'calculate_niqe' was already registered in 'metric' registry!

I did plugin the above code and post this i am seeing this issue.