h4nwei / SPAQ

[CVPR2020] Official SPAQ & Implementation
165 stars 35 forks source link

AttributeError: numpy #19

Open hetarth18 opened 2 years ago

hetarth18 commented 2 years ago

I am trying to test some images using the SPAQ BL_demo.py script, and I am supposedly getting this following error -

    main()
  File "BL_demo.py", line 100, in main
    t.predit_quality()
  File "BL_demo.py", line 64, in predit_quality
    image_1 = self.prepare_image(Image.open(self.config.image_1).convert("RGB"))
  File "/Users/image-quality-enhancement/SPAQ/SPAQ/Prepare_image.py", line 15, in __call__
    return self.generate_patches(image, input_size=self.stride)
  File "/Users/image-quality-enhancement/SPAQ/SPAQ/Prepare_image.py", line 36, in generate_patches
    img = self.to_numpy(image)
  File "/Users/image-quality-enhancement/SPAQ/SPAQ/Prepare_image.py", line 32, in to_numpy
    p = image.numpy()
  File "/Users/choprahetarth/opt/anaconda3/envs/price/lib/python3.7/site-packages/PIL/Image.py", line 546, in __getattr__
    raise AttributeError(name)
AttributeError: numpy

Can you please tell me which sorts of images are accepted as input as I am passing .jpeg images (some work, while others don't).

System specs - Python 3.8 MacOS Catalina i3 (yes i have removed the .cuda() wherever it is required in the script so that it works on cpu)

youyuge34 commented 2 years ago

This is a bug which I also encounter. Fix it by editting the code in Prepare_image.py as below:

    def adaptive_resize(self, img):
        """
        Args:
            img (PIL Image): Image to be scaled.

        Returns:
            PIL Image: Rescaled image.
        """
        h, w = img.size
        if h < self.size or w < self.size:
            img = transforms.ToTensor()(img)
            print('if img.size=', img.size(), type(img))
            return img
        else:
            img = transforms.ToTensor()(transforms.Resize(self.size, self.interpolation)(img))
            print('else img.size=', img.size(), type(img))
            return img
jianyesysu commented 2 years ago

This is a bug which I also encounter. Fix it by editting the code in Prepare_image.py as below:

    def adaptive_resize(self, img):
        """
        Args:
            img (PIL Image): Image to be scaled.

        Returns:
            PIL Image: Rescaled image.
        """
        h, w = img.size
        if h < self.size or w < self.size:
            img = transforms.ToTensor()(img)
            print('if img.size=', img.size(), type(img))
            return img
        else:
            img = transforms.ToTensor()(transforms.Resize(self.size, self.interpolation)(img))
            print('else img.size=', img.size(), type(img))
            return img

Could share the BL_release.pt file with me?Thx. My e-mail: 229020168@qq.com