ailia_tflite package

Classes

class ailia_tflite.Interpreter(model_path=None, env_id: int = 0, memory_mode: int = 0, flags: int = 0, **kwargs)

Bases: object

ailia TFLite Runtime inference interface (compatible with tf.lite.interpreter)
ailia TFLite Runtime 推論用インターフェース(tf.lite.Interpreterと互換)
__init__(model_path=None, env_id: int = 0, memory_mode: int = 0, flags: int = 0, **kwargs)
Constructor
コンストラクタ
Parameters:
  • model_path (str) –

    Path to tflite model
    tfliteモデルへのパス

  • env_id (int) –

    Used when using NNAPI in Android ID in the execution environment
    実行環境のID、AndroidでNNAPIを使用する場合に使用

  • memory_mode (int) –

    ailia_tflite.AILIA_TFLITE_MEMORY_REDUCE_INTERSTAGE can be used by specifying the memory mode.
    ailia_tflite.AILIA_TFLITE_MEMORY_MODE_REDUCE_INTERSTAGEを指定することで省メモリモードが使用可能

  • flags (int) –

    You can change the reasoning mode by specifying ailia_tflite.AILIA_TFLITE_FLAG_*
    ailia_tflite.AILIA_TFLITE_FLAG_*を指定することで推論モードを変更可能

allocate_tensors()
Allocate tensor buffers
Tensorの割当を行う
get_cpu_features()
Get the CPU instrunction to use
使用するCPU命令を取得する
Returns:

AILIA_TFLITE_CPU_FEATURES_XXX logical sum
AILIA_TFLITE_CPU_FEATURES_XXXの論理和

Return type:

int

get_input_details()
Get information of input tensor
入力Tensorの情報を取得する
Returns:

Input tensor information array
入力Tensorの情報の配列。

Return type:

List[Dict[str, any]]

References

index
Tensor index
Tensorのindex
shape
Tensor shape(numpy array)
Tensorの形状(numpy array)
shape_signature
Tensor shape signature(numpy array) Unlike Shape, if the shape is undecided, -1 is stored.
Tensorの形状(numpy array) shapeと異なり、形状が未定な場合は-1が格納される。
dtype
Tensor type
Tensorの型
name
Tensor name
Tensor名
quantization
Quantization information(deprecated)
量子化情報(deprecated)
quantization_parameters
Quantization parameters
量子化情報
quantization_parameters.scales
Array of scale (1 element when quantizing in tensor units)
スケールの配列 (Tensor単位で量子化する場合は1要素)
quantization_parameters.zero_points
Array of zero point (1 element when quantizing in tensor units)
ゼロポイントの配列 (Tensor単位で量子化する場合は1要素)
quantization_parameters.quantized_dimension
Axis of quantization (Specify when quantizing in axis units)
量子化を行う軸 (axis単位で量子化する場合に指定)
get_node_infos()
Get node information
Nodeの情報を取得する
Returns:

Node information array
Nodeの情報の配列

Return type:

List[Dict[str, any]]

References

index
Node index
Nodeのindex
name
Node name
Nodeの名前
operator
Operator enum value
Operatorのenum値
operator_name
Operator name
Operatorの名前
input_tensor_indices
List of index of input tensor
入力TensorのindexのList
input_details
List of information in input tensor
入力Tensorの情報のList
output_tensor_index
Index of output tensor
出力Tensorのindex
output_detail
Output tensor information
出力Tensorの情報
weight
Weight (for Conv2D/DepthwiseConv2D/Fullyconnected)
Weight (Conv2D/DepthwiseConv2D/FullyConnectedの場合)
weight_detail
Weight detail (for Conv2D/DepthwiseConv2D/Fullyconnected)
Weightの情報 (Conv2D/DepthwiseConv2D/FullyConnectedの場合)
bias
Bias (for Conv2D/DepthwiseConv2D/Fullyconnected)
Bias (Conv2D/DepthwiseConv2D/FullyConnectedの場合)
bias_detail
Bias detail(for Conv2D/DepthwiseConv2D/Fullyconnected)
Biasの情報 (Conv2D/DepthwiseConv2D/FullyConnectedの場合)
option
Dict of option name and value (for Add/Conv2D/DepthwiseConv2D/FullyConnected/MaxPool2D/Softmax/Mean)
オプション名と値のDict (Add/Conv2D/DepthwiseConv2D/FullyConnected/MaxPool2D/Softmax/Meanの場合)
get_output_details()
Get information of output tensor
出力Tensorの情報を取得する
Returns:

Output tensor information array
出力Tensorの情報の配列

Return type:

List[Dict[str, any]]

References

index
Tensor index
Tensorのindex
shape
Tensor shape(numpy array)
Tensorの形状(numpy array)
shape_signature
Tensor shape signature(numpy array) Unlike Shape, if the shape is undecided, -1 is stored.
Tensorの形状(numpy array) shapeと異なり、形状が未定な場合は-1が格納される。
dtype
Tensor type
Tensorの型
name
Tensor name
Tensor名
quantization
Quantization information(deprecated)
量子化情報(deprecated)
quantization_parameters
Quantization parameters
量子化情報
quantization_parameters.scales
Array of scale (1 element when quantizing in tensor units)
スケールの配列 (Tensor単位で量子化する場合は1要素)
quantization_parameters.zero_points
Array of zero point (1 element when quantizing in tensor units)
ゼロポイントの配列 (Tensor単位で量子化する場合は1要素)
quantization_parameters.quantized_dimension
Axis of quantization (Specify when quantizing in axis units)
量子化を行う軸 (axis単位で量子化する場合に指定)
get_summary()
Get the summary information
サマリを取得する
Returns:

Summary information
サマリ情報

Return type:

str

get_tensor(tensor_index)
Get the value of the specified tensor
指定したTensorの値を取得する
Parameters:

tensor_index (int) –

Tensor’s index (acquired with get_output_details)
Tensorのindex(get_output_detailsで取得する)

Returns:

Tensor value
Tensorの値

Return type:

np.ndarray

invoke()
Inference
推論を実行する
resize_tensor_input(tensor_index, shape, strict=False)
Change input tensor shape
入力Tensorの形状を変更する
Parameters:
  • tensor_index (int) –

    Index of Tensor (index returned by Get_input_details)
    Tensorのindex(get_input_detailsが返すindex)

  • shape (Union[Tuple, nd.array, List]) –

    New shape
    新しい形状

  • strict (bool, optional) –

    Strict mode. In the case of true, only unknown dimensions (parts that are -1 in Shape_Signature) can be changed. by default False
    厳格モード。Trueの場合不明な次元(shape_signatureで-1となっている部分)のみ変更可能です。デフォルトはFalseです。

set_cpu_features(cpu_features)
Set the CPU instruction to use
使用するCPU命令を設定する
Parameters:

cpu_features (int) –

AILIA_TFLITE_CPU_FEATURES_XXX logical sum
AILIA_TFLITE_CPU_FEATURES_XXXの論理和

set_profile_mode(profile_mode)
Enable profile mode
プロファイルモードを指定する
It must be executed immediately after creation of an interpreter. After setting the profile mode, you can get profile information by calling get_summary.
Interpreterの作成直後に実行する必要がある。プロファイルモードを設定した後にget_summaryを呼び出すことで、プロファイル情報を取得可能。
Parameters:

profile_mode (bool or int) –

Profile mode (enabled in true)
プロファイルモード(Trueで有効)

set_tensor(tensor_index, value)
Set the value in the specified tensor
指定したTensorに値をセットする
Parameters:
  • tensor_index (int) –

    TENSOR’s index (acquired with get_input_details)
    Tensorのindex(get_input_detailsで取得する)

  • value (np.ndarray) –

    The value to set
    セットする値