TensorLabel class

TensorLabel is an util wrapper for TensorBuffers with meaningful labels on an axis.

For example, an image classification model may have an output tensor with shape as {1, 10}, where 1 is the batch size and 10 is the number of categories. In fact, on the 2nd axis, we could label each sub-tensor with the name or description of each corresponding category. [TensorLabel] could help converting the plain Tensor in [TensorBuffer] into a map from predefined labels to sub-tensors. In this case, if provided 10 labels for the 2nd axis, [TensorLabel] could convert the original {1, 10} Tensor to a 10 element map, each value of which is Tensor in shape {} (scalar).

Note: currently we only support tensor-to-map conversion for the first label with size greater than 1.

See FileUtil.loadLabels to load labels from a label file (plain text file whose each line is a label) in assets simply.

Constructors

TensorLabel(Map<int, List<String>> axisLabels, TensorBuffer tensorBuffer)
Creates a TensorLabel object which is able to label on the axes of multi-dimensional tensors.
factory
TensorLabel.fromList(List<String> axisLabels, TensorBuffer tensorBuffer)
Creates a TensorLabel object which is able to label on one axis of multi-dimensional tensors.
factory
TensorLabel.fromMap(Map<int, List<String>> axisLabels, TensorBuffer tensorBuffer)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getCategoryList() List<Category>
Gets a list of Category from the TensorLabel object.
getMapWithFloatValue() Map<String, double>
Gets a map that maps label to float. Only allow the mapping on the first axis with size greater than 1, and the axis should be effectively the last axis (which means every sub tensor specified by this axis should have a flat size of 1).
getMapWithTensorBuffer() Map<String, TensorBuffer>
Gets the map with a pair of the label and the corresponding TensorBuffer. Only allow the mapping on the first axis with size greater than 1 currently.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

getFirstAxisWithSizeGreaterThanOne(TensorBuffer tensorBuffer) int