blackfeather-wang / ISDA-for-Deep-Networks

An efficient implicit semantic augmentation method, complementary to existing non-semantic techniques.
582 stars 93 forks source link

RuntimeError: size mismatch #2

Closed etetteh closed 4 years ago

etetteh commented 4 years ago

Thank you for this repo. I am trying to implement ISDA with my own model on the CIFAR-10 dataset, but for some reason I am getting issues. My model is defined below :

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3, 64, 5)
        self.pool = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(64, 256, 5)
        self.dp1 = nn.Dropout2d(p=.25) 
        self.fc1 = nn.Linear(256 * 5 * 5, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)
    def forward(self, x):
        residual = x
        x = self.pool(mish(self.conv1(x)))
        x = self.pool(mish(self.conv2(x)))
        x = x.view(-1, 256 * 5 * 5)
        x = self.dp1(x)
        if residual.shape == x.shape:
            x += residual
        x = mish(self.fc1(x))
        x = mish(self.fc2(x))
        x = self.fc3(x)

        return x

net = Net()

batch_size = 4 feature_num = 84 num_classes = len(classes) #10 fc = Full_layer(feature_num, num_classes)

I have done every in the train function right but for some reason I am getting RuntimeError: size mismatch, m1: [4 x 10], m2: [84 x 10] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:197

blackfeather-wang commented 4 years ago

Thank you for your question.

I think that is because the fc-layer has been explicitly defined beyond Net(). Therefore, self.fc3 should be removed from both the definition of Net() and Net.forward(). Feel free to contact me if it does not work~

Sincerely, Yulin Wang.

etetteh commented 4 years ago

Thank you for the response. It worked after following your suggestion.