TensorLabel

public class TensorLabel

TensorLabel は、軸上に意味のあるラベルを持つ TensorBuffers のユーティリティ ラッパーです。

たとえば、画像分類モデルの出力テンソルの形状が {1, 10} の場合、1 はバッチサイズ、10 はカテゴリ数です。実際、2 番目の軸では、各サブテンソルに、対応する各カテゴリの名前や説明でラベルを付けることができます。TensorLabel は、TensorBuffer のプレーンなテンソルを、事前定義されたラベルからサブテンソルへのマップに変換するのに役立ちます。この場合、第 2 軸に 10 個のラベルを指定すると、TensorLabel は元の {1, 10} テンソルを 10 要素マップに変換できます。その各値は形状 {}(スカラー)のテンソルです。使用例:

   TensorBuffer outputTensor = ...;
   List<String> labels = FileUtil.loadLabels(context, labelFilePath);
   // labels the first axis with size greater than one
   TensorLabel labeled = new TensorLabel(labels, outputTensor);
   // If each sub-tensor has effectively size 1, we can directly get a float value
   Map<String, Float> probabilities = labeled.getMapWithFloatValue();
   // Or get sub-tensors, when each sub-tensor has elements more than 1
   Map<String, TensorBuffer> subTensors = labeled.getMapWithTensorBuffer();
 

注: 現在、テンソルからマップへの変換は、サイズが 1 より大きい最初のラベルに対してのみサポートされています。

パブリック コンストラクタ

TensorLabelMap<IntegerList<String>> axisLabels, TensorBuffer tensorBuffer)
多次元テンソルの軸にラベルを付けられる TensorLabel オブジェクトを作成します。
TensorLabelList<String> axisLabels、TensorBuffer tensorBuffer)
多次元テンソルの 1 軸上にラベル付けできる TensorLabel オブジェクトを作成します。

パブリック メソッド

List<Category>
getCategoryList()
TensorLabel オブジェクトから Category のリストを取得します。
Map<StringFloat>
getMapWithFloatValue()
ラベルを浮動小数点数にマッピングする地図を取得します。
Map<StringTensorBuffer>
getMapWithTensorBuffer()
ラベルと対応する TensorBuffer のペアを持つマップを取得します。

継承されるメソッド

パブリック コンストラクタ

public TensorLabel (Map<IntegerList<String>> axisLabels, TensorBuffer tensorBuffer)

多次元テンソルの軸にラベルを付けられる TensorLabel オブジェクトを作成します。

パラメータ
axisLabels キーが軸 ID(0 から始まる)で、値が対応するラベルであるマップ。注: ラベルのサイズは、その軸上のテンソルのサイズと同じにする必要があります。
tensorBuffer ラベルを付ける TensorBuffer。
例外
NullPointerException axisLabels または tensorBuffer が null、または axisLabels のいずれかの値が null の場合。
IllegalArgumentException axisLabels のいずれかのキーが範囲外(tensorBuffer の形状との比較)、または任意の値(ラベル)が指定されたディメンションの tensorBuffer とサイズが異なる場合。

public TensorLabel (List<String> axisLabels, TensorBuffer tensorBuffer)

多次元テンソルの 1 軸にラベルを付けられる TensorLabel オブジェクトを作成します。

注: ラベルは、サイズが 1 より大きい最初の軸に適用されます。たとえば、テンソルの形状が [1, 10, 3] の場合、ラベルは軸 1(0 から始まる id)に適用され、axisLabels のサイズも 10 である必要があります。

パラメータ
axisLabels ラベルのリスト。そのサイズは、ラベルを付ける軸のテンソルのサイズと同じである必要があります。
tensorBuffer ラベルを付ける TensorBuffer。

パブリック メソッド

public List<Category> getCategoryList ()

TensorLabel オブジェクトから Category のリストを取得します。

ラベルの軸は実質的に最後の軸である必要があります(つまり、この軸で指定されたすべてのサブテンソルのフラット サイズが 1 である必要があります)。これにより、ラベル付けされた各サブテンソルを浮動小数点数のスコアに変換できます。例: 形状 {2, 5, 3} で軸 2 の TensorLabel は有効です。軸が 1 または 0 の場合、Category に変換できません。

getMapWithFloatValue() は代替手段ですが、結果として Map を返します。

例外
IllegalStateException 各ラベルのサブテンソルのサイズが 1 でない場合。

public Map<StringFloat> getMapWithFloatValue ()

ラベルを浮動小数点数にマッピングする地図を取得します。最初の軸でサイズが 1 より大きいマッピングのみを許可し、その軸を実質的に最後の軸にする必要があります(つまり、この軸によって指定されるすべてのサブテンソルのフラットなサイズを 1 にします)。

getCategoryList() は、結果を取得するための代替 API です。

例外
IllegalStateException 各ラベルのサブテンソルのサイズが 1 でない場合。

public Map<StringTensorBuffer> getMapWithTensorBuffer ()

ラベルと対応する TensorBuffer のペアを持つマップを取得します。現時点では、サイズが 1 より大きい最初の軸でのマッピングのみを許可します。