zshuai8 / FedGMM_ICML2023

Personalized Federated Learning under Mixture of Distributions
MIT License
15 stars 3 forks source link

RuntimeError: The size of tensor a (32) must match the size of tensor b (3) at non-singleton dimension 1 #1

Closed jxthyatt closed 10 months ago

jxthyatt commented 11 months ago

Run FedEM ==> Clients initialization.. ===> Building data iterators.. Traceback (most recent call last): File "run_experiment.py", line 244, in run_experiment(args) File "run_experiment.py", line 142, in run_experiment clients = initclients(args, File "run_experiment.py", line 31, in init_clients get_loaders( File "/mnt/traffic1/data/jxt/Personalized_Federated_Learning/FedGMM/utils/utils.py", line 375, in get_loaders inputs, targets = get_cifar10(dist_shift, dp) File "/mnt/traffic1/data/jxt/Personalized_Federated_Learning/FedGMM/datasets.py", line 1170, in get_cifar10 cifar10_data = d_norm(cifar10_data) File "/mnt/traffic/home/jxt/miniconda3/envs/FedGMM/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _callimpl result = self.forward(*input, **kwargs) File "/mnt/traffic/home/jxt/miniconda3/envs/FedGMM/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 221, in forward return F.normalize(tensor, self.mean, self.std, self.inplace) File "/mnt/traffic/home/jxt/miniconda3/envs/FedGMM/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 336, in normalize tensor.sub(mean).div_(std) RuntimeError: The size of tensor a (32) must match the size of tensor b (3) at non-singleton dimension 1

I train on cifar10 dataset and have this problem.

jxthyatt commented 11 months ago

I notice that do_norm() is new function in datasets.py, which is different from FedEM code.

zshuai8 commented 11 months ago

Hi, this is because we were evaluating our model on altering P(x) and P(y|x) (which is not included in the FedEM's code), it seems some part of the code is not updated correctly. Can I get back to you sometime next week? I am currently occupied.

jxthyatt commented 11 months ago

Looking forward to it! Also, I have a new question: how to get "data/cifar10/all_data/PCA.pkl"?

zshuai8 commented 10 months ago

Sorry for the late reply, I will upload them this week. Essentially these PCA files are extracted after perturbing P(X) and P(Y|X).

zshuai8 commented 10 months ago

Hi, it seems it is not necessary to have the normalization layer. You can probably just comment it out, if the problem persists, please let me know! It may be due to the dimension manipulation. For the PCA, you can actually get these PCA.pkl files by uncommenting 42-72 lines to create these projections.

zshuai8 commented 10 months ago

I will update the descriptions and code shortly after.