Skip to content

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

@huytranvan2010

Description

@huytranvan2010

`
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions