shaoxiongji / federated-learning

A PyTorch Implementation of Federated Learning http://doi.org/10.5281/zenodo.4321561
http://doi.org/10.5281/zenodo.4321561
MIT License
1.29k stars 372 forks source link

Getting Runtime Error #1

Closed santanu-2018 closed 5 years ago

santanu-2018 commented 6 years ago

HI, When I try to run the code with the following command: python main_fed.py --dataset mnist --model cnn --epochs 50 --gpu -1 (since I have no gpu) I get the following error message:

CNNMnist( (conv1): Conv2d(3, 10, kernel_size=(5, 5), stride=(1, 1)) (conv2): Conv2d(10, 20, kernel_size=(5, 5), stride=(1, 1)) (conv2_drop): Dropout2d(p=0.5) (fc1): Linear(in_features=320, out_features=50, bias=True) (fc2): Linear(in_features=50, out_features=10, bias=True) ) 0%| | 0/50 [00:00<?, ?it/s] Traceback (most recent call last): File "main_fed.py", line 122, in w, loss = local.update_weights(net=copy.deepcopy(net_glob)) File "/federated-learning-master/FedAvg/Update.py", line 55, in update_weights log_probs = net(images) File "/miniconda/envs/fedlearn/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(*input, *kwargs) File "/federated-learning-master/FedAvg/FedNets.py", line 38, in forward x = F.relu(F.max_pool2d(self.conv1(x), 2)) File "/home/santanu/miniconda/envs/fedlearn/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in call result = self.forward(input, **kwargs) File "/miniconda/envs/fedlearn/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 282, in forward self.padding, self.dilation, self.groups) File "/miniconda/envs/fedlearn/lib/python3.6/site-packages/torch/nn/functional.py", line 90, in conv2d return f(input, weight, bias) RuntimeError: Given groups=1, weight[10, 3, 5, 5], so expected input[10, 1, 28, 28] to have 3 channels, but got 1 channels instead

Any suggestion how to fix it?

shaoxiongji commented 6 years ago

try python main_fed.py --dataset mnist --model cnn --epochs 50 --gpu -1 --num_channels 1 since images of MINST only have one channel