TsingZ0 / PFLlib

37 traditional FL (tFL) or personalized FL (pFL) algorithms, 3 scenarios, and 20 datasets.
GNU General Public License v2.0
1.36k stars 285 forks source link

Dimensional error while using for image data #111

Closed Abhijit4-debug closed 1 year ago

Abhijit4-debug commented 1 year ago

Hi I wanted to use this framework for the image dataset for which I preprocessed the images in dimensional order [Channels,width,Height] which is [3,150,150] and I am using the following CNN for classification,

class FedAvgCNN(nn.Module): def init(self, in_features=3, num_classes=4, dim=67500): super().init() self.conv1 = nn.Sequential( nn.Conv2d(3, 32, kernel_size=3, padding=1), nn.ReLU(), nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1), nn.ReLU(), nn.MaxPool2d(2, 2), # output: 64 x 16 x 16 )

    self.conv2 = nn.Sequential(
        nn.Conv2d(64, 64, kernel_size=3, stride=1, padding=1),
        nn.ReLU(),
        nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
        nn.ReLU(),
        nn.MaxPool2d(2, 2), # output: 128 x 8 x 8
        )

    self.conv3 = nn.Sequential(
        nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1),
        nn.ReLU(),
        nn.Conv2d(256, 256, kernel_size=3, stride=1, padding=1),
        nn.ReLU(),
        nn.MaxPool2d(2, 2), # output: 256 x 4 x 4
        )

    self.fc1 = nn.Sequential(
        nn.Flatten(), 
        nn.Linear(360000, 1024),
        nn.ReLU(),
        nn.Linear(1024, 512),
        nn.ReLU(),

    )

    self.fc = nn.Linear(512, num_classes)

def forward(self, x):
    out = self.conv1(x)
    out = self.conv2(x)
    out=  self.conv3(x)
    out = self.fc1(out)
    out = self.fc(out)
    return out

When I used the above CNN in the local setup it ran without any errors but when i tried using in this framework I am getting the following dimensional error. image

I understand the meaning of the error but I am not sure why it is occurring as I preprocessed the images correctly according to the CNN

Abir-Tx commented 1 year ago

I am getting dimensional error too on Digit5 dataset

 mat1 and mat2 shapes cannot be multiplied (10x1600 and 10816x512)
Abhijit4-debug commented 1 year ago

This error usually occurs in the feed forward neural network layer at the end, probably if the input size in the flatten layer is wrong.

Abir-Tx commented 1 year ago

This error usually occurs in the feed forward neural network layer at the end, probably if the input size in the flatten layer is wrong.

Can you suggest a way to fix it ?

Abhijit4-debug commented 1 year ago

could you share your model architecture? and your image dimensional order?

TsingZ0 commented 1 year ago

Sorry for the delayed response. I have been quite busy recently

I used the above CNN in the local setup it ran without any error

Did you mean the Local method in this platform?

Which FL method did you use? Can you print the dimension of the feature map in the model where this error occurs?