如何定义create_tf_dataset_from_all_all_clients()函数
我正在尝试从联合的数据集中制作集中式数据集。数据包含路径,client_id和标签,
因此首先,我使用接受客户端ID创建客户端data的函数
def extract_file_paths(dataset):
return [item["path"] for item in dataset]
@tf.function
def create_dataset(client_id):
new_datset = tf.data.Dataset.from_tensor_slices(dict(df_aml))
client_id = int(client_id)
client_id = tf.cast(client_id, dtype=tf.int64)
files = new_datset.filter(lambda x: x['client_id'] == client_id)
list_ds = tf.data.Dataset.list_files(tf.py_function(func=extract_file_paths,inp=[files], Tout = tf.string ))
images_ds = list_ds.map(parse_image)
return images_ds
创建客户端对象:
client_ids = ['0', '1', '2']
client_data = tff.simulation.datasets.ClientData.from_clients_and_tf_fn(client_ids,
create_dataset)
centralized = client_data.create_tf_dataset_from_all_clients()
我期望一个具有不同标签和文件的数据集,但是此代码正在生成一个只有一个文件的数据集。是因为我试图实现图形执行方法吗?
我尝试使用类似的函数来创建适用于联合设置并生成预期数据集的客户端数据集,但是当我尝试产生集中式数据集时,使用相同的功能会给我一个错误
I am trying to make a centralized dataset from a federated one. Data contains path, client_id and label
So first I create a clientdata object using a function that accepts the client's id
def extract_file_paths(dataset):
return [item["path"] for item in dataset]
@tf.function
def create_dataset(client_id):
new_datset = tf.data.Dataset.from_tensor_slices(dict(df_aml))
client_id = int(client_id)
client_id = tf.cast(client_id, dtype=tf.int64)
files = new_datset.filter(lambda x: x['client_id'] == client_id)
list_ds = tf.data.Dataset.list_files(tf.py_function(func=extract_file_paths,inp=[files], Tout = tf.string ))
images_ds = list_ds.map(parse_image)
return images_ds
creating clientdata:
client_ids = ['0', '1', '2']
client_data = tff.simulation.datasets.ClientData.from_clients_and_tf_fn(client_ids,
create_dataset)
centralized = client_data.create_tf_dataset_from_all_clients()
I expected a dataset with different labels and files but this code is producing a dataset with only one file in it. Is it because I am trying to implement the graph execution method?
I tried using a similar function for creating a clientdata object that works for federated settings and produces the expected dataset, but using the same function gives me an error when I try to produce a centralized dataset
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论