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

ValueError: Image dimensions must be powers of 2 #150

Closed
Shivansh20128 opened this issue Nov 30, 2024 · 5 comments · Fixed by #151
Closed

ValueError: Image dimensions must be powers of 2 #150

Shivansh20128 opened this issue Nov 30, 2024 · 5 comments · Fixed by #151

Comments

@Shivansh20128
Copy link
Contributor

Hi @SaashaJoshi, there seems to be a problem with the first example given in the repository readme file. The following code gave a value error - "ValueError: Image dimensions must be powers of 2." Please look into this.

# INEQR Encoding Method
import torch.utils.data
from piqture.data_loader.mnist_data_loader import load_mnist_dataset
from piqture.embeddings.image_embeddings.ineqr import INEQR

# Load MNIST dataset
train_dataset, test_dataset = load_mnist_dataset()

# Retrieve a single image from the dataset
image, label = train_dataset[0]
image_size = tuple(image.squeeze().size())

# Change pixel values from float to integer
pixel_vals = (image * 255).round().to(torch.uint8)
pixel_vals = pixel_vals.tolist()

embedding = INEQR(image_size, pixel_vals).ineqr()

# Display circuit.
embedding.draw()
ValueError                                Traceback (most recent call last)
Cell In[1], line 17
     14 pixel_vals = (image * 255).round().to(torch.uint8)
     15 pixel_vals = pixel_vals.tolist()
---> 17 embedding = INEQR(image_size, pixel_vals).ineqr()
     19 # Display circuit.
     20 embedding.draw()

File /Users/Shared/Drive/Qiskit/piQture/piqture/embeddings/image_embeddings/ineqr.py:43, in INEQR.__init__(self, img_dims, pixel_vals, max_color_intensity)
     37 def __init__(
     38     self,
     39     img_dims: tuple[int, int],
     40     pixel_vals: list[list[list]],
     41     max_color_intensity: int = 255,
     42 ):
---> 43     NEQR.__init__(self, img_dims, pixel_vals, max_color_intensity)
     45     # Determine number of qubits for position embedding
     46     self.x_coord = int(math.log(img_dims[0], 2))

File /Users/Shared/Drive/Qiskit/piQture/piqture/embeddings/image_embeddings/neqr.py:33, in NEQR.__init__(self, img_dims, pixel_vals, max_color_intensity)
     27 def __init__(
     28     self,
     29     img_dims: tuple[int, int],
     30     pixel_vals: list[list],
     31     max_color_intensity: int = 255,
     32 ):
---> 33     ImageEmbedding.__init__(self, img_dims, pixel_vals)
     35     if max_color_intensity < 0 or max_color_intensity > 255:
     36         raise ValueError(
     37             \"Maximum color intensity cannot be less than 0 or greater than 255.\"
     38         )

File /Users/Shared/Drive/Qiskit/piQture/piqture/embeddings/image_embedding.py:44, in ImageEmbedding.__init__(self, img_dims, pixel_vals, color_channels)
     38 if (
     39     not all((isinstance(dims, int) for dims in img_dims))
     40     or all((isinstance(dims, bool) for dims in img_dims))
     41     or not isinstance(img_dims, tuple)
     42 ):
     43     raise TypeError(\"Input img_dims must be of the type tuple[int, ...].\")
---> 44 self.validate_image_dimensions(img_dims)
     45 self.img_dims = img_dims
     47 self.color_channels = color_channels

File /Users/Shared/Drive/Qiskit/piQture/piqture/embeddings/image_embeddings/ineqr.py:72, in INEQR.validate_image_dimensions(self, img_dims)
     70 for dim in img_dims:
     71     if math.ceil(math.log(dim, 2)) != math.floor(math.log(dim, 2)):
---> 72         raise ValueError(\"Image dimensions must be powers of 2.\")

ValueError: Image dimensions must be powers of 2."
}
@Shivansh20128
Copy link
Contributor Author

Maybe we can change the image size while loading the dataset.

# Load MNIST dataset
train_dataset, test_dataset = load_mnist_dataset(img_size=(8, 8))

@Shivansh20128
Copy link
Contributor Author

I also noticed that the project is not documented that well, as It only contains the installation steps and some details about the dataset loader. Do you have any document where I could read what the project is about, what it can do, and what the goals of the project are? If not, do you want to work together on making a roadmap for this project? Because I think this could be so much bigger...Do you have a community channel where we could discuss this?
Thanks

@SaashaJoshi
Copy link
Owner

SaashaJoshi commented Dec 11, 2024

Hi @Shivansh20128,
Thanks for pointing out the lack of documentation. It would be great to sit and plan out something to correct this. Let me know if you will be interested in helping in creating this documentation plan! Also, you may want to refer the issue #116

@Shivansh20128
Copy link
Contributor Author

Great @SaashaJoshi ! Let's get to it then. Let me know a communication channel we could use for this. Meanwhile, I will make a PR for the above issue.
I have seen the issue #116, but the problem is there is a lack of information about the project in the documentation. We'll need to add some of the documentation ourselves before asking the open-source community to do it.

@SaashaJoshi
Copy link
Owner

Let me see how to setup a discord channel for piQture. I will get back to you.

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

Successfully merging a pull request may close this issue.

2 participants