Exemple #1
0
    def on_init(self, *args):
        print('EA on_init')
        FederatedClient.on_init(self, *args)
        model_config = args[0]
        self.p = model_config["p"]
        self.e = model_config["e"]

        def synchronize():
            global_w = self.request_weights()
            local_w = self.local_model.get_weights()
            diff = [self.e * (w-gw) for w,gw in zip(local_w, global_w)]
            self.local_model.set_weights([w-d for w,d in zip(local_w, diff)])
            self.send_diff(diff)

        def train():
            while True:
                if random.random() < self.p:
                    synchronize()
                self.local_model.train_one_round()

        threading.Thread(target = train).start()
Exemple #2
0
def start_client():
    print("start client")
    # c = FederatedClient("127.0.0.1", 5000, datasource.Mnist)
    FederatedClient("192.168.199.222", 5000, datasource.Mnist)
Exemple #3
0
                                                    replace=False)

                attack_mode = [0] * len(selected_writers)
                attack_number = int(args.attack_ratio * len(selected_writers))
                for attack_idx in range(attack_number):
                    attack_mode[attack_idx] = args.attack_mode
                print("Selected Writers", selected_writers,
                      len(selected_writers))
                print("Attack Modes", attack_mode)

                # feiminst数据集使用
                #                 for selected_idx in range(len(selected_writers)):
                #                     clients.append( FederatedClient("127.0.0.1", 5000, datasource.Mnist, gpu,
                #                             attack_mode[selected_idx], writer=writers[ selected_writers[selected_idx] ]) )
                for selected_idx in range(len(selected_writers)):
                    clients.append(FederatedClient(gpu,\
                                                   attack_mode[selected_idx], writer=writers[ selected_writers[selected_idx] ], number=selected_writers[selected_idx]) )
                init_info = {
                    # 'model_json': server.global_model.model.to_json(),
                    'model_json': server.global_model.model,
                    'model_id': server.model_id,
                    'min_train_size': 500,
                    'data_split': (0.6, 0.3, 0.1),  # train, test, valid
                    'epoch_per_round': args.local_epoch,
                    'batch_size': args.batch_size,
                    'request_sid': "rid",  #request.sid,
                }

                for client in clients:
                    client.on_init(init_info)
                ########
Exemple #4
0
 def __init__(self, server_host, server_port, datasource):
     # probability to synchronize. Note: here epoch_per_round ~ 1/p
     self.p = None
     self.e = None  # weight for elasiticity term
     FederatedClient.__init__(self, server_host, server_port, datasource)
def start_client():
    print("start client")
    c = FederatedClient("127.0.0.1", 5000, datasource.Mnist)
def start_client(cid, ip, port, thread):
    print("start client")
    c = FederatedClient(ip, int(port), thread, cid)
Exemple #7
0
def start_client0():
    print("start client0")
    c = FederatedClient("172.17.0.2", 1111, datasource5.Mnist)
def start_client():
    print("start client")
    c = FederatedClient(server_host, server_port, datasource.Mnist)
Exemple #9
0
def start_client(value_data_class_train_size):
    device_id = value_data_class_train_size['device_id'] - 1
    print("start client on {}".format(device_id))
    with tf.device('/gpu:{}'.format(device_id)):
        c = FederatedClient(value_data_class_train_size, "127.0.0.1", 5000,
                            datasource.Mnist)
Exemple #10
0
def start_client(fo_name, f_training_name):
    #c = FederatedClient("172.31.20.224", 5000, datasource_CIFAR10.Cifar10, fo_name, f_training_name)
    c = FederatedClient("172.31.20.224", 5000, datasource.Mnist, fo_name,
                        f_training_name)