RuntimeError: shape '[10, 32, 32]' is invalid for input of size 30720

Am trying to do quanvolution with Cifar dataset how am geeting error,my models are below,any assistance am grateful

class HybridModel(nn.Module):
def init(self):
super().init()
self.conv0 = nn.Sequential(
QuanvolutionFilter(),
nn.Conv2d(3, 64, kernel_size=3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(inplace=False),
nn.MaxPool2d(2),
)
self.fc1 = nn.Linear(161664,10)

  #forward propagation function
def forward(self,x,use_cirq=False):
    x = self.conv0(x)
    x = self.QuanvolutionFilter(x,use_cirq)
    x = x.view(x.size(0),-1)
    x = self.fc1(x)
    return x

class HybridModel_without_qf(nn.Module):
def init(self):
super().init()
self.conv1 = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(inplace=False),
nn.MaxPool2d(2),
)
self.conv2 = nn.Sequential(
nn.Conv2d(64, 128, kernel_size=3, padding=1),
nn.BatchNorm2d(128),
nn.ReLU(inplace=False),
nn.MaxPool2d(2),
)
self.conv3 = nn.Sequential(
nn.Conv2d(128, 256, kernel_size=3, padding=1),
nn.BatchNorm2d(256),
nn.ReLU(inplace=False),
nn.MaxPool2d(2),
)

    self.fc = nn.Linear(4*4*256,10)

#forward propagation function
def forward1(self,x):
x = self.conv1(x)
x = self.conv2(x)
x = self.conv3(x)
x = x.view(x.size(0),-1)
x = self.fc(x)
return x

I don’t see where the failing view operation is used in your code, but here is a code snippet reproducing the error:

x = torch.randn(30720)

# fails
y = x.view(10, 32, 32) 
# RuntimeError: shape '[10, 32, 32]' is invalid for input of size 30720

# works
y = x.view(30, 32, 32)
y = x.view(-1, 32, 32)

You might be trying to create a view with a shape of [10, 32, 32] which is incompatible with the number of elements, which is 30720.