的构造函数tf.data.Dataset接受一个参数variant_tensor,该参数仅记录为:
代表数据集的 DT_VARIANT 张量。
和
在 DatasetV2 中,我们期望子类创建一个 variant_tensor 并将其传递给 super() 调用。
我在哪里可以了解“DT_VARIANT 张量”或“variant_tensor”是什么?
变体张量可以是任何数据类型的张量。
变体张量的一些示例如下所示:
# Integer element
a = 1
# Float element
b = 2.0
# Tuple element with 2 components
c = (1, 2)
# Dict element with 3 components
d = {"a": (2, 2), "b": 3}
# Element containing a dataset
e = tf.data.Dataset.from_element(10)
Run Code Online (Sandbox Code Playgroud)
关于Variant Tensor或 的说明DT_Variant如下所示。
// This is an implementation of a type-erased container that can store an
// object of any type. The implementation is very similar to std::any, but has
// restrictions on the types of objects that can be stored, and eschews some of
// the fancier constructors available for std::any. An object of
// tensorflow::Variant is intended to be used as the value that will be stored
// in a tensorflow::Tensor object when its type is DT_VARIANT.
//
// tensorflow::Variant can store an object of a class that satisfies the
// following constraints:
//
// * The class is CopyConstructible.
// * The class has a default constructor.
// * It's either a protocol buffer, a tensorflow::Tensor, or defines the
// following functions:
//
// string TypeName() const;
// void Encode(VariantTensorData* data) const;
// bool Decode(VariantTensorData data);
Run Code Online (Sandbox Code Playgroud)
更多细节请参考TF Org Page和Github源代码。
| 归档时间: |
|
| 查看次数: |
1622 次 |
| 最近记录: |