def evaluate(self, ins: EvaluateIns) -> EvaluateRes: # Set the set so we are sure to generate the same batches # accross all clients. np.random.seed(123) print(f"Client {self.cid}: evaluate") config = ins[1] #batch_size = int(config["batch_size"]) weights = fl.common.parameters_to_weights(ins[0]) # Use provided weights to update the local model #self.model.set_weights(weights) set_weights(self.model, weights) # get IID test dataset testset = dataset_afterpartition( train=False, client_id=int(self.cid), num_partitions=self.nb_clients, xy_train_partitions=self.xy_train_partitions, xy_test_partitions=self.xy_test_partitions) # Evaluate the updated model on the local dataset testloader = torch.utils.data.DataLoader(testset, batch_size=32, shuffle=False) loss, accuracy = cifar.test(self.model, testloader, device=DEVICE) # Return the number of evaluation examples and the evaluation result (loss) return len(testset), float(loss), float(accuracy)
def evaluate( self, parameters: List[np.ndarray], config: Dict[str, str] ) -> Tuple[int, float, float]: # Set model parameters, evaluate model on local test dataset, return result self.set_parameters(parameters) loss, accuracy = cifar.test(self.model, self.testloader, device=DEVICE) return float(loss), len(self.testloader), {"accuracy": float(accuracy)}
def evaluate(weights: fl.common.Weights) -> Optional[Tuple[float, float]]: """Use the entire CIFAR-10 test set for evaluation.""" #model = cifar.load_model() #model.set_weights(weights) model = models.resnet18() set_weights(model, weights) model.to(DEVICE) model.eval() testloader = torch.utils.data.DataLoader(testset, batch_size=32, shuffle=False) return cifar.test(model, testloader, device=DEVICE)
def evaluate(self, ins: EvaluateIns) -> EvaluateRes: print(f"Client {self.cid}: evaluate") weights = fl.common.parameters_to_weights(ins[0]) # Use provided weights to update the local model #self.model.set_weights(weights) set_weights(self.model, weights) # Evaluate the updated model on the local dataset testloader = torch.utils.data.DataLoader(self.testset, batch_size=32, shuffle=False) loss, accuracy = cifar.test(self.model, testloader, device=DEVICE) # Return the number of evaluation examples and the evaluation result (loss) return len(self.testset), float(loss), float(accuracy)