tff.types.to_type
Stay organized with collections
Save and categorize content based on your preferences.
Converts the argument into an instance of tff.Type
.
tff.types.to_type(
obj: object
) -> tff.types.Type
Examples of arguments convertible to tensor types:
np.int32
(np.int32, [10])
(np.int32, [None])
Examples of arguments convertible to flat named tuple types:
[np.int32, np.bool]
(np.int32, np.bool)
[('a', np.int32), ('b', np.bool)]
('a', np.int32)
collections.OrderedDict([('a', np.int32), ('b', np.bool)])
Examples of arguments convertible to nested named tuple types:
(np.int32, (np.float32, np.bool))
(np.int32, (('x', np.float32), np.bool))
((np.int32, [1]), (('x', (np.float32, [2])), (np.bool, [3])))
attr.s
class instances can also be used to describe TFF types by populating
the fields with the corresponding types:
@attr.s(auto_attribs=True)
class MyDataClass:
int_scalar
string_array
obj = MyDataClass(...)
type_spec = tff.types.to_type(obj)
@tff.tensorflow.computation(type_spec)
def work(my_data):
assert isinstance(my_data, MyDataClass)
...
Args |
obj
|
Either an instance of tff.Type , or an argument convertible to
tff.Type .
|
Returns |
An instance of tff.Type corresponding to the given obj .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-27 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-27 UTC."],[],[],null,["# tff.types.to_type\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nConverts the argument into an instance of [`tff.Type`](../../tff/types/Type).\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tff.to_type`](https://www.tensorflow.org/federated/api_docs/python/tff/types/to_type)\n\n\u003cbr /\u003e\n\n tff.types.to_type(\n obj: object\n ) -\u003e ../../tff/types/Type\n\nExamples of arguments convertible to tensor types: \n\n np.int32\n (np.int32, [10])\n (np.int32, [None])\n\nExamples of arguments convertible to flat named tuple types: \n\n [np.int32, np.bool]\n (np.int32, np.bool)\n [('a', np.int32), ('b', np.bool)]\n ('a', np.int32)\n collections.OrderedDict([('a', np.int32), ('b', np.bool)])\n\nExamples of arguments convertible to nested named tuple types: \n\n (np.int32, (np.float32, np.bool))\n (np.int32, (('x', np.float32), np.bool))\n ((np.int32, [1]), (('x', (np.float32, [2])), (np.bool, [3])))\n\n`attr.s` class instances can also be used to describe TFF types by populating\nthe fields with the corresponding types: \n\n @attr.s(auto_attribs=True)\n class MyDataClass:\n int_scalar\n string_array\n\n obj = MyDataClass(...)\n type_spec = tff.types.to_type(obj)\n\n @tff.tensorflow.computation(type_spec)\n def work(my_data):\n assert isinstance(my_data, MyDataClass)\n ...\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------|-----------------------------------------------------------------------------------------------------------------------------|\n| `obj` | Either an instance of [`tff.Type`](../../tff/types/Type), or an argument convertible to [`tff.Type`](../../tff/types/Type). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| An instance of [`tff.Type`](../../tff/types/Type) corresponding to the given `obj`. ||\n\n\u003cbr /\u003e"]]