tff.to_type

Converts the argument into an instance of tff.Type.

Used in the notebooks

Used in the tutorials

Examples of arguments convertible to tensor types:

tf.int32
(tf.int32, [10])
(tf.int32, [None])

Examples of arguments convertible to flat named tuple types:

[tf.int32, tf.bool]
(tf.int32, tf.bool)
[('a', tf.int32), ('b', tf.bool)]
('a', tf.int32)
collections.OrderedDict([('a', tf.int32), ('b', tf.bool)])

Examples of arguments convertible to nested named tuple types:

(tf.int32, (tf.float32, tf.bool))
(tf.int32, (('x', tf.float32), tf.bool))
((tf.int32, [1]), (('x', (tf.float32, [2])), (tf.bool, [3])))

Custom attr classes can also be converted to a nested tff.Type by using attr.ib(type=...) annotations (deprecated):

@attr.s
class MyDataClass:
  int_scalar = attr.ib(type=tf.int32)
  string_array = attr.ib(type=tff.TensorType(dtype=tf.string, shape=[3]))

Support for converting attr classes is deprecated and will be removed in a future release. Please use one of the other supported forms instead.

spec Either an instance of tff.Type, or an argument convertible to tff.Type.

An instance of tff.Type corresponding to the given spec.