TensorLabel は、軸上に意味のあるラベルを持つ TensorBuffer のユーティリティ ラッパーです。
たとえば、画像分類モデルの出力テンソルの形状は {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();
注: 現時点では、サイズが大きい最初のラベルのテンソルからマップへの変換のみがサポートされています なります。
パブリック コンストラクタ
|
TensorLabel(Map<Integer, List<String>> alignLabels, TensorBuffer tensorBuffer)
多次元テンソルの軸にラベル付けできる TensorLabel オブジェクトを作成します。
|
|
|
TensorLabel(List<String> alignLabels, TensorBuffer tensorBuffer)
多次元テンソルの 1 軸にラベル付けできる TensorLabel オブジェクトを作成します。
|
パブリック メソッド
| List<カテゴリ> |
getCategoryList()
TensorLabel オブジェクトから Category のリストを取得します。 |
| Map<String, Float> |
getMapWithFloatValue()
label を float にマッピングする地図を取得します。
|
| Map<String, TensorBuffer> |
getMapWithTensorBuffer()
ラベルと対応する TensorBuffer のペアを含む地図を取得します。
|
継承されるメソッド
パブリック コンストラクタ
<ph type="x-smartling-placeholder"></ph> 一般公開 TensorLabel (Map <Integer, List<String>> alignLabels, TensorBuffer tensorBuffer)
多次元テンソルの軸にラベル付けできる TensorLabel オブジェクトを作成します。
パラメータ
| axisLabels | キーが軸 ID(0 から開始)で、値が対応するマップ できます。注: ラベルのサイズは、その軸のテンソルのサイズと同じにする必要があります。 |
|---|---|
| tensorBuffer | ラベル付けする TensorBuffer。 |
例外
| NullPointerException | axisLabels または tensorBuffer が null またはいずれか
axisLabels の値が null です。 |
|---|---|
| IllegalArgumentException | axisLabels のキーが範囲外の場合(比較対象:
tensorBuffer の形状、または任意の値(ラベル)のサイズが、指定されたディメンションの tensorBuffer と異なります。
|
<ph type="x-smartling-placeholder"></ph> 一般公開 TensorLabel (List<String> alignLabels, TensorBuffer tensorBuffer)
多次元テンソルの 1 軸にラベル付けできる TensorLabel オブジェクトを作成します。
注: ラベルは、サイズが 1 より大きい最初の軸に適用されます。たとえば
テンソルの形状が [1, 10, 3] の場合、ラベルは軸 1 に適用されます(ID は
0)、axisLabels のサイズも 10 にする必要があります。
パラメータ
| axisLabels | ラベルのリスト。そのサイズは 1 次元のテンソルのサイズと同じでなければなりません。 指定します。 |
|---|---|
| tensorBuffer | ラベル付けする TensorBuffer。 |
パブリック メソッド
<ph type="x-smartling-placeholder"></ph> 一般公開 List<カテゴリ> getCategoryList ()
TensorLabel オブジェクトから Category のリストを取得します。
ラベルの軸は実質的に最後の軸でなければなりません(つまり、すべてのサブテンソル
平面のサイズを 1 にする必要がある)。これにより、ラベル付けされた各サブテンソルは、
浮動小数点値のスコアに変換されます。例: 形状が {2, 5, 3} の TensorLabel
軸 2 は有効です。軸が 1 または 0 の場合、Category に変換できません。
getMapWithFloatValue() も代替手段ですが、次のように Map を返します。
返されます。
例外
| IllegalStateException | 各ラベルの下位テンソルのサイズが 1 でない場合。 |
|---|
<ph type="x-smartling-placeholder"></ph> 一般公開 Map<String, Float> getMapWithFloatValue ()
label を float にマッピングする地図を取得します。サイズがより大きい最初の軸のマッピングのみを許可します 軸は実質的に最後の軸にする必要があります(つまり、すべてのサブテンソル は、フラットサイズ 1)にする必要があります。
getCategoryList() は、結果を取得するための代替 API です。
例外
| IllegalStateException | 各ラベルの下位テンソルのサイズが 1 でない場合。 |
|---|
<ph type="x-smartling-placeholder"></ph> 一般公開 Map<String, TensorBuffer> getMapWithTensorBuffer ()
ラベルと対応する TensorBuffer のペアを含む地図を取得します。次のみを許可: サイズが 1 より大きい最初の軸でマッピングが表示されています。