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

size error #273

Open
badreddinemerabet opened this issue Jun 2, 2024 · 4 comments
Open

size error #273

badreddinemerabet opened this issue Jun 2, 2024 · 4 comments
Assignees

Comments

@badreddinemerabet
Copy link

when i tried to run the example from the youtube video "https://www.youtube.com/watch?v=-Grfxkg3-DI" I got this error when I try to run the training cell
Epoch 1:

RuntimeError Traceback (most recent call last)
in <cell line: 46>()
47 # train
48 print(f"Epoch {epoch}:")
---> 49 train(dataflow, model, device, optimizer)
50 print(optimizer.param_groups[0]['lr'])
51

13 frames
/content/torchquantum/torchquantum/functional/gate_wrapper.py in apply_unitary_bmm(state, mat, wires)
129 if len(mat.shape) > 2:
130 # both matrix and state are in batch mode
--> 131 new_state = mat.bmm(permuted)
132 else:
133 # matrix no batch, state in batch mode

RuntimeError: Expected size for first two dimensions of batch2 tensor to be: [10, 2] but got: [1, 2].

i didn't change anything

@01110011011101010110010001101111
Copy link
Collaborator

Try https://github.com/mit-han-lab/torchquantum/tree/main/examples/quanvolution (with #147 to increase accuracy); I’ll ask about updating the link!

@badreddinemerabet
Copy link
Author

thank you, it worked

@badreddinemerabet
Copy link
Author

Define transformations for the dataset

transform = transforms.Compose([
transforms.Grayscale(num_output_channels=1),
transforms.Resize((28, 28)),
transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))
])

Load your dataset

data_dir = 'OAM28' # Replace with the path to your dataset
full_dataset = datasets.ImageFolder(root=data_dir, transform=transform)

Split dataset into train and test

train_size = int(0.9 * len(full_dataset))
test_size = len(full_dataset) - train_size
train_dataset, test_dataset = random_split(full_dataset, [train_size, test_size])

Create data loaders

batch_size = 16
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=8, pin_memory=True)
test_loader = DataLoader(test_dataset, batch_size=batch_size, shuffle=False, num_workers=8, pin_memory=True)

dataflow = {'train': train_loader, 'test': test_loader}

@01110011011101010110010001101111
Copy link
Collaborator

Hello, do you have a follow up? Happy to help but am a bit unsure what you are asking!

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

2 participants