Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is a DT_VARIANT tensor?

The constructor of tf.data.Dataset takes an argument variant_tensor, which is only documented as:

A DT_VARIANT tensor that represents the dataset.

and

in the DatasetV2, we expect subclasses to create a variant_tensor and pass it in to the super() call.

Where can I learn what a "DT_VARIANT tensor" or a "variant_tensor" is?

like image 946
jochen Avatar asked Nov 17 '19 10:11

jochen


People also ask

What are Dtypes in TensorFlow?

Classes. class DType : Represents the type of the elements in a Tensor .

What is variant tensor?

A contravariant tensor is a tensor having specific transformation properties (cf., a covariant tensor). To examine the transformation properties of a contravariant tensor, first consider a tensor of rank 1 (a vector)

What does from_tensor_slices do?

from_tensor_slices(tensor) creates a Dataset whose elements are slices of the given tensors.

What is a TF dataset?

The tf. data API introduces a tf. data. Dataset abstraction that represents a sequence of elements, in which each element consists of one or more components. For example, in an image pipeline, an element might be a single training example, with a pair of tensor components representing the image and its label.


1 Answers

A Variant Tensor can be a Tensor of any data type.

Some examples of Variant Tensor are shown below:

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

Explanation about Variant Tensor or DT_Variant is shown below.

// 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);

For more details, please refer TF Org Page and Github source code.

like image 188
Tensorflow Support Avatar answered Sep 30 '22 14:09

Tensorflow Support