Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: numpy #19

Open
hetarth18 opened this issue Jan 6, 2022 · 2 comments
Open

AttributeError: numpy #19

hetarth18 opened this issue Jan 6, 2022 · 2 comments

Comments

@hetarth18
Copy link

hetarth18 commented Jan 6, 2022

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants