SaashaJoshi / piQture

piQture: A quantum machine learning library for image processing.
https://saashajoshi.github.io/piQture/
Apache License 2.0
44 stars 20 forks source link

ValueError: Image dimensions must be powers of 2 #150

Open Shivansh20128 opened 3 days ago

Shivansh20128 commented 3 days ago

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 commented 3 days ago

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 commented 3 days ago

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