既知の直接サブクラス |
モデルの入力または出力のデータバッファを表します。
パブリック メソッド
静的 TensorBuffer | |
静的 TensorBuffer | |
静的 TensorBuffer |
createFrom(TensorBuffer バッファ、DataType dataType)
指定された
DataType で、別のデータからデータをディープコピーする TensorBuffer を作成します。 |
ByteBuffer |
getBuffer()
データバッファを返します。
|
抽象 DataType |
getDataType()
このバッファのデータ型を返します。
|
整数 |
getFlatSize()
バッファの flatSize を取得します。
|
抽象 float[] |
getFloatArray()
このバッファに格納されている値の浮動小数点配列を返します。
|
抽象 浮動小数点 |
getFloatValue(int absIndex)
指定されたインデックスの浮動小数点値を返します。
|
抽象 int[] |
getIntArray()
このバッファに格納されている値の int 配列を返します。
|
抽象 整数 |
getIntValue(int absIndex)
指定されたインデックスの int 値を返します。
|
int[] |
getShape()
現在のシェイプを取得します。
|
抽象 整数 |
getTypeSize()
配列内の単一要素のバイト数を返します。
|
ブール値 |
isDynamic()
TensorBuffer が動的なサイズである場合(任意にサイズ変更が可能である場合)を返します。 |
抽象 void |
loadArray(int[] src, int[] shape)
特定の形状の int 配列をこのバッファに読み込みます。
|
抽象 void |
loadArray(float[] src, int[] shape)
指定した形状の float 配列をこのバッファに読み込みます。
|
void |
loadArray(float[] src)
このバッファに浮動小数点数の配列を読み込みます。
|
void |
loadArray(int[] src)
このバッファに int 配列を読み込みます。
|
void | |
void |
継承されるメソッド
パブリック メソッド
public static TensorBuffer createDynamic (DataType dataType)
指定された DataType
で空の動的 TensorBuffer
を作成します。作成された TensorBuffer
の形状は {0} です。
Dynamic TensorBuffers は、バッファサイズが異なる配列またはデータバッファを読み込むときにメモリを再割り当てします。次に例を示します。
// Creating a float dynamic TensorBuffer: TensorBuffer tensorBuffer = TensorBuffer.createDynamic(DataType.FLOAT32); // Loading a float array: float[] arr1 = new float[] {1, 2, 3}; tensorBuffer.loadArray(arr, new int[] {arr1.length}); // loading another float array: float[] arr2 = new float[] {1, 2, 3, 4, 5}; tensorBuffer.loadArray(arr, new int[] {arr2.length}); // loading a third float array with the same size as arr2, assuming shape doesn't change: float[] arr3 = new float[] {5, 4, 3, 2, 1}; tensorBuffer.loadArray(arr); // loading a forth float array with different size as arr3 and omitting the shape will result // in error: float[] arr4 = new float[] {3, 2, 1}; tensorBuffer.loadArray(arr); // Error: The size of byte buffer and the shape do not match.
パラメータ
dataType | 作成する TensorBuffer の dataType。
|
---|
public static TensorBuffer createFixedSize (int[] shape, DataType dataType)
指定された shape
と DataType
で TensorBuffer
を作成します。次に例を示します。
// Creating a float TensorBuffer with shape {2, 3}: int[] shape = new int[] {2, 3}; TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, DataType.FLOAT32);
// Creating an uint8 TensorBuffer of a scalar: int[] shape = new int[] {}; TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, DataType.UINT8);
// Creating an empty uint8 TensorBuffer: int[] shape = new int[] {0}; TensorBuffer tensorBuffer = TensorBuffer.createFixedSize(shape, DataType.UINT8);
固定サイズの TensorBuffer は、作成後にサイズを変更できません。
パラメータ
シェイプ | 作成する TensorBuffer のシェイプ。 |
---|---|
dataType | 作成する TensorBuffer の dataType。 |
例外
NullPointerException | shape が null の場合。 |
---|---|
IllegalArgumentException | shape に正数でない要素がある場合。 |
public static TensorBuffer createFrom (TensorBuffer buffer, DataType dataType)
指定された DataType
で、別のデータからデータをディープコピーする TensorBuffer
を作成します。
パラメータ
buffer | コピー元の TensorBuffer 。 |
---|---|
dataType | 新しく作成された TensorBuffer の想定される DataType 。 |
例外
NullPointerException | buffer が null の場合。 |
---|
public 抽象 float[] getFloatArray ()
このバッファに格納されている値の浮動小数点配列を返します。バッファが float 型と異なる場合、値は float 型に変換されます。たとえば、TensorBufferUint8
の値は uint8 から float に変換されます。
public 抽象 float getFloatValue (int absIndex)
指定されたインデックスの浮動小数点値を返します。バッファが浮動小数点数と異なる型の場合、値は浮動小数点数に変換されます。たとえば、TensorBufferUint8
から値を読み取る場合、値は最初に uint8 として読み取られ、その後 uint8 から浮動小数点数に変換されます。
For example, a TensorBuffer with shape {2, 3} that represents the following array, [[0.0f, 1.0f, 2.0f], [3.0f, 4.0f, 5.0f]]. The fourth element (whose value is 3.0f) in the TensorBuffer can be retrieved by: float v = tensorBuffer.getFloatValue(3);
パラメータ
absIndex | 読み取られる値の絶対インデックス。 |
---|
public 抽象 int[] getIntArray ()
このバッファに格納されている値の int 配列を返します。バッファの型が int と異なる場合、値は int に変換され、精度が低下する可能性があります。たとえば、TensorBufferFloat
から値が {400.32f, 23.04f} の int 配列を取得すると、出力は {400, 23} になります。
public 抽象 int getIntValue (int absIndex)
指定されたインデックスの int 値を返します。バッファの型が int と異なる場合、値は int に変換されます。たとえば、TensorBufferFloat
から値を読み取る場合、値は最初に float として読み出され、その後 float から int に変換されます。そのため、精度が低下する可能性があります。
For example, a TensorBuffer with shape {2, 3} that represents the following array, [[0.0f, 1.0f, 2.0f], [3.0f, 4.0f, 5.0f]]. The fourth element (whose value is 3.0f) in the TensorBuffer can be retrieved by: int v = tensorBuffer.getIntValue(3); Note that v is converted from 3.0f to 3 as a result of type conversion.
パラメータ
absIndex | 読み取られる値の絶対インデックス。 |
---|
public int[] getShape ()
現在のシェイプを取得します。(予期しない変更を避けるために、ここでコピーを返します)。
例外
IllegalStateException | 基になるデータが破損している場合 |
---|
public 抽象 int getTypeSize ()
配列内の単一要素のバイト数を返します。たとえば、浮動小数点バッファは 4 を返し、バイトバッファは 1 を返します。
public 抽象 void loadArray (int[] src, int[] shape)
特定の形状の int 配列をこのバッファに読み込みます。バッファの型が int と異なる場合、値はバッファに読み込まれる前にバッファの型に変換され、精度が低下する可能性があります。たとえば、値 {400, -23} の int 配列を TensorBufferUint8
に読み込むと、値は [0, 255] にクランプされた後、{255, 0} によって uint8 にキャストされます。
パラメータ
src | 読み込まれるソース配列。 |
---|---|
シェイプ | src が表すテンソルの形状。 |
例外
NullPointerException | src が null の場合。 |
---|---|
NullPointerException | shape が null の場合。 |
IllegalArgumentException | 読み込まれる配列のサイズが指定されたシェイプと一致しない場合。 |
public 抽象 void loadArray (float[] src, int[] shape)
指定した形状の float 配列をこのバッファに読み込みます。バッファの型が float と異なる場合、値はバッファに読み込まれる前にバッファの型に変換され、精度が低下する可能性があります。たとえば、値が {400.32f, -23.04f} の float 配列を TensorBufferUint8
に読み込むと、値は [0, 255] にクランプされてから、{255, 0} によって uint8 にキャストされます。
パラメータ
src | 読み込まれるソース配列。 |
---|---|
シェイプ | src が表すテンソルの形状。 |
例外
NullPointerException | src が null の場合。 |
---|---|
NullPointerException | shape が null の場合。 |
IllegalArgumentException | 読み込まれる配列のサイズが指定されたシェイプと一致しない場合。 |
public void loadArray (float[] src)
このバッファに浮動小数点数の配列を読み込みます。バッファの型が float と異なる場合、値はバッファに読み込まれる前にバッファの型に変換され、精度が低下する可能性があります。たとえば、値が {400.32f, -23.04f} の float 配列を TensorBufferUint8
に読み込むと、値は [0, 255] にクランプされてから、{255, 0} によって uint8 にキャストされます。
このメソッドを使用する場合、src
の形状はこの TensorBuffer
の形状と同じであることを前提としています。したがって、buffer
(src.length
)のサイズは、固定サイズと動的 TensorBuffer
の両方で、この TensorBuffer
のフラットサイズと常に一致する必要があります。src
の形状が異なる場合は、loadArray(float[], int[])
を使用します。
パラメータ
src | 読み込まれるソース配列。 |
---|
public void loadArray (int[] src)
このバッファに int 配列を読み込みます。バッファの型が int と異なる場合、値はバッファに読み込まれる前にバッファの型に変換され、精度が低下する可能性があります。たとえば、値 {400, -23} の int 配列を TensorBufferUint8
に読み込むと、値は [0, 255] にクランプされ、{255, 0} によって uint8 にキャストされます。
このメソッドを使用する場合、src
の形状はこの TensorBuffer
の形状と同じであることを前提としています。したがって、buffer
(src.length
)のサイズは、固定サイズと動的 TensorBuffer
の両方で、この TensorBuffer
のフラットサイズと常に一致する必要があります。src
の形状が異なる場合は、loadArray(int[], int[])
を使用します。
パラメータ
src | 読み込まれるソース配列。 |
---|
public void loadBuffer (ByteBuffer バッファ)
この TensorBuffer
にバイトバッファを読み込みます。バッファサイズは、この TensorBuffer
のフラットサイズと一致する必要があります。
このメソッドを使用する場合、buffer
の形状はこの TensorBuffer
の形状と同じであることを前提としています。したがって、buffer
(buffer.limit()
)のサイズは、固定サイズと動的 TensorBuffer
の両方で、この TensorBuffer
のフラットサイズと常に一致する必要があります。buffer
の形状が異なる場合は、loadBuffer(ByteBuffer, int[])
を使用します。
重要: 読み込まれたバッファは参照です。変更しないでください。パフォーマンス上の問題からコピーは作成されませんが、変更が必要な場合はコピーを作成してください。
最高のパフォーマンスを得るには、常に ByteBuffer
または配列を基盤とする ByteBuffer
を直接読み込みます。
buffer
が読み取り専用の場合は、パフォーマンスのためにコピーオンライト戦略を採用しています。
パラメータ
buffer | 読み込むバイトバッファ。 |
---|
public void loadBuffer (ByteBuffer buffer, int[] shape)
特定のシェイプでバイトバッファをこの TensorBuffer
に読み込みます。
重要: 読み込まれたバッファは参照です。変更しないでください。パフォーマンス上の問題からコピーは作成されませんが、変更が必要な場合はコピーを作成してください。
最高のパフォーマンスを得るには、常に配列を基盤とする ByteBuffer
または ByteBuffer
を直接読み込みます。
パラメータ
buffer | 読み込むバイトバッファ。 |
---|---|
シェイプ |
例外
NullPointerException | buffer が null の場合。 |
---|---|
IllegalArgumentException | buffer と typeSize のサイズが一致しない場合、または buffer と flatSize のサイズが一致しない場合。 |