Code Monkey home page Code Monkey logo

fedavg's Introduction

FedAvg

The implementation of federated average learning[1] based on TensorFlow and PyTorch respectively.

Some codes refers to https://github.com/Zing22/tf-fed-demo, https://tensorflow.googlesource.com/tensorflow/+/master/tensorflow/g3doc/tutorials/mnist/input_data.py and https://github.com/persistforever/cifar10-tensorflow/blob/master/src/dataloader/cifar10.py

environment

Tensorflow-version

1.python3.7.6

2.tensorflow1.13.1

PyTorch-version

1.python3.7.6

2.pytorch1.4.0

both of them run on GPU

prepare data sets

You are supposed to prepare the data set by yourself. MNIST can be downloaded on http://yann.lecun.com/exdb/mnist/, and CIFAR-10 can be downloaded on http://www.cs.toronto.edu/~kriz/cifar.html. These data sets should be put into /data/MNIST and /data/CIFAR-10 when the download is finished.

usage

Run the code

python server.py -nc 100 -cf 0.1 -E 5 -B 10 -mn mnist_cnn  -ncomm 1000 -iid 0 -lr 0.01 -vf 20 -g 0

which means there are 100 clients, we randomly select 10 in each communicating round. The data set are allocated in Non-IID way. The epoch and batch size are set to 5 and 10. The learning rate is 0.01, we validate the codes every 20 rounds during the training, training stops after 1000 rounds. There are three models to do experiments: mnist_2nn mnist_cnn and cifar_cnn, and we choose mnist_cnn in this command. Notice the data set path when run the code of pytorch-version(you can take the source code out of the 'use_pytorch' folder).

[1] Mcmahan H B , Moore E , Ramage D , et al. Communication-Efficient Learning of Deep Networks from Decentralized Data[J]. 2016.

fedavg's People

Contributors

whdy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fedavg's Issues

getData的疑问

为什么getData那里那么复杂?没太看懂,为什么不直接按普通的读数据方式呢?有什么特别的地方吗,求教!
dataset_train = datasets.MNIST('../data/mnist/', train=True, download=True,
transform=transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
]))

TypeError: 'NoneType' object is not subscriptable

Hi,

I created a virtual environment as your suggestion. But I got the following error:

Extracting ./data/MNIST\train-images-idx3-ubyte.gz
Extracting ./data/MNIST\train-labels-idx1-ubyte.gz
Extracting ./data/MNIST\t10k-images-idx3-ubyte.gz
Extracting ./data/MNIST\t10k-labels-idx1-ubyte.gz
communicate round 0
  0%|          | 0/10 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "E:/OneDrive - University of Otago/research/FedAvg/server.py", line 87, in <module>
    local_vars = myClients.ClientUpdate(client, global_vars)
  File "E:\OneDrive - University of Otago\research\FedAvg\clients.py", line 112, in ClientUpdate
    train_data, train_label = self.clientsSet[client].next_batch(self.B)
  File "E:\OneDrive - University of Otago\research\FedAvg\clients.py", line 38, in next_batch
    return self.train_dataset[start:end], self.train_label[start:end]
TypeError: 'NoneType' object is not subscriptable

Do you know the reason? Thank you very much for your great help.

关于pytorch版 cifar 数据集处理

想请问一下,pytorch版本中,getData.py 只写了获取mnist数据集而没有cifar数据集,请问获取cifar具体过程是不是和TensorFlow版一致,还是得进行修改呢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.