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

Shape of output through self.hybrid is not correct? #4

Open
huytranvan2010 opened this issue Jun 17, 2022 · 1 comment
Open

Shape of output through self.hybrid is not correct? #4

huytranvan2010 opened this issue Jun 17, 2022 · 1 comment

Comments

@huytranvan2010
Copy link

`
class Net(nn.Module):
def init(self):
super(Net, self).init()
self.conv1 = nn.Conv2d(1, 6, kernel_size=5)
self.conv2 = nn.Conv2d(6, 16, kernel_size=5)
self.dropout = nn.Dropout2d()
self.fc1 = nn.Linear(256, 64)
self.fc2 = nn.Linear(64, 10)
# self.hybrid = Hybrid(qiskit.Aer.get_backend('qasm_simulator'), 100, np.pi / 2)
self.hybrid = [Hybrid(qiskit.Aer.get_backend('qasm_simulator'), 100, np.pi / 2) for i in range(10)]

def forward(self, x):
    x = F.relu(self.conv1(x))
    x = F.max_pool2d(x, 2)
    x = F.relu(self.conv2(x))
    x = F.max_pool2d(x, 2)
    x = self.dropout(x)
    # x = x.view(-1, 256)
    x = torch.flatten(x, start_dim=1)
    x = F.relu(self.fc1(x))
    x = self.fc2(x)
    x = torch.chunk(x, 10, dim=1)
    # x = self.hybrid(x)
    x = tuple([hy(x_) for hy, x_ in zip(self.hybrid, x)])
    return torch.cat(x, -1)

`
I tried to run this code with batch (32, 1, 28, 28) and obtained output shape was (1, 10), not (32, 10). It wasn't correct. I guess that self.hybrid always ouput with shape (1, 1) regarless the batch size. I mean that with input (32, 1) through self.hybrid I receive an output with shape (32, 1). Thank you.

@ccu1tn
Copy link

ccu1tn commented Jan 25, 2024

Hi @huytranvan2010 ,
Did you fix this problems?

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