pythontensorflowtensorflow2.0tensorflow-federated

How to explain "tff.to_type((tf.int64, [2]))"?


I am learning Tensorflow-Federated, while I don't know how to explain the syntax tff.to_type((tf.int64, [2])). I consider tff.to_type can create a tff data type, but I don't know the meaning of [2].


Solution

  • So, tff.to_type creates a tff type with the dtype tf.int64 and the shape [2]. It is like defining a tf.TensorSpec that describes the properties of a tensor. It has a shape argument as well as a dtype argument. For better understanding, run:

    import tensorflow as tf
    tf.TensorSpec(dtype=tf.int64, shape=[2])
    
    TensorSpec(shape=(2,), dtype=tf.int64, name=None)
    

    This tensor will, therefore, have two values with the data type tf.int64.