什么是DT_VARIANT张量?

时间:2019-11-17 10:56:24

标签: python-3.x tensorflow

tf.data.Dataset的构造函数采用参数variant_tensor,该参数仅为documented as

  

表示数据集的DT_VARIANT张量。

  

在DatasetV2中,我们希望子类创建一个variant_tensor并将其传递给super()调用。

在哪里可以了解“ DT_VARIANT张量”或“ variant_tensor”是什么?

1 个答案:

答案 0 :(得分:3)

变量张量可以是任何数据类型的张量。

变张量的一些示例如下所示:

# 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)

关于Variant TensorDT_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);

有关更多详细信息,请参阅TF Org PageGithub Source Code。谢谢!

相关问题