tensorflow-federated - 有没有办法类型转换联合值(value)?

标签 tensorflow-federated

如果我有一个联合值,比如说我想转换为 {float32}@CLIENTS{int32}@CLIENTS ,有没有一种简单的方法可以做到这?谢谢!

最佳答案

张量操作通常需要发生在用tff.tf_computation修饰的函数内部。 。由于提到的类型有位置 (@CLIENTS),这可能位于 tff.federated_computation 内。修饰函数,因此需要使用 tff.federated_map 调用转换方法.

类似这样的事情:

@tff.tf_computation
def cast_to_float(x):
  return tf.cast(x, tf.float32)

@tff.federated_computation(tff.FederatedType(int32, tff.CLIENTS))
def my_func(a):
  a_float = tff.federated_map(cast_to_float, a)
  return a_float

print(my_func.type_signature)

>>> ({int32}@CLIENTS -> {float32}@CLIENTS)

关于tensorflow-federated - 有没有办法类型转换联合值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62598087/

相关文章:

tensorflow-federated - TFF 中高斯自适应裁剪中的 intial_clip_norm 意味着什么?

tensorflow-federated - 调用函数tff.learning.build_federated_averaging_process时的学习率设置

tensorflow-federated - TFF : Difference between split clients into train and test or split each client dataset into train and test

tensorflow - 多 GPU TFF 模拟错误 "Detected dataset reduce op in multi-GPU TFF simulation"

tensorflow-federated - TFF 是否序列化另一个库的函数?

python - 执行堆栈中数据集类型的更改

tensorflow2.0 - 使用 tf.data 与联合核心 API 和远程执行客户端上的数据进行线性回归

python - TensorFlow 联合 : How can I write an Input Spec for a model with more than one input

tensorflow - 如何从 CSV 文件创建联合数据集?

python-3.x - 在 TensorFlow Federated 中创建自定义联合数据集