当我运行文件时,我收到一个**NumPyClient.fit没有返回包含3个元素的元组 client.py 错误。可能是什么问题?



我正在使用Flower代码示例尝试联合学习的POC,但当我运行client.py文件时,我一直收到以下错误:

INFO flower 2022-07-04 15:27:37,301 | connection.py:102 | Opened insecure gRPC connection (no certificates were passed)
DEBUG flower 2022-07-04 15:27:37,323 | connection.py:39 | ChannelConnectivity.IDLE
DEBUG flower 2022-07-04 15:27:37,389 | connection.py:39 | ChannelConnectivity.CONNECTING
DEBUG flower 2022-07-04 15:27:37,708 | connection.py:39 | ChannelConnectivity.READY
Training finished for round 5
DEBUG flower 2022-07-04 15:27:41,178 | connection.py:121 | gRPC channel closed
Traceback (most recent call last):
File "C:UsersHPDevelopmentFederated-Learning-sklearnsklearnffclient.py", line 52, in
fl.client.start_numpy_client(
File "C:UsersHP.virtualenvssklearnff-UZKgGLZylibsite-packagesflwrclientapp.py", line 173, in start_numpy_client
start_client(
File "C:UsersHP.virtualenvssklearnff-UZKgGLZylibsite-packagesflwrclientapp.py", line 94, in start_client
client_message, sleep_duration, keep_going = handle(
File "C:UsersHP.virtualenvssklearnff-UZKgGLZylibsite-packagesflwrclientgrpc_clientmessage_handler.py", line 61, in handle
return _fit(client, server_msg.fit_ins), 0, True
File "C:UsersHP.virtualenvssklearnff-UZKgGLZylibsite-packagesflwrclientgrpc_clientmessage_handler.py", line 117, in _fit
fit_res = client.fit(fit_ins)
File "C:UsersHP.virtualenvssklearnff-UZKgGLZylibsite-packagesflwrclientnumpy_client.py", line 203, in fit
raise Exception(EXCEPTION_MESSAGE_WRONG_RETURN_TYPE_FIT)
Exception:
NumPyClient.fit did not return a tuple with 3 elements.
The returned values should have the following type signature:
Tuple[List[np.ndarray], int, Dict[str, Scalar]]
Example
model.get_weights(), 10, {"accuracy": 0.95}

我通过将get_model_parameters的返回类型从元组更改为列表来解决这个问题。

def get_model_parameters(model: LogisticRegression) -> LogRegParams:
    """Returns the paramters of a sklearn LogisticRegression model."""
    if model.fit_intercept:
        params = [model.coef_, model.intercept_]
    else:
        params = [model.coef_, ]
    return params

最新更新