A few modifications cause `standalone.py` to fail.
liyipeng00 opened this issue · 7 comments
Thanks for this clear and usefull open code for Federated Learning.
I make a few modifications to the file standalone.py
(FedLab/examples/standalone-mnist/standalone.py).
I found that this modification cause the command python standalone.py --total_client 100 --com_round 3 --sample_ratio 0.1 --batch_size 100 --epochs 5 --lr 0.02
to fail, which runs well when using the original code. Could you provide more details about how to use the other partitions?
In addtion, more simple examples (that can be validated easily) would be better for the popularity of this code.
Thanks for your time to check this issue.
This failure is caused by the false alignment of data preprocess and model input.
The codes below show my usage of "PartitionedMNIST". You may add an additional transform transform=transforms.Compose( [transforms.ToPILImage(), transforms.ToTensor()]))
to your code.
dataset = PartitionedMNIST(root="./datasets/mnist/",
path="./datasets/mnist/fedmnist_{}/".format(args.dir),
num_clients=args.num_clients,
partition="noniid-labeldir",
dir_alpha=args.dir,
seed=args.dseed,
preprocess=args.preprocess,
download=True,
verbose=True,
transform=transforms.Compose(
[transforms.ToPILImage(), transforms.ToTensor()]))
For the definition of other parameters, please see our tutorial.
Thanks for your advice, yet I still failed with the same runtime error. I used four setttings below. (1) I deleted the generated .pkl
file at the begining of each run; (2) I did not make any modification to the original code except what I showed below.
[Basic setting]
dataset = PartitionedMNIST(root="../../datasets/mnist/",
path="../../datasets/mnist/",
num_clients=args.total_client,
partition="iid",
dir_alpha=1.0,
seed=0,
preprocess=True,
download=True,
verbose=True,
transform=transforms.Compose(
[transforms.ToPILImage(), transforms.ToTensor()]))
[Four cases]
1. transform=transforms.Compose(
[transforms.ToPILImage(), transforms.ToTensor()])
2. transform=transforms.Compose(
[transforms.ToTensor()])
3. transform=transforms.Compose(
[transforms.ToTensor()]),
target_transform=transforms.Compose(
[transforms.ToTensor()])
4. transform=transforms.Compose(
[transforms.ToPILImage(), transforms.ToTensor()]),
target_transform=transforms.Compose(
[transforms.ToPILImage(), transforms.ToTensor()])
you dont need to use target_transform actually
The demo in branch release-1.3.0 works. Please check this version.
Thanks for this clear and usefull open code for Federated Learning.
I make a few modifications to the file
standalone.py
(FedLab/examples/standalone-mnist/standalone.py).I found that this modification cause the command
python standalone.py --total_client 100 --com_round 3 --sample_ratio 0.1 --batch_size 100 --epochs 5 --lr 0.02
to fail, which runs well when using the original code. Could you provide more details about how to use the other partitions?In addtion, more simple examples (that can be validated easily) would be better for the popularity of this code.
Thanks for your time to check this issue.
For more usage of partition, please check this, the function parameters are almost the same, and you can also see the visualization result of these partition methods.
We are still adding more features to the dataset interface, which may lead to some inconsistency in the code. The tutorials shown above are for the previous version but can still be helpful if you want to use in release-1.3.0
Also please check PartitionedMNIST; we directly use MNISTPartitioner here. You can replace this for other datasets. Also check this. All partitioners are provided here.