public class Ailia
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
AILIA_MEMORY_REDUCE_CONSTANT_WITH_FILE_MAPPED
Deprecated.
|
static int |
ENVIRONMENT_ID_AUTO
Automatic setup of the inference backend
|
static int |
MEMORY_NO_OPTIMIZATION
Deprecated.
Please use
AiliaMemoryMode.NO_OPTIMIZATION |
static int |
MEMORY_OPTIMAIZE_DEFAULT
Deprecated.
Please use
AiliaMemoryMode.OPTIMAIZE_DEFAULT |
static int |
MEMORY_REDUCE_CONSTANT
Deprecated.
Please use
AiliaMemoryMode.REDUCE_CONSTANT |
static int |
MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER
Deprecated.
|
static int |
MEMORY_REDUCE_INTERSTAGE
Deprecated.
Please use
AiliaMemoryMode.REDUCE_INTERSTAGE |
static int |
MEMORY_REUSE_INTERSTAGE
Deprecated.
Please use
AiliaMemoryMode.REUSE_INTERSTAGE |
static int |
MULTITHREAD_AUTO
Number of threads
|
Constructor and Description |
---|
Ailia() |
Modifier and Type | Method and Description |
---|---|
static void |
CopyBlobData(long dstHandle,
int dstBlobIdx,
long srcHandle,
int srcBlobIdx)
Perform copies between blobs that specified.
|
static long |
Create(int envId,
int numThread)
Creates a network instance.
|
static void |
Destroy(long handle)
It destroys the network instance.
|
static void |
DisableLayerFusion(long handle)
Disalbe layer fusion optimaization for inference
|
static void |
Finalize()
Release GPU and other resources that have been globally allocated with ailia.
|
static int |
FindBlobIndexByName(long handle,
java.lang.String name)
Searches by name for the index of the internal data (blob) during inference and returns it.
|
static java.lang.String |
FindBlobNameByIndex(long handle,
int blobIdx)
Searches by index for the name of the internal data (blob) during inference and returns it.
|
static int |
GetBlobCount(long handle)
Gets the amount of internal data (blob) during inference.
|
static void |
GetBlobData(long handle,
float[] dest,
int destSize,
int blobIdx)
Gets the internal data (blob) during inference.
|
static int |
GetBlobDim(long handle,
int blobIdx)
Gets the dimension of the internal data (blob) during inference.
|
static int |
GetBlobIndexByInputIndex(long handle,
int inputBlobIdx)
Get the blob index of the input data.
|
static int |
GetBlobIndexByOutputIndex(long handle,
int outputBlobIdx)
Get the blob index of the output data blob.
|
static AiliaShape |
GetBlobShape(long handle,
int blobIdx,
int version)
Gets the shape of the internal data (blob) during inference.
|
static void |
GetBlobShapeND(long handle,
int[] shape,
int dim,
int blobIdx)
Gets the shape of internal data (blob) during inference.
|
static AiliaEnvironment |
GetEnvironment(int env_id,
int version)
Gets the list of computational environments.
|
static int |
GetEnvironmentCount()
Gets the number of available computational environments (CPU, GPU).
|
static java.lang.String |
GetErrorDetail(long handle)
Returns the details of errors.
|
static int |
GetInputBlobCount(long handle)
Get the number of input data blobs.
|
static int |
GetInputDim(long handle)
Gets the dimension of the input data during inference.
|
static AiliaShape |
GetInputShape(long handle,
int version)
Gets the shape of the input data during inference.
|
static void |
GetInputShapeND(long handle,
int[] shape,
int dim)
Gets the shape of the input data during inference.
|
static int |
GetOutputBlobCount(long handle)
Get the number of output data blobs.
|
static int |
GetOutputDim(long handle)
Gets the dimension of the output data during inference.
|
static AiliaShape |
GetOutputShape(long handle,
int version)
Gets the shape of the output data during inference.
|
static void |
GetOutputShapeND(long handle,
int[] shape,
int dim)
Gets the shape of the output data during inference.
|
static AiliaEnvironment |
GetSelectedEnvironment(long handle,
int version)
Gets the selected computational environment.
|
static java.lang.String |
GetVersion()
Get the version of the library.
|
static void |
OpenStreamFile(long handle,
java.lang.String path)
Initializes the network instance.
|
static void |
OpenStreamMem(long handle,
byte[] buf,
int buf_size)
Initializes the network instance.
|
static void |
OpenWeightFile(long handle,
java.lang.String path)
Reads weights into a network instance.
|
static void |
OpenWeightMem(long handle,
byte[] buf,
int buf_size)
Reads weights into a network instance.
|
static void |
Predict(long handle,
float[] dest,
int destSize,
float[] src,
int srcSize)
Performs the inferences and provides the inference result.
|
static void |
SetInputBlobData(long handle,
float[] src,
int srcSize,
int blobIdx)
Provides the specified blob with the input data.
|
static void |
SetInputBlobShape(long handle,
AiliaShape shape,
int blobIdx,
int version)
Change the shape of the blob given by its index
|
static void |
SetInputBlobShapeND(long handle,
int[] shape,
int dim,
int blobIdx)
Change the shape of the blob given by its index
|
static void |
SetInputShape(long handle,
AiliaShape shape,
int version)
Changes the shape of the input data during inference.
|
static void |
SetInputShapeND(long handle,
int[] shape,
int dim)
Changes the shape of the input data during inference.
|
static void |
SetMemoryMode(long handle,
int mode)
Set the memory usage policy for inference
|
static void |
SetProfileMode(long handle,
int mode)
Set the profile mode.
|
static void |
SetTemporaryCachePath(java.lang.String cache_path)
Specifies a temporary cache directory.
|
static java.lang.String |
Summary(long handle)
Shows the name and shape of each blob.
|
static void |
Update(long handle)
Makes inferences with the input data specified in advance.
|
public static final int MULTITHREAD_AUTO
public static final int ENVIRONMENT_ID_AUTO
@Deprecated public static final int MEMORY_NO_OPTIMIZATION
AiliaMemoryMode.NO_OPTIMIZATION
@Deprecated public static final int MEMORY_REDUCE_CONSTANT
AiliaMemoryMode.REDUCE_CONSTANT
@Deprecated public static final int MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER
AiliaMemoryMode.REDUCE_CONSTANT_WITH_INPUT_INITIALIZER
@Deprecated public static final int MEMORY_REDUCE_INTERSTAGE
AiliaMemoryMode.REDUCE_INTERSTAGE
@Deprecated public static final int MEMORY_REUSE_INTERSTAGE
AiliaMemoryMode.REUSE_INTERSTAGE
MEMORY_REDUCE_INTERSTAGE
, the sharable intermediate buffer is not opened.@Deprecated public static final int AILIA_MEMORY_REDUCE_CONSTANT_WITH_FILE_MAPPED
AiliaMemoryMode.REDUCE_CONSTANT_WITH_FILE_MAPPED
@Deprecated public static final int MEMORY_OPTIMAIZE_DEFAULT
AiliaMemoryMode.OPTIMAIZE_DEFAULT
public static long Create(int envId, int numThread) throws AiliaException
If the inference backend is set to automatic, CPU mode is used, while if BLAS is available, it uses BLAS. Note that if BLAS is used, num_thread may be ignored.
envId
- The ID of the inference backend used for computation (obtained by GetEnvironment(int, int)
). It is selected automatically if ENVIRONMENT_ID_AUTO
is specified.numThread
- The upper limit on the number of threads (It is set automatically if MULTITHREAD_AUTO
is specified.)AiliaException
- Exceptionpublic static void OpenStreamFile(long handle, java.lang.String path) throws AiliaException
This function reads the network instance from a file and initializes it.
handle
- A network instance handlepath
- The path name to the prototxt fileAiliaException
- Exceptionpublic static void OpenStreamMem(long handle, byte[] buf, int buf_size) throws AiliaException
This function reads the network instance from memory and initializes it.
handle
- A network instance handlebuf
- An array of the data in the protobuf filebuf_size
- The data size of the prototxt fileAiliaException
- Exceptionpublic static void OpenWeightFile(long handle, java.lang.String path) throws AiliaException
This function reads weights into the network instance from a file.
handle
- A network instance handlepath
- The path name to the protobuf/onnx fileAiliaException
- Exceptionpublic static void OpenWeightMem(long handle, byte[] buf, int buf_size) throws AiliaException
handle
- A network instance handlebuf
- An array of the data in the protobuf/onnx filebuf_size
- The data size of the protobuf/onnx fileAiliaException
- Exceptionpublic static void Destroy(long handle)
handle
- A network instance handlepublic static void SetInputShape(long handle, AiliaShape shape, int version) throws AiliaException
This function changes the input shape defined in prototxt.
The shape must have the same rank as the one contained in prototxt.
Note that AiliaException
may be throw if the weights are dependent on the input shapes, among other reasons.
The dimension of shape that defined in prototxt has 5 or more, please use SetInputShapeND(long, int[], int)
.
handle
- A network instance handleshape
- Shape information for the input dataversion
- Shape version(AiliaShape.version
)AiliaException
- Exceptionpublic static void SetInputShapeND(long handle, int[] shape, int dim) throws AiliaException
This function changes the input shape defined in prototxt.
The shape must have the same rank as the one contained in prototxt.
Note that AiliaException
may be throw if the weights are dependent on the input shapes, among other reasons.
handle
- A network instance handleshape
- An array of shapedim
- The size of shape.AiliaException
- Exceptionpublic static AiliaShape GetInputShape(long handle, int version) throws AiliaException
When dimension of shape is 5 or more, please use GetInputDim(long)
and GetInputShapeND(long, int[], int)
.
When shape is not settled, this method stores 0 at unsettled dimension and otherwise stores valid value.
handle
- A network instance handleversion
- Shape version(AiliaShape.version
)AiliaException
- Exceptionpublic static int GetInputDim(long handle)
handle
- A network instance handlepublic static void GetInputShapeND(long handle, int[] shape, int dim)
When shape is not settled, this function stores 0 at unsettled dimension and otherwise stores valid value.
handle
- A network instance handleshape
- The storage array of the shape. (It stores dim-1, dim-2, ... ,1, 0 order.)dim
- The size of shapepublic static AiliaShape GetOutputShape(long handle, int version) throws AiliaException
When dimension of shape is 5 or more, please use GetOutputDim(long)
and GetOutputShapeND(long, int[], int)
.
handle
- A network instance handleversion
- Shape version(AiliaShape.version
)AiliaException
- Exceptionpublic static int GetOutputDim(long handle)
handle
- A network instance handlepublic static void GetOutputShapeND(long handle, int[] shape, int dim)
handle
- A network instance handleshape
- The storage array of the shape. (It stores dim-1, dim-2, ... ,1, 0 order.)dim
- The size of shapepublic static void Predict(long handle, float[] dest, int destSize, float[] src, int srcSize) throws AiliaException
handle
- A network instance handledest
- The result is stored in the inference result destination buffer as float data in the order of X, Y, Z, and W. The buffer has the same size as the network file outputSize.destSize
- The size of the dest (in byte)src
- The input is stored as float data in the order of the inference data X, Y, Z, and W. The input has the same size as the network file inputSize.srcSize
- The size of the src (in byte)AiliaException
- Exceptionpublic static int GetBlobCount(long handle) throws AiliaException
handle
- A network instance handleAiliaException
- Exceptionpublic static AiliaShape GetBlobShape(long handle, int blobIdx, int version) throws AiliaException
handle
- A network instance handleblobIdx
- The index of the blob (0 to GetBlobCount(long)
-1)version
- Shape version(AiliaShape.version
)AiliaException
- Exceptionpublic static int GetBlobDim(long handle, int blobIdx)
handle
- A network instance handleblobIdx
- The index of the blob (0 to GetBlobCount(long)
-1)public static void GetBlobShapeND(long handle, int[] shape, int dim, int blobIdx)
handle
- A network instance handleshape
- The storage array of the shape. (It stores dim-1, dim-2, ... ,1, 0 order.)dim
- The size of shapeblobIdx
- The index of the blob (0 to GetBlobCount(long)
-1)public static void GetBlobData(long handle, float[] dest, int destSize, int blobIdx) throws AiliaException
handle
- A network instance handledest
- The result is stored in the inference result destination buffer as float data in the order of X, Y, Z, and W.destSize
- The size of the dest (in byte)blobIdx
- The index of the blob (0 to GetBlobCount(long)
-1)AiliaException
- Exceptionpublic static int FindBlobIndexByName(long handle, java.lang.String name) throws AiliaException
handle
- A network instance handlename
- The name of the blob to search forGetBlobCount(long)
-1)AiliaException
- Exceptionpublic static java.lang.String FindBlobNameByIndex(long handle, int blobIdx) throws AiliaException
handle
- A network instance handleblobIdx
- The index of the blob (0 to GetBlobCount(long)
-1)AiliaException
- Exceptionpublic static java.lang.String Summary(long handle) throws AiliaException
handle
- A network instance handleAiliaException
- Exceptionpublic static int GetInputBlobCount(long handle) throws AiliaException
handle
- A network instance handleAiliaException
- Exceptionpublic static int GetBlobIndexByInputIndex(long handle, int inputBlobIdx) throws AiliaException
handle
- A network instance handleinputBlobIdx
- Index among the input blobs (between 0 and GetInputBlobCount(long)
-1)GetBlobCount(long)
-1)AiliaException
- Exceptionpublic static void SetInputBlobData(long handle, float[] src, int srcSize, int blobIdx) throws AiliaException
This method is used to specify the input on networks with multiple inputs.
handle
- A network instance handlesrc
- The inference data is stored as float data in the order of X, Y, Z, and W.srcSize
- The size of the inference data (in byte)blobIdx
- The index of the blob for inputAiliaException
- Exceptionpublic static void SetInputBlobShape(long handle, AiliaShape shape, int blobIdx, int version) throws AiliaException
This is useful to change the network input shape in a context where there are several input blobs.
If dimension of shape has 5 or more, please use SetInputBlobShapeND(long, int[], int, int)
handle
- A network instance handleshape
- New shape of the blobblobIdx
- Index referencing the blob to reshapeversion
- Shape version(AiliaShape.version
)AiliaException
- ExceptionSetInputShape(long, AiliaShape, int)
public static void SetInputBlobShapeND(long handle, int[] shape, int dim, int blobIdx) throws AiliaException
This is useful to change the network input shape in a context where there are several input blobs.
handle
- A network instance handleshape
- The array of the new shape. (It stores dim-1, dim-2, ... ,1, 0 order.)dim
- The size of shapeblobIdx
- Index referencing the blob to reshapeAiliaException
- ExceptionSetInputShapeND(long, int[], int)
public static void CopyBlobData(long dstHandle, int dstBlobIdx, long srcHandle, int srcBlobIdx) throws AiliaException
dstHandle
- A network instance handle that contains destination blobdstBlobIdx
- A network instance handle The index of destination blobsrcHandle
- A network instance handle that contains source blobsrcBlobIdx
- A network instance handle The index of source blobAiliaException
- Exceptionpublic static void Update(long handle) throws AiliaException
This function is used when, for example, the input is provided with SetInputBlobData(long, float[], int, int)
.
Get the inference result with GetBlobData(long, float[], int, int)
handle
- A network instance handleAiliaException
- Exceptionpublic static int GetOutputBlobCount(long handle) throws AiliaException
handle
- A network instance handleAiliaException
- Exceptionpublic static int GetBlobIndexByOutputIndex(long handle, int outputBlobIdx) throws AiliaException
handle
- A network instance handleoutputBlobIdx
- Index among output blobs (between 0 and GetOutputBlobCount(long)
-1)GetBlobCount(long)
-1)AiliaException
- Exceptionpublic static void SetTemporaryCachePath(java.lang.String cache_path) throws AiliaException
This system uses the specified cache directory to generate and store machine code optimized for each inference backend. Call only once at the start of execution of ailia. It ignores any second and subsequent calls, and automatically returns success. There is no particular problem if it is called from multiple threads, as it provides exclusive control internally. Some functions, such as Vulkan shader cache, cannot be used until this API function is called. Specify the file path obtained by android.content.Context#getCacheDir() for cache_dir.
cache_path
- Temporary cache directoryAiliaException
- Exceptionpublic static int GetEnvironmentCount() throws AiliaException
AiliaException
- Exceptionpublic static AiliaEnvironment GetEnvironment(int env_id, int version) throws AiliaException
env_id
- The index of the computational environment information (0 to GetEnvironmentCount()
-1)version
- AiliaEnvironment.version
AiliaException
- Exceptionpublic static AiliaEnvironment GetSelectedEnvironment(long handle, int version) throws AiliaException
handle
- A network instance handleversion
- AiliaEnvironment.version
AiliaException
- Exceptionpublic static void SetMemoryMode(long handle, int mode) throws AiliaException
Change the memory usage policy.
If a value other than MEMORY_NO_OPTIMIZATION
is specified,
the intermediate buffer secured during inference will be released, so the memory usage during inference can be reduced.
Must be specified immediately after ailiaCreate. It cannot be changed after calling ailiaOpen.
If you specify to release the intermediate buffer, calling GetBlobData(long, float[], int, int)
for the corresponding blob will thrown AiliaException
.
handle
- A network instance handlemode
- Memory mode (Multiple specifications possible with logical sum) AiliaMemoryMode
(Default :AiliaMemoryMode.OPTIMAIZE_DEFAULT
)AiliaException
- Exceptionpublic static void DisableLayerFusion(long handle) throws AiliaException
This api use to get blob that remove by layer fusion optimization. Must be specified immediately after ailiaCreate. It cannot be changed after calling ailiaOpen. Note: When disable layer fusion optimization, inference speed may be down.
handle
- A network instance handleAiliaException
public static void SetProfileMode(long handle, int mode) throws AiliaException
Change the profile mode.
If a value other than AiliaProfileMode.PROFILE_DISABLE
is specified,
the profile data is added to Summary
handle
- A network instance handlemode
- Profile mode (Default :AiliaProfileMode.PROFILE_DISABLE
)AiliaException
- Exceptionpublic static java.lang.String GetErrorDetail(long handle)
handle
- A network instance handlepublic static java.lang.String GetVersion()
public static void Finalize() throws AiliaException
AiliaException
- Exception