NeuralNetworks

Summary

Enumerations

Anonymous Enum 53{
  ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES = 128
}
enum
For ANeuralNetworksModel_setOperandValue, values with a length smaller or equal to this will be immediately copied into the model.
Anonymous Enum 54{
  ANEURALNETWORKS_BYTE_SIZE_OF_CACHE_TOKEN = 32
}
enum
For ANeuralNetworksCompilation_setCaching, specify the size of the cache token required from the application.
DeviceTypeCode{
  ANEURALNETWORKS_DEVICE_UNKNOWN = 0,
  ANEURALNETWORKS_DEVICE_OTHER = 1,
  ANEURALNETWORKS_DEVICE_CPU = 2,
  ANEURALNETWORKS_DEVICE_GPU = 3,
  ANEURALNETWORKS_DEVICE_ACCELERATOR = 4
}
enum
Device types.
DurationCode{
  ANEURALNETWORKS_DURATION_ON_HARDWARE = 0,
  ANEURALNETWORKS_DURATION_IN_DRIVER = 1,
  ANEURALNETWORKS_FENCED_DURATION_ON_HARDWARE = 2,
  ANEURALNETWORKS_FENCED_DURATION_IN_DRIVER = 3
}
enum
Different duration measurements.
FeatureLevelCode{
  ANEURALNETWORKS_FEATURE_LEVEL_1 = 27,
  ANEURALNETWORKS_FEATURE_LEVEL_2 = 28,
  ANEURALNETWORKS_FEATURE_LEVEL_3 = 29,
  ANEURALNETWORKS_FEATURE_LEVEL_4 = 30,
  ANEURALNETWORKS_FEATURE_LEVEL_5 = 31,
  ANEURALNETWORKS_FEATURE_LEVEL_6 = 1000006,
  ANEURALNETWORKS_FEATURE_LEVEL_7 = 1000007,
  ANEURALNETWORKS_FEATURE_LEVEL_8 = 1000008
}
enum
NNAPI feature levels.
FuseCode{
  ANEURALNETWORKS_FUSED_NONE = 0,
  ANEURALNETWORKS_FUSED_RELU = 1,
  ANEURALNETWORKS_FUSED_RELU1 = 2,
  ANEURALNETWORKS_FUSED_RELU6 = 3
}
enum
Fused activation function types.
OperandCode{
  ANEURALNETWORKS_FLOAT32 = 0,
  ANEURALNETWORKS_INT32 = 1,
  ANEURALNETWORKS_UINT32 = 2,
  ANEURALNETWORKS_TENSOR_FLOAT32 = 3,
  ANEURALNETWORKS_TENSOR_INT32 = 4,
  ANEURALNETWORKS_TENSOR_QUANT8_ASYMM = 5,
  ANEURALNETWORKS_BOOL = 6,
  ANEURALNETWORKS_TENSOR_QUANT16_SYMM = 7,
  ANEURALNETWORKS_TENSOR_FLOAT16 = 8,
  ANEURALNETWORKS_TENSOR_BOOL8 = 9,
  ANEURALNETWORKS_FLOAT16 = 10,
  ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL = 11,
  ANEURALNETWORKS_TENSOR_QUANT16_ASYMM = 12,
  ANEURALNETWORKS_TENSOR_QUANT8_SYMM = 13,
  ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED = 14,
  ANEURALNETWORKS_MODEL = 15
}
enum
Operand types.
OperationCode{
  ANEURALNETWORKS_ADD = 0,
  ANEURALNETWORKS_AVERAGE_POOL_2D = 1,
  ANEURALNETWORKS_CONCATENATION = 2,
  ANEURALNETWORKS_CONV_2D = 3,
  ANEURALNETWORKS_DEPTHWISE_CONV_2D = 4,
  ANEURALNETWORKS_DEPTH_TO_SPACE = 5,
  ANEURALNETWORKS_DEQUANTIZE = 6,
  ANEURALNETWORKS_EMBEDDING_LOOKUP = 7,
  ANEURALNETWORKS_FLOOR = 8,
  ANEURALNETWORKS_FULLY_CONNECTED = 9,
  ANEURALNETWORKS_HASHTABLE_LOOKUP = 10,
  ANEURALNETWORKS_L2_NORMALIZATION = 11,
  ANEURALNETWORKS_L2_POOL_2D = 12,
  ANEURALNETWORKS_LOCAL_RESPONSE_NORMALIZATION = 13,
  ANEURALNETWORKS_LOGISTIC = 14,
  ANEURALNETWORKS_LSH_PROJECTION = 15,
  ANEURALNETWORKS_LSTM = 16,
  ANEURALNETWORKS_MAX_POOL_2D = 17,
  ANEURALNETWORKS_MUL = 18,
  ANEURALNETWORKS_RELU = 19,
  ANEURALNETWORKS_RELU1 = 20,
  ANEURALNETWORKS_RELU6 = 21,
  ANEURALNETWORKS_RESHAPE = 22,
  ANEURALNETWORKS_RESIZE_BILINEAR = 23,
  ANEURALNETWORKS_RNN = 24,
  ANEURALNETWORKS_SOFTMAX = 25,
  ANEURALNETWORKS_SPACE_TO_DEPTH = 26,
  ANEURALNETWORKS_SVDF = 27,
  ANEURALNETWORKS_TANH = 28,
  ANEURALNETWORKS_BATCH_TO_SPACE_ND = 29,
  ANEURALNETWORKS_DIV = 30,
  ANEURALNETWORKS_MEAN = 31,
  ANEURALNETWORKS_PAD = 32,
  ANEURALNETWORKS_SPACE_TO_BATCH_ND = 33,
  ANEURALNETWORKS_SQUEEZE = 34,
  ANEURALNETWORKS_STRIDED_SLICE = 35,
  ANEURALNETWORKS_SUB = 36,
  ANEURALNETWORKS_TRANSPOSE = 37,
  ANEURALNETWORKS_ABS = 38,
  ANEURALNETWORKS_ARGMAX = 39,
  ANEURALNETWORKS_ARGMIN = 40,
  ANEURALNETWORKS_AXIS_ALIGNED_BBOX_TRANSFORM = 41,
  ANEURALNETWORKS_BIDIRECTIONAL_SEQUENCE_LSTM = 42,
  ANEURALNETWORKS_BIDIRECTIONAL_SEQUENCE_RNN = 43,
  ANEURALNETWORKS_BOX_WITH_NMS_LIMIT = 44,
  ANEURALNETWORKS_CAST = 45,
  ANEURALNETWORKS_CHANNEL_SHUFFLE = 46,
  ANEURALNETWORKS_DETECTION_POSTPROCESSING = 47,
  ANEURALNETWORKS_EQUAL = 48,
  ANEURALNETWORKS_EXP = 49,
  ANEURALNETWORKS_EXPAND_DIMS = 50,
  ANEURALNETWORKS_GATHER = 51,
  ANEURALNETWORKS_GENERATE_PROPOSALS = 52,
  ANEURALNETWORKS_GREATER = 53,
  ANEURALNETWORKS_GREATER_EQUAL = 54,
  ANEURALNETWORKS_GROUPED_CONV_2D = 55,
  ANEURALNETWORKS_HEATMAP_MAX_KEYPOINT = 56,
  ANEURALNETWORKS_INSTANCE_NORMALIZATION = 57,
  ANEURALNETWORKS_LESS = 58,
  ANEURALNETWORKS_LESS_EQUAL = 59,
  ANEURALNETWORKS_LOG = 60,
  ANEURALNETWORKS_LOGICAL_AND = 61,
  ANEURALNETWORKS_LOGICAL_NOT = 62,
  ANEURALNETWORKS_LOGICAL_OR = 63,
  ANEURALNETWORKS_LOG_SOFTMAX = 64,
  ANEURALNETWORKS_MAXIMUM = 65,
  ANEURALNETWORKS_MINIMUM = 66,
  ANEURALNETWORKS_NEG = 67,
  ANEURALNETWORKS_NOT_EQUAL = 68,
  ANEURALNETWORKS_PAD_V2 = 69,
  ANEURALNETWORKS_POW = 70,
  ANEURALNETWORKS_PRELU = 71,
  ANEURALNETWORKS_QUANTIZE = 72,
  ANEURALNETWORKS_QUANTIZED_16BIT_LSTM = 73,
  ANEURALNETWORKS_RANDOM_MULTINOMIAL = 74,
  ANEURALNETWORKS_REDUCE_ALL = 75,
  ANEURALNETWORKS_REDUCE_ANY = 76,
  ANEURALNETWORKS_REDUCE_MAX = 77,
  ANEURALNETWORKS_REDUCE_MIN = 78,
  ANEURALNETWORKS_REDUCE_PROD = 79,
  ANEURALNETWORKS_REDUCE_SUM = 80,
  ANEURALNETWORKS_ROI_ALIGN = 81,
  ANEURALNETWORKS_ROI_POOLING = 82,
  ANEURALNETWORKS_RSQRT = 83,
  ANEURALNETWORKS_SELECT = 84,
  ANEURALNETWORKS_SIN = 85,
  ANEURALNETWORKS_SLICE = 86,
  ANEURALNETWORKS_SPLIT = 87,
  ANEURALNETWORKS_SQRT = 88,
  ANEURALNETWORKS_TILE = 89,
  ANEURALNETWORKS_TOPK_V2 = 90,
  ANEURALNETWORKS_TRANSPOSE_CONV_2D = 91,
  ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM = 92,
  ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_RNN = 93,
  ANEURALNETWORKS_RESIZE_NEAREST_NEIGHBOR = 94,
  ANEURALNETWORKS_QUANTIZED_LSTM = 95,
  ANEURALNETWORKS_IF = 96,
  ANEURALNETWORKS_WHILE = 97,
  ANEURALNETWORKS_ELU = 98,
  ANEURALNETWORKS_HARD_SWISH = 99,
  ANEURALNETWORKS_FILL = 100,
  ANEURALNETWORKS_RANK = 101,
  ANEURALNETWORKS_BATCH_MATMUL = 102,
  ANEURALNETWORKS_PACK = 103,
  ANEURALNETWORKS_MIRROR_PAD = 104,
  ANEURALNETWORKS_REVERSE = 105
}
enum
Operation types.
PaddingCode{
  ANEURALNETWORKS_PADDING_SAME = 1,
  ANEURALNETWORKS_PADDING_VALID = 2
}
enum
Implicit padding algorithms.
PreferenceCode{
  ANEURALNETWORKS_PREFER_LOW_POWER = 0,
  ANEURALNETWORKS_PREFER_FAST_SINGLE_ANSWER = 1,
  ANEURALNETWORKS_PREFER_SUSTAINED_SPEED = 2
}
enum
Execution preferences.
PriorityCode{
  ANEURALNETWORKS_PRIORITY_LOW = 90,
  ANEURALNETWORKS_PRIORITY_MEDIUM = 100,
  ANEURALNETWORKS_PRIORITY_HIGH = 110,
  ANEURALNETWORKS_PRIORITY_DEFAULT = ANEURALNETWORKS_PRIORITY_MEDIUM
}
enum
Relative execution priority.
ResultCode{
  ANEURALNETWORKS_NO_ERROR = 0,
  ANEURALNETWORKS_OUT_OF_MEMORY = 1,
  ANEURALNETWORKS_INCOMPLETE = 2,
  ANEURALNETWORKS_UNEXPECTED_NULL = 3,
  ANEURALNETWORKS_BAD_DATA = 4,
  ANEURALNETWORKS_OP_FAILED = 5,
  ANEURALNETWORKS_BAD_STATE = 6,
  ANEURALNETWORKS_UNMAPPABLE = 7,
  ANEURALNETWORKS_OUTPUT_INSUFFICIENT_SIZE = 8,
  ANEURALNETWORKS_UNAVAILABLE_DEVICE = 9,
  ANEURALNETWORKS_MISSED_DEADLINE_TRANSIENT = 10,
  ANEURALNETWORKS_MISSED_DEADLINE_PERSISTENT = 11,
  ANEURALNETWORKS_RESOURCE_EXHAUSTED_TRANSIENT = 12,
  ANEURALNETWORKS_RESOURCE_EXHAUSTED_PERSISTENT = 13,
  ANEURALNETWORKS_DEAD_OBJECT = 14
}
enum
Result codes.

Typedefs

ANeuralNetworksBurst typedef
ANeuralNetworksBurst is an opaque type that can be used to reduce the latency of a rapid sequence of executions.
ANeuralNetworksCompilation typedef
ANeuralNetworksCompilation is an opaque type that can be used to compile a machine learning model.
ANeuralNetworksDevice typedef
ANeuralNetworksDevice is an opaque type that represents a device.
ANeuralNetworksEvent typedef
ANeuralNetworksEvent is an opaque type that represents an event that will be signaled once an execution completes.
ANeuralNetworksExecution typedef
ANeuralNetworksExecution is an opaque type that can be used to apply a machine learning model to a set of inputs.
ANeuralNetworksMemory typedef
ANeuralNetworksMemory is an opaque type that represents memory.
ANeuralNetworksMemoryDesc typedef
ANeuralNetworksMemoryDesc is an opaque type that represents a memory descriptor.
ANeuralNetworksModel typedef
ANeuralNetworksModel is an opaque type that contains a description of the mathematical operations that constitute the model.
ANeuralNetworksOperandType typedef
ANeuralNetworksOperandType describes the type of an operand.
ANeuralNetworksOperationType typedef
int32_t
Aliasing to OperationCode, used in function ANeuralNetworksModel_addOperation.
ANeuralNetworksSymmPerChannelQuantParams typedef
Parameters for ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL operand.

Functions

ANeuralNetworksBurst_create(ANeuralNetworksCompilation *compilation, ANeuralNetworksBurst **burst)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksBurst to apply the given compilation.
ANeuralNetworksBurst_free(ANeuralNetworksBurst *burst)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroys the burst object.
ANeuralNetworksCompilation_create(ANeuralNetworksModel *model, ANeuralNetworksCompilation **compilation)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksCompilation to compile the given model.
ANeuralNetworksCompilation_createForDevices(ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices, uint32_t numDevices, ANeuralNetworksCompilation **compilation)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksCompilation to compile the given model for a specified set of devices.
ANeuralNetworksCompilation_finish(ANeuralNetworksCompilation *compilation)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Indicate that we have finished modifying a compilation.
ANeuralNetworksCompilation_free(ANeuralNetworksCompilation *compilation)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroy a compilation.
ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput(const ANeuralNetworksCompilation *compilation, uint32_t index, uint32_t *alignment)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the preferred buffer and memory alignment of an input to an execution created from a particular compilation.
ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput(const ANeuralNetworksCompilation *compilation, uint32_t index, uint32_t *alignment)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the preferred buffer and memory alignment of an output to an execution created from a particular compilation.
ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput(const ANeuralNetworksCompilation *compilation, uint32_t index, uint32_t *padding)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the preferred buffer and memory end padding of an input to an execution created from a particular compilation.
ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput(const ANeuralNetworksCompilation *compilation, uint32_t index, uint32_t *padding)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the preferred memory end padding of an output to an execution created from a particular compilation.
ANeuralNetworksCompilation_setCaching(ANeuralNetworksCompilation *compilation, const char *cacheDir, const uint8_t *token)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets the compilation caching signature and the cache directory.
ANeuralNetworksCompilation_setPreference(ANeuralNetworksCompilation *compilation, int32_t preference)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets the execution preference.
ANeuralNetworksCompilation_setPriority(ANeuralNetworksCompilation *compilation, int priority)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Set the execution priority.
ANeuralNetworksCompilation_setTimeout(ANeuralNetworksCompilation *compilation, uint64_t duration)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Set the maximum expected duration for compiling the model.
ANeuralNetworksDevice_getFeatureLevel(const ANeuralNetworksDevice *device, int64_t *featureLevel)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the NNAPI feature level of the specified NNAPI device.
ANeuralNetworksDevice_getName(const ANeuralNetworksDevice *device, const char **name)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the name of the specified device.
ANeuralNetworksDevice_getType(const ANeuralNetworksDevice *device, int32_t *type)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the type of a given device.
ANeuralNetworksDevice_getVersion(const ANeuralNetworksDevice *device, const char **version)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the version of the driver implementation of the specified device.
ANeuralNetworksDevice_wait(const ANeuralNetworksDevice *device)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Wait until the device is in a live state.
ANeuralNetworksEvent_createFromSyncFenceFd(int sync_fence_fd, ANeuralNetworksEvent **event)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksEvent from a sync_fence file descriptor.
ANeuralNetworksEvent_free(ANeuralNetworksEvent *event)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroys the event.
ANeuralNetworksEvent_getSyncFenceFd(const ANeuralNetworksEvent *event, int *sync_fence_fd)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get sync_fence file descriptor from the event.
ANeuralNetworksEvent_wait(ANeuralNetworksEvent *event)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Waits until the execution completes.
ANeuralNetworksExecution_burstCompute(ANeuralNetworksExecution *execution, ANeuralNetworksBurst *burst)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Schedule synchronous evaluation of the execution on a burst object.
ANeuralNetworksExecution_compute(ANeuralNetworksExecution *execution)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Schedule synchronous evaluation of the execution.
ANeuralNetworksExecution_create(ANeuralNetworksCompilation *compilation, ANeuralNetworksExecution **execution)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksExecution to apply the given compilation.
ANeuralNetworksExecution_enableInputAndOutputPadding(ANeuralNetworksExecution *execution, bool enable)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specifies whether the ANeuralNetworksExecution is able to accept padded input and output buffers and memory objects.
ANeuralNetworksExecution_free(ANeuralNetworksExecution *execution)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroy an execution.
ANeuralNetworksExecution_getDuration(const ANeuralNetworksExecution *execution, int32_t durationCode, uint64_t *duration)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the time spent in the latest computation evaluated on the specified ANeuralNetworksExecution, in nanoseconds.
ANeuralNetworksExecution_getOutputOperandDimensions(ANeuralNetworksExecution *execution, int32_t index, uint32_t *dimensions)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the dimensional information of the specified output operand of the model of the latest computation evaluated on ANeuralNetworksExecution.
ANeuralNetworksExecution_getOutputOperandRank(ANeuralNetworksExecution *execution, int32_t index, uint32_t *rank)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the dimensional information of the specified output operand of the model of the latest computation evaluated on ANeuralNetworksExecution.
ANeuralNetworksExecution_setInput(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const void *buffer, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Associate a user buffer with an input of the model of the ANeuralNetworksExecution.
ANeuralNetworksExecution_setInputFromMemory(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Associate a region of a memory object with an input of the model of the ANeuralNetworksExecution.
ANeuralNetworksExecution_setLoopTimeout(ANeuralNetworksExecution *execution, uint64_t duration)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Set the maximum duration of WHILE loops in the specified execution.
ANeuralNetworksExecution_setMeasureTiming(ANeuralNetworksExecution *execution, bool measure)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specifies whether duration of the ANeuralNetworksExecution is to be measured.
ANeuralNetworksExecution_setOutput(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, void *buffer, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Associate a user buffer with an output of the model of the ANeuralNetworksExecution.
ANeuralNetworksExecution_setOutputFromMemory(ANeuralNetworksExecution *execution, int32_t index, const ANeuralNetworksOperandType *type, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Associate a region of a memory object with an output of the model of the ANeuralNetworksExecution.
ANeuralNetworksExecution_setReusable(ANeuralNetworksExecution *execution, bool reusable)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specifies whether the ANeuralNetworksExecution can be reused for multiple computations.
ANeuralNetworksExecution_setTimeout(ANeuralNetworksExecution *execution, uint64_t duration)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Set the maximum expected duration of the specified execution.
ANeuralNetworksExecution_startCompute(ANeuralNetworksExecution *execution, ANeuralNetworksEvent **event)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Schedule asynchronous evaluation of the execution.
ANeuralNetworksExecution_startComputeWithDependencies(ANeuralNetworksExecution *execution, const ANeuralNetworksEvent *const *dependencies, uint32_t num_dependencies, uint64_t duration, ANeuralNetworksEvent **event)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Schedule asynchronous evaluation of the execution with dependencies.
ANeuralNetworksMemoryDesc_addInputRole(ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, uint32_t index, float frequency)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specify that a memory object will be playing the role of an input to an execution created from a particular compilation.
ANeuralNetworksMemoryDesc_addOutputRole(ANeuralNetworksMemoryDesc *desc, const ANeuralNetworksCompilation *compilation, uint32_t index, float frequency)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specify that a memory object will be playing the role of an output to an execution created from a particular compilation.
ANeuralNetworksMemoryDesc_create(ANeuralNetworksMemoryDesc **desc)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create a ANeuralNetworksMemoryDesc with no properties.
ANeuralNetworksMemoryDesc_finish(ANeuralNetworksMemoryDesc *desc)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Indicate that we have finished modifying a memory descriptor.
ANeuralNetworksMemoryDesc_free(ANeuralNetworksMemoryDesc *desc)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroy a memory descriptor.
ANeuralNetworksMemoryDesc_setDimensions(ANeuralNetworksMemoryDesc *desc, uint32_t rank, const uint32_t *dimensions)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Set the dimensional information of the memory descriptor.
ANeuralNetworksMemory_copy(const ANeuralNetworksMemory *src, const ANeuralNetworksMemory *dst)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Copies data from one memory object to another.
ANeuralNetworksMemory_createFromAHardwareBuffer(const AHardwareBuffer *ahwb, ANeuralNetworksMemory **memory)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Creates a shared memory object from an AHardwareBuffer handle.
ANeuralNetworksMemory_createFromDesc(const ANeuralNetworksMemoryDesc *desc, ANeuralNetworksMemory **memory)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Creates a memory object from a memory descriptor.
ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset, ANeuralNetworksMemory **memory)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Creates a shared memory object from a file descriptor.
ANeuralNetworksMemory_free(ANeuralNetworksMemory *memory)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Delete a memory object.
ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model, const ANeuralNetworksOperandType *type)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Add an operand to a model.
ANeuralNetworksModel_addOperation(ANeuralNetworksModel *model, ANeuralNetworksOperationType type, uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Add an operation to a model.
ANeuralNetworksModel_create(ANeuralNetworksModel **model)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Create an empty ANeuralNetworksModel.
ANeuralNetworksModel_finish(ANeuralNetworksModel *model)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Indicate that we have finished modifying a model.
ANeuralNetworksModel_free(ANeuralNetworksModel *model)
void
Deprecated. NNAPI is deprecated. See this webpage for more details.
Destroy a model.
ANeuralNetworksModel_getSupportedOperationsForDevices(const ANeuralNetworksModel *model, const ANeuralNetworksDevice *const *devices, uint32_t numDevices, bool *supportedOps)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the supported operations for a specified set of devices.
ANeuralNetworksModel_identifyInputsAndOutputs(ANeuralNetworksModel *model, uint32_t inputCount, const uint32_t *inputs, uint32_t outputCount, const uint32_t *outputs)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specifies which operands will be the model's inputs and outputs.
ANeuralNetworksModel_relaxComputationFloat32toFloat16(ANeuralNetworksModel *model, bool allow)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Specifies whether ANEURALNETWORKS_TENSOR_FLOAT32 is allowed to be calculated with range and/or precision as low as that of the IEEE 754 16-bit floating-point format.
ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksSymmPerChannelQuantParams *channelQuant)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets an operand's per channel quantization parameters.
ANeuralNetworksModel_setOperandValue(ANeuralNetworksModel *model, int32_t index, const void *buffer, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets an operand to a constant value.
ANeuralNetworksModel_setOperandValueFromMemory(ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksMemory *memory, size_t offset, size_t length)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets an operand to a value stored in a memory object.
ANeuralNetworksModel_setOperandValueFromModel(ANeuralNetworksModel *model, int32_t index, const ANeuralNetworksModel *value)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Sets an operand to a value that is a reference to another NNAPI model.
ANeuralNetworks_getDefaultLoopTimeout()
uint64_t
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the default timeout value for WHILE loops.
ANeuralNetworks_getDevice(uint32_t devIndex, ANeuralNetworksDevice **device)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the representation of the specified device.
ANeuralNetworks_getDeviceCount(uint32_t *numDevices)
int
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the number of available devices.
ANeuralNetworks_getMaximumLoopTimeout()
uint64_t
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the maximum timeout value for WHILE loops.
ANeuralNetworks_getRuntimeFeatureLevel()
int64_t
Deprecated. NNAPI is deprecated. See this webpage for more details.
Get the NNAPI runtime feature level.

Structs

ANeuralNetworksOperandType

ANeuralNetworksOperandType describes the type of an operand.

ANeuralNetworksSymmPerChannelQuantParams

Parameters for ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL operand.

Enumerations

Anonymous Enum 53

Declared in android/NeuralNetworksTypes.h
 Anonymous Enum 53

For ANeuralNetworksModel_setOperandValue, values with a length smaller or equal to this will be immediately copied into the model.

The size is in bytes.

Available since NNAPI feature level 1.

Properties
ANEURALNETWORKS_MAX_SIZE_OF_IMMEDIATELY_COPIED_VALUES

Anonymous Enum 54

Declared in android/NeuralNetworksTypes.h
 Anonymous Enum 54

For ANeuralNetworksCompilation_setCaching, specify the size of the cache token required from the application.

The size is in bytes.

Available since NNAPI feature level 3.

Properties
ANEURALNETWORKS_BYTE_SIZE_OF_CACHE_TOKEN

DeviceTypeCode

Declared in android/NeuralNetworksTypes.h
 DeviceTypeCode

Device types.

The type of NNAPI device.

Properties
ANEURALNETWORKS_DEVICE_ACCELERATOR

Dedicated accelerator for Machine Learning workloads.

ANEURALNETWORKS_DEVICE_CPU

The device runs NNAPI models on single or multi-core CPU.

ANEURALNETWORKS_DEVICE_GPU

The device can run NNAPI models and also accelerate graphics APIs such as OpenGL ES and Vulkan.

ANEURALNETWORKS_DEVICE_OTHER

The device does not fall into any category below.

ANEURALNETWORKS_DEVICE_UNKNOWN

The device type cannot be provided.

DurationCode

Declared in android/NeuralNetworksTypes.h
 DurationCode

Different duration measurements.

Durations are measured in nanoseconds.

Available since NNAPI feature level 3.

Properties
ANEURALNETWORKS_DURATION_IN_DRIVER
ANEURALNETWORKS_DURATION_ON_HARDWARE
ANEURALNETWORKS_FENCED_DURATION_IN_DRIVER
ANEURALNETWORKS_FENCED_DURATION_ON_HARDWARE

FeatureLevelCode

Declared in android/NeuralNetworksTypes.h
 FeatureLevelCode

NNAPI feature levels.

Each update of the NNAPI specification yields a new NNAPI feature level enum value. NNAPI feature level corrseponds to an NNAPI specification version that a driver and/or the NNAPI runtime can implement.

A feature level up to and including "FEATURE_LEVEL_5" maps directly to the Android API level that introduced the corresponding update of the NNAPI specification. Feature levels after Android API level 31 have no association with API level because the NNAPI specification can be updated between Android API releases. Outputs of ANeuralNetworksDevice_getFeatureLevel and ANeuralNetworks_getRuntimeFeatureLevel must be compared against these enum values instead of the Android API level.

Properties
ANEURALNETWORKS_FEATURE_LEVEL_1

NNAPI specification available in Android O-MR1, Android NNAPI feature level 1.

ANEURALNETWORKS_FEATURE_LEVEL_2

NNAPI specification available in Android P, Android NNAPI feature level 2.

ANEURALNETWORKS_FEATURE_LEVEL_3

NNAPI specification available in Android Q, Android NNAPI feature level 3.

ANEURALNETWORKS_FEATURE_LEVEL_4

NNAPI specification available in Android R, Android NNAPI feature level 4.

ANEURALNETWORKS_FEATURE_LEVEL_5

NNAPI specification available in Android S, Android NNAPI feature level 5.

After Android S, the NNAPI specification can be updated between Android API releases.

ANEURALNETWORKS_FEATURE_LEVEL_6

Android NNAPI feature level 6.

ANEURALNETWORKS_FEATURE_LEVEL_7

Android NNAPI feature level 7.

ANEURALNETWORKS_FEATURE_LEVEL_8

Android NNAPI feature level 8.

FuseCode

Declared in android/NeuralNetworksTypes.h
 FuseCode

Fused activation function types.

Available since NNAPI feature level 1.

Properties
ANEURALNETWORKS_FUSED_NONE

NO fused activation function.

ANEURALNETWORKS_FUSED_RELU

Fused ReLU activation function.

ANEURALNETWORKS_FUSED_RELU1

Fused ReLU1 activation function.

ANEURALNETWORKS_FUSED_RELU6

Fused ReLU6 activation function.

OperandCode

Declared in android/NeuralNetworksTypes.h
 OperandCode

Operand types.

The type of an operand in a model.

Types prefaced with ANEURALNETWORKS_TENSOR_* must be used for tensor data (i.e., tensors with at least one dimension). Types not prefaced by ANEURALNETWORKS_TENSOR_* represent scalar values and must have no dimensions.

Although we define many types, most operators accept just a few types. Most used are ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, and ANEURALNETWORKS_INT32.

Available since NNAPI feature level 1.

Properties
ANEURALNETWORKS_BOOL

An 8 bit boolean scalar value.

Values of this operand type are either true or false. A zero value represents false; any other value represents true.

Available since NNAPI feature level 3.

ANEURALNETWORKS_FLOAT16

An IEEE 754 16 bit floating point scalar value.

Available since NNAPI feature level 3.

ANEURALNETWORKS_FLOAT32

A 32 bit floating point scalar value.

ANEURALNETWORKS_INT32

A signed 32 bit integer scalar value.

ANEURALNETWORKS_MODEL

A reference to a model.

ANeuralNetworksModel_setOperandValueFromModel must be used to set the value for an Operand of this type.

Available since NNAPI feature level 4.

ANEURALNETWORKS_TENSOR_BOOL8

A tensor of 8 bit boolean values.

Values of this operand type are either true or false. A zero value represents false; any other value represents true.

Available since NNAPI feature level 3.

ANEURALNETWORKS_TENSOR_FLOAT16

A tensor of IEEE 754 16 bit floating point values.

Available since NNAPI feature level 3.

ANEURALNETWORKS_TENSOR_FLOAT32

A tensor of 32 bit floating point values.

ANEURALNETWORKS_TENSOR_INT32

A tensor of 32 bit integer values.

ANEURALNETWORKS_TENSOR_QUANT16_ASYMM

A tensor of 16 bit unsigned integers that represent real numbers.

Attached to this tensor are two numbers that can be used to convert the 16 bit integer to the real value and vice versa. These two numbers are:

  • scale: a 32 bit floating point value greater than zero.
  • zeroPoint: a 32 bit integer, in range [0, 65535].

The formula is: real_value = (integer_value - zeroPoint) * scale.

Available since NNAPI feature level 3.

ANEURALNETWORKS_TENSOR_QUANT16_SYMM

A tensor of 16 bit signed integers that represent real numbers.

Attached to this tensor is a number representing real value scale that is used to convert the 16 bit number to a real value in the following way: realValue = integerValue * scale.

scale is a 32 bit floating point with value greater than zero.

Available since NNAPI feature level 3.

ANEURALNETWORKS_TENSOR_QUANT8_ASYMM

A tensor of 8 bit unsigned integers that represent real numbers.

Attached to this tensor are two numbers that can be used to convert the 8 bit integer to the real value and vice versa. These two numbers are:

  • scale: a 32 bit floating point value greater than zero.
  • zeroPoint: a 32 bit integer, in range [0, 255].

The formula is: real_value = (integer_value - zeroPoint) * scale.

ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED

A tensor of 8 bit signed integers that represent real numbers.

Attached to this tensor are two numbers that can be used to convert the 8 bit integer to the real value and vice versa. These two numbers are:

  • scale: a 32 bit floating point value greater than zero.
  • zeroPoint: a 32 bit integer, in range [-128, 127].

The formula is: real_value = (integer_value - zeroPoint) * scale.

Available since NNAPI feature level 4.

ANEURALNETWORKS_TENSOR_QUANT8_SYMM

A tensor of 8 bit signed integers that represent real numbers.

Attached to this tensor is a number representing real value scale that is used to convert the 8 bit number to a real value in the following way: realValue = integerValue * scale.

scale is a 32 bit floating point with value greater than zero.

Available since NNAPI feature level 3.

ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL

A tensor of 8 bit signed integers that represent real numbers.

This tensor is associated with additional fields that can be used to convert the 8 bit signed integer to the real value and vice versa. These fields are:

  • channelDim: a 32 bit unsigned integer indicating channel dimension.
  • scales: an array of positive 32 bit floating point values. The size of the scales array must be equal to dimensions[channelDim].

ANeuralNetworksModel_setOperandSymmPerChannelQuantParams must be used to set the parameters for an Operand of this type.

The channel dimension of this tensor must not be unknown (dimensions[channelDim] != 0).

The formula is: realValue[..., C, ...] = integerValue[..., C, ...] * scales[C] where C is an index in the Channel dimension.

Available since NNAPI feature level 3.

ANEURALNETWORKS_UINT32

An unsigned 32 bit integer scalar value.

OperationCode

Declared in android/NeuralNetworksTypes.h
 OperationCode

Operation types.

The type of an operation in a model.

Available since NNAPI feature level 1.

Properties
ANEURALNETWORKS_ABS

Computes the absolute value of a tensor, element-wise.

Supported tensor OperandCode:

Supported tensor rank: from 1.

Inputs:

  • 0: A tensor.

Outputs:

  • 0: The output tensor of same shape as input0.

Available since NNAPI feature level 3.

ANEURALNETWORKS_ADD

Adds two tensors, element-wise.

Takes two input tensors of identical OperandCode and compatible dimensions. The output is the sum of both input tensors, optionally modified by an activation function.

Two dimensions are compatible when:

  1. they are equal, or
  2. one of them is 1

The size of the output is the maximum size along each dimension of the input operands. It starts with the trailing dimensions, and works its way forward.

Example:

input1.dimension = {4, 1, 2}
input2.dimension = {5, 4, 3, 1}
output.dimension = {5, 4, 3, 2}

Since NNAPI feature level 3, generic zero-sized input tensor is supported. Zero dimension is only compatible with 0 or 1. The size of the output dimension is zero if either of corresponding input dimension is zero.

Supported tensor OperandCode:

Supported tensor rank: up to 4

Inputs:

Outputs:

Available since NNAPI feature level 1.

ANEURALNETWORKS_ARGMAX

Returns the index of the largest element along an axis.

Supported tensor OperandCode:

Supported tensor rank: from 1

Inputs:

  • 0: An n-D tensor specifying the input. Must be non-empty.
  • 1: An ANEURALNETWORKS_INT32 scalar specifying the axis to reduce across. Negative index is used to specify axis from the end (e.g. -1 for the last axis). Must be in the range [-n, n).

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_ARGMIN

Returns the index of the smallest element along an axis.

Supported tensor OperandCode:

Supported tensor rank: from 1

Inputs:

  • 0: An n-D tensor specifying the input. Must be non-empty.
  • 1: An ANEURALNETWORKS_INT32 scalar specifying the axis to reduce across. Negative index is used to specify axis from the end (e.g. -1 for the last axis). Must be in the range [-n, n).

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_AVERAGE_POOL_2D

Performs a 2-D average pooling operation.

The output dimensions are functions of the filter dimensions, stride, and padding.

The values in the output tensor are computed as:

output[b, i, j, channel] =
    sum_{di, dj}(
        input[b, strides[1] * i + di, strides[2] * j + dj, channel]
    ) / sum(1)

Supported tensor OperandCode:

Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. With the default data layout NHWC, the data is stored in the order of: [batch, height, width, channels]. Alternatively, the data layout could be NCHW, the data storage order of: [batch, channels, height, width]. NCHW is supported since NNAPI feature level 3.

Both explicit padding and implicit padding are supported.

Inputs (explicit padding):

  • 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input. Since NNAPI feature level 3, zero batches is supported for this tensor.
  • 1: An ANEURALNETWORKS_INT32 scalar, specifying the padding on the left, in the ‘width’ dimension.
  • 2: An ANEURALNETWORKS_INT32 scalar, specifying the padding on the right, in the ‘width’ dimension.
  • 3: An ANEURALNETWORKS_INT32 scalar, specifying the padding on the top, in the ‘height’ dimension.
  • 4: An ANEURALNETWORKS_INT32 scalar, specifying the padding on the bottom, in the ‘height’ dimension.
  • 5: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘width’ dimension.
  • 6: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘height’ dimension.
  • 7: An ANEURALNETWORKS_INT32 scalar, specifying the filter width.
  • 8: An ANEURALNETWORKS_INT32 scalar, specifying the filter height.
  • 9: An ANEURALNETWORKS_INT32 scalar, and has to be one of the FuseCode values. Specifies the activation to invoke on the result.
  • 10: An optional ANEURALNETWORKS_BOOL scalar, default to false. Set to true to specify NCHW data layout for input0 and output0. Available since NNAPI feature level 3.

Inputs (implicit padding):

  • 0: A 4-D tensor, of shape [batches, height, width, depth], specifying the input. Since NNAPI feature level 3, zero batches is supported for this tensor.
  • 1: An ANEURALNETWORKS_INT32 scalar, specifying the implicit padding scheme, has to be one of the PaddingCode values.
  • 2: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘width’ dimension.
  • 3: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘height’ dimension.
  • 4: An ANEURALNETWORKS_INT32 scalar, specifying the filter width.
  • 5: An ANEURALNETWORKS_INT32 scalar, specifying the filter height.
  • 6: An ANEURALNETWORKS_INT32 scalar, and has to be one of the FuseCode values. Specifies the activation to invoke on the result.
  • 7: An optional ANEURALNETWORKS_BOOL scalar, default to false. Set to true to specify NCHW data layout for input0 and output0. Available since NNAPI feature level 3.

Outputs:

Available since NNAPI feature level 1.

ANEURALNETWORKS_AXIS_ALIGNED_BBOX_TRANSFORM

Transform axis-aligned bounding box proposals using bounding box deltas.

Given the positions of bounding box proposals and the corresponding bounding box deltas for each class, return the refined bounding box regions. The resulting bounding boxes are cliped against the edges of the image.

Supported tensor OperandCode:

Inputs:

  • 0: A 2-D Tensor of shape [num_rois, 4], specifying the locations of the bounding box proposals, each line with format [x1, y1, x2, y2]. For tensor of type ANEURALNETWORKS_TENSOR_QUANT16_ASYMM, the zeroPoint must be 0 and the scale must be 0.125. Zero num_rois is supported for this tensor.
  • 1: A 2-D Tensor of shape [num_rois, num_classes * 4], specifying the bounding box delta for each region of interest and each class. The bounding box deltas are organized in the following order [dx, dy, dw, dh], where dx and dy is the relative correction factor for the center position of the bounding box with respect to the width and height, dw and dh is the log-scale relative correction factor for the width and height. For input0 of type ANEURALNETWORKS_TENSOR_QUANT16_ASYMM, this tensor should be of ANEURALNETWORKS_TENSOR_QUANT8_ASYMM or ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED. Zero num_rois is supported for this tensor.
  • 2: An 1-D ANEURALNETWORKS_TENSOR_INT32 tensor, of shape [num_rois], specifying the batch index of each box. Boxes with the same batch index are grouped together. Zero num_rois is supported for this tensor.
  • 3: A 2-D Tensor of shape [batches, 2], specifying the information of each image in the batch, each line with format [image_height, image_width].

Outputs:

  • 0: A tensor of the same OperandCode as input0, with shape [num_rois, num_classes * 4], specifying the coordinates of each output bounding box for each class, with format [x1, y1, x2, y2]. For type of ANEURALNETWORKS_TENSOR_QUANT16_ASYMM, the scale must be 0.125 and the zero point must be 0.

Available since NNAPI feature level 3.

ANEURALNETWORKS_BATCH_MATMUL

Performs multiplication of two tensors in batches.

Multiplies all slices of two input tensors and arranges the individual results in a single output tensor of the same batch size. Each pair of slices in the same batch have identical OperandCode. Each slice can optionally be adjointed (transpose and conjugate) before multiplication.

The two input tensors and the output tensor must be 2-D or higher and have the same batch size.

Supported tensor OperandCode:

Supported tensor rank: at least 2 and up to 4

Inputs:

  • 0: A tensor with 2-D or higher shape [..., r_x, c_x].
  • 1: A tensor with 2-D or higher shape [..., r_y, c_y]. It has the same OperandCode and batch size as input0.
  • 2: An optional ANEURALNETWORKS_BOOL scalar adj_x, default to false. Set to true to adjoint the slices of input0.
  • 3: An optional ANEURALNETWORKS_BOOL scalar adj_y, default to false. Set to true to adjoint the slices of input1.

Outputs:

  • 0: A tensor with 2-D or higher shape [..., r_o, c_o], where r_o = c_x if adj_x else r_x c_o = r_y if adj_y else c_y

Available since NNAPI feature level 6.

ANEURALNETWORKS_BATCH_TO_SPACE_ND

BatchToSpace for N-dimensional tensors.

This operation reshapes the batch dimension (dimension 0) into M + 1 dimensions of shape block_shape + [batch], interleaves these blocks back into the grid defined by the spatial dimensions [1, ..., M], to obtain a result with the same rank as the input.

This is the reverse of SpaceToBatch.

Supported tensor OperandCode:

Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. With the default data layout NHWC, the data is stored in the order of: [batch, height, width, channels]. Alternatively, the data layout could be NCHW, the data storage order of: [batch, channels, height, width]. NCHW is supported since NNAPI feature level 3.

Inputs:

  • 0: An n-D tensor, specifying the tensor to be reshaped
  • 1: A 1-D Tensor of ANEURALNETWORKS_TENSOR_INT32, the block sizes for each spatial dimension of the input tensor. All values must be >= 1.
  • 2: An optional ANEURALNETWORKS_BOOL scalar, default to false. Set to true to specify NCHW data layout for input0 and output0. Available since API level 29.

Outputs:

Available since NNAPI feature level 2.

ANEURALNETWORKS_BIDIRECTIONAL_SEQUENCE_LSTM

A recurrent neural network layer that applies an LSTM cell to a sequence of inputs in forward and backward directions.

The op supports cross-linking via an auxiliary input. Regular cell feeds one input into the two RNN cells in the following way:

  INPUT  (INPUT_REVERSED)
    |         |

| FW_LSTM BW_LSTM |

| | FW_OUT BW_OUT

An op with cross-linking takes two inputs and feeds them into the RNN cells in the following way:

  AUX_INPUT   (AUX_INPUT_REVERSED)
      |             |
INPUT | (INPUT_R'D.)|
  |   |       |     |

| \ / \ / |

| FW_LSTM BW_LSTM |

| | FW_OUT BW_OUT

The cross-linking mode is enabled iff auxiliary input and auxiliary weights are present. While stacking this op on top of itself, this allows to connect both forward and backward outputs from previous cell to the next cell's input.

Since NNAPI feature level 4 parallel linking mode is supported. The mode is enabled if auxiliary input is present but auxiliary weights are omitted. In this case, the cell feeds inputs into the RNN in the following way:

  INPUT (AUX_INPUT_REVERSED)
    |         |

| FW_LSTM BW_LSTM |

| | FW_OUT BW_OUT

While stacking this op on top of itself, this allows to connect both forward and backward outputs from previous cell to the next cell's corresponding inputs.

Supported tensor OperandCode:

Supported tensor rank: 3, either time-major or batch-major.

All input and output tensors must be of the same type.

Inputs:

  • 0: The input. A 3-D tensor of shape: If time-major: [max_time, batch_size, input_size] If batch-major: [batch_size, max_time, input_size] where "max_time" is the number of timesteps (sequence length), "batch_size" corresponds to the batching dimension, and "input_size" is the size of the input.
  • 1: The forward input-to-input weights. Optional. A 2-D tensor of shape [fw_num_units, input_size], where “fw_num_units” corresponds to the number of forward cell units.
  • 2: The forward input-to-forget weights. A 2-D tensor of shape [fw_num_units, input_size].
  • 3: The forward input-to-cell weights. A 2-D tensor of shape [fw_num_units, input_size].
  • 4: The forward input-to-output weights. A 2-D tensor of shape [fw_num_units, input_size].
  • 5: The forward recurrent-to-input weights. Optional. A 2-D tensor of shape [fw_num_units, fw_output_size], where “fw_output_size” corresponds to either the number of cell units (i.e., fw_num_units), or the second dimension of the “fw_projection_weights”, if defined.
  • 6: The forward recurrent-to-forget weights. A 2-D tensor of shape [fw_num_units, fw_output_size].
  • 7: The forward recurrent-to-cell weights. A 2-D tensor of shape [fw_num_units, fw_output_size].
  • 8: The forward recurrent-to-output weights. A 2-D tensor of shape [fw_num_units, fw_output_size].
  • 9: The forward cell-to-input weights. Optional. A 1-D tensor of shape [fw_num_units].
  • 10: The forward cell-to-forget weights. Optional. A 1-D tensor of shape [fw_num_units].
  • 11: The forward cell-to-output weights. Optional. A 1-D tensor of shape [fw_num_units].
  • 12: The forward input gate bias. Optional. A 1-D tensor of shape [fw_num_units].
  • 13: The forward forget gate bias. A 1-D tensor of shape [fw_num_units].
  • 14: The forward cell gate bias. A 1-D tensor of shape [fw_num_units].
  • 15: The forward output gate bias. A 1-D tensor of shape [fw_num_units].
  • 16: The forward projection weights. Optional. A 2-D tensor of shape [fw_output_size, fw_num_units].
  • 17: The forward projection bias. Optional. A 1-D tensor of shape [fw_output_size].
  • 18: The backward input-to-input weights. Optional. A 2-D tensor of shape [bw_num_units, input_size], where “bw_num_units” corresponds to the number of backward cell units.
  • 19: The backward input-to-forget weights. A 2-D tensor of shape [bw_num_units, input_size].
  • 20: The backward input-to-cell weights. A 2-D tensor of shape [bw_num_units, input_size].
  • 21: The backward input-to-output weights. A 2-D tensor of shape [bw_num_units, input_size].
  • 22: The backward recurrent-to-input weights. Optional. A 2-D tensor of shape [bw_num_units, bw_output_size], where “bw_output_size” corresponds to either the number of cell units (i.e., “bw_num_units”), or the second dimension of the “bw_projection_weights”, if defined.
  • 23: The backward recurrent-to-forget weights. A 2-D tensor of shape [bw_num_units, bw_output_size].
  • 24: The backward recurrent-to-cell weights. A 2-D tensor of shape [bw_num_units, bw_output_size].
  • 25: The backward recurrent-to-output weights. A 2-D tensor of shape [bw_num_units, bw_output_size].
  • 26: The backward cell-to-input weights. Optional. A 1-D tensor of shape [bw_num_units].
  • 27: The backward cell-to-forget weights. Optional. A 1-D tensor of shape [bw_num_units].
  • 28: The backward cell-to-output weights. Optional. A 1-D tensor of shape [bw_num_units].
  • 29: The backward input gate bias. Optional. A 1-D tensor of shape [bw_num_units].
  • 30: The backward forget gate bias. A 1-D tensor of shape [bw_num_units].
  • 31: The backward cell gate bias. A 1-D tensor of shape [bw_num_units].
  • 32: The backward output gate bias. A 1-D tensor of shape [bw_num_units].
  • 33: The backward projection weights. Optional. A 2-D tensor of shape [bw_output_size, bw_num_units].
  • 34: The backward projection bias. Optional. A 1-D tensor of shape [bw_output_size].
  • 35: The forward input activation state. A 2-D tensor of shape [batch_size, bw_output_size].
  • 36: The forward input cell state. A 2-D tensor of shape [batch_size, bw_num_units].
  • 37: The backward input activation state. A 2-D tensor of shape [batch_size, bw_output_size].
  • 38: The backward input cell state. A 2-D tensor of shape [batch_size, bw_num_units].
  • 39: The auxiliary input. Optional. A 3-D tensor of shape [max_time, batch_size, aux_input_size], where “batch_size” corresponds to the batching dimension, and “aux_input_size” is the size of the auxiliary input. Optional. See the docs above for the usage modes explanation.
  • 40: The forward auxiliary input-to-input weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [fw_num_units, aux_input_size].
  • 41: The forward auxiliary input-to-forget weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [fw_num_units, aux_input_size].
  • 42: The forward auxiliary input-to-cell weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [fw_num_units, aux_input_size].
  • 43: The forward auxiliary input-to-output weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [fw_num_units, aux_input_size].
  • 44: The backward auxiliary input-to-input weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [bw_num_units, aux_input_size].
  • 45: The backward auxiliary input-to-forget weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [bw_num_units, aux_input_size].
  • 46: The backward auxiliary input-to-cell weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [bw_num_units, aux_input_size].
  • 47: The backward auxiliary input-to-output weights. Optional. See the docs above for the usage modes explanation. A 2-D tensor of shape [bw_num_units, aux_input_size].
  • 48: The activation function. A value indicating the activation function:
    • 0: None;
    • 1: Relu;
    • 3: Relu6;
    • 4: Tanh;
    • 6: Sigmoid.
  • 49: The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0 then clipping is disabled. If all the input tensors have type ANEURALNETWORKS_TENSOR_FLOAT32, this scalar must be of the type ANEURALNETWORKS_FLOAT32, otherwise if all the input tensors have the type ANEURALNETWORKS_TENSOR_FLOAT16, this scalar must be of type ANEURALNETWORKS_FLOAT16.
  • 50: The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0 then clipping is disabled. If all the input tensors have type ANEURALNETWORKS_TENSOR_FLOAT32, this scalar must be of the type ANEURALNETWORKS_FLOAT32, otherwise if all the input tensors have the type ANEURALNETWORKS_TENSOR_FLOAT16, this scalar must be of type ANEURALNETWORKS_FLOAT16.
  • 51: merge_outputs An ANEURALNETWORKS_BOOL scalar specifying if the outputs from forward and backward cells should be merged.
  • 52: time_major An ANEURALNETWORKS_BOOL scalar specifying the shape format of input and output tensors.
  • 53: The forward input layer normalization weights. Optional. A 1-D tensor of shape [fw_num_units]. Used to rescale normalized inputs to activation at input gate.
  • 54: The forward forget layer normalization weights. Optional. A 1-D tensor of shape [fw_num_units]. Used to rescale normalized inputs to activation at forget gate.
  • 55: The forward cell layer normalization weights. Optional. A 1-D tensor of shape [fw_num_units]. Used to rescale normalized inputs to activation at cell gate.
  • 56: The forward output layer normalization weights. Optional. A 1-D tensor of shape [fw_num_units]. Used to rescale normalized inputs to activation at output gate.
  • 57: The backward input layer normalization weights. Optional. A 1-D tensor of shape [bw_num_units]. Used to rescale normalized inputs to activation at input gate.
  • 58: The backward forget layer normalization weights. Optional. A 1-D tensor of shape [bw_num_units]. Used to rescale normalized inputs to activation at forget gate.
  • 59: The backward cell layer normalization weights. Optional. A 1-D tensor of shape [bw_num_units]. Used to rescale normalized inputs to activation at cell gate.
  • 60: The backward output layer normalization weights. Optional. A 1-D tensor of shape [bw_num_units]. Used to rescale normalized inputs to activation at output gate.

Outputs:

  • 0: The forward output. A 3-D tensor of shape: If time-major and not merge_outputs: [max_time, batch_size, fw_output_size] If time-major and merge_outputs: [max_time, batch_size, fw_output_size + bw_output_size] If batch-major and not merge_outputs: [batch_size, max_time, fw_output_size] If batch-major and merge_outputs: [batch_size, max_time, fw_output_size + bw_output_size]
  • 1: The backward output. Unused if merge_outputs is true. A 3-D tensor of shape: If time-major: [max_time, batch_size, bw_output_size] If batch-major: [batch_size, max_time, bw_output_size]
  • 2: The forward activation state output. A 2-D tensor of shape [batch_size, fw_output_size] containing an activation state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then outputs 3-5 must be present as well. Available since NNAPI feature level 4.
  • 3: The forward cell state output. A tensor of shape [batch_size, fw_cell_size] containing a cell state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then outputs 2, 4, 5 must be present as well. Available since NNAPI feature level 4.
  • 4: The backward activation state output. A 2-D tensor of shape [batch_size, bw_output_size] containing an activation state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then outputs 2, 3, 5 must be present as well. Available since NNAPI feature level 4.
  • 5: The backward cell state output. A tensor of shape [batch_size, bw_cell_size] containing a cell state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then outputs 2-4 must be present as well. Available since NNAPI feature level 4.

Available since NNAPI feature level 3.

Important: As of NNAPI feature level 3, there is no way to get the output state tensors out and NNAPI does not maintain internal states. This operator does not support the usage pattern in which multiple cells are chained and state tensors are propagated.

ANEURALNETWORKS_BIDIRECTIONAL_SEQUENCE_RNN

A recurrent neural network layer that applies a basic RNN cell to a sequence of inputs in forward and backward directions.

This Op unrolls the input along the sequence dimension, and implements the following operation for each element in the sequence s = 1...sequence_length: fw_outputs[s] = fw_state = activation(inputs[s] * fw_input_weights’ + fw_state * fw_recurrent_weights’ + fw_bias)

And for each element in sequence t = sequence_length : 1 bw_outputs[t] = bw_state = activation(inputs[t] * bw_input_weights’ + bw_state * bw_recurrent_weights’ + bw_bias)

Where:

  • “{fw,bw}_input_weights” is a weight matrix that multiplies the inputs;
  • “{fw,bw}_recurrent_weights” is a weight matrix that multiplies the current “state” which itself is the output from the previous time step computation;
  • “{fw,bw}_bias” is a bias vector (added to each output vector in the batch);
  • “activation” is the function passed as the “fused_activation_function” argument (if not “NONE”).

The op supports cross-linking via an auxiliary input. Regular cell feeds one input into the two RNN cells in the following way:

  INPUT  (INPUT_REVERSED)
    |         |

| FW_RNN BW_RNN |

| | FW_OUT BW_OUT

An op with cross-linking takes two inputs and feeds them into the RNN cells in the following way:

  AUX_INPUT   (AUX_INPUT_REVERSED)
      |             |
INPUT | (INPUT_R'D.)|
  |   |       |     |

| \ / \ / |

| FW_RNN BW_RNN |

| | FW_OUT BW_OUT

The cross-linking mode is enabled iff auxiliary input and auxiliary weights are present. While stacking this op on top of itself, this allows to connect both forward and backward outputs from previous cell to the next cell's input.

Since NNAPI feature level 4 parallel linking mode is supported. The mode is enabled if auxiliary input is present but auxiliary weights are omitted. In this case, the cell feeds inputs into the RNN in the following way:

  INPUT (AUX_INPUT_REVERSED)
    |         |

| FW_RNN BW_RNN |

| | FW_OUT BW_OUT

While stacking this op on top of itself, this allows to connect both forward and backward outputs from previous cell to the next cell's corresponding inputs.

Supported tensor OperandCode:

The input tensors must all be the same type.

Inputs:

  • 0: input. A 3-D tensor. The shape is defined by the input 6 (timeMajor). If it is set to true, then the input has a shape [maxTime, batchSize, inputSize], otherwise the input has a shape [batchSize, maxTime, inputSize].
  • 1: fwWeights. A 2-D tensor of shape [fwNumUnits, inputSize].
  • 2: fwRecurrentWeights. A 2-D tensor of shape [fwNumUnits, fwNumUnits].
  • 3: fwBias. A 1-D tensor of shape [fwNumUnits].
  • 4: fwHiddenState. A 2-D tensor of shape [batchSize, fwNumUnits]. Specifies a hidden state input for the first time step of the computation.
  • 5: bwWeights. A 2-D tensor of shape [bwNumUnits, inputSize].
  • 6: bwRecurrentWeights. A 2-D tensor of shape [bwNumUnits, bwNumUnits].
  • 7: bwBias. A 1-D tensor of shape [bwNumUnits].
  • 8: bwHiddenState A 2-D tensor of shape [batchSize, bwNumUnits]. Specifies a hidden state input for the first time step of the computation.
  • 9: auxInput. A 3-D tensor. The shape is defined by the input 6 (timeMajor). If it is set to true, then the input has a shape [maxTime, batchSize, auxInputSize], otherwise the input has a shape [batchSize, maxTime, auxInputSize]. Can be omitted. See the docs above for the usage modes explanation.
  • 10:fwAuxWeights. A 2-D tensor of shape [fwNumUnits, auxInputSize]. Can be omitted. See the docs above for the usage modes explanation.
  • 11:bwAuxWeights. A 2-D tensor of shape [bwNumUnits, auxInputSize]. Can be omitted. See the docs above for the usage modes explanation.
  • 12:fusedActivationFunction. A FuseCode value indicating the activation function. If “NONE” is specified then it results in a linear activation.
  • 13:timeMajor An ANEURALNETWORKS_BOOL scalar specifying the shape format of input and output tensors.
  • 14:mergeOutputs An ANEURALNETWORKS_BOOL scalar specifying if the outputs from forward and backward cells are separate (if set to false) or concatenated (if set to true). Outputs:
  • 0: fwOutput. A 3-D tensor. The first two dimensions of the shape are defined by the input 6 (timeMajor) and the third dimension is defined by the input 14 (mergeOutputs). If timeMajor is set to true, then the first two dimensions are [maxTime, batchSize], otherwise they are set to [batchSize, maxTime]. If mergeOutputs is set to true, then the third dimension is equal to (fwNumUnits + bwNumUnits), otherwise it is set to fwNumUnits.
  • 1: bwOutput. A 3-D tensor. If the input 14 (mergeOutputs) is set to true, then this tensor is not produced. The shape is defined by the input 6 (timeMajor). If it is set to true, then the shape is set to [maxTime, batchSize, bwNumUnits], otherwise the shape is set to [batchSize, maxTime, bwNumUnits].
  • 2: The forward hidden state output. A 2-D tensor of shape [batchSize, fwNumUnits] containing a hidden state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then output 3 must be present as well. Available since NNAPI feature level 4.
  • 3: The backward hidden state output. A 2-D tensor of shape [batchSize, bwNumUnits] containing a hidden state from the last time step in the sequence. This output is optional and can be omitted. If this output is present then output 2 must be present as well. Available since NNAPI feature level 4.

Available since NNAPI feature level 3.

Important: As of NNAPI feature level 3, there is no way to get the output state tensors out and NNAPI does not maintain internal states. This operator does not support the usage pattern in which multiple cells are chained and state tensors are propagated.

ANEURALNETWORKS_BOX_WITH_NMS_LIMIT

Greedily selects a subset of bounding boxes in descending order of score.

This op applies NMS algorithm to each class. In each loop of execution, the box with maximum score gets selected and removed from the pending set. The scores of the rest of boxes are lowered according to the intersection-over-union (IOU) overlapping with the previously selected boxes and a specified NMS kernel method. Any boxes with score less than a threshold are removed from the pending set.

Three NMS kernels are supported:

  • Hard: score_new = score_old * (1 if IoU < threshold else 0)
  • Linear: score_new = score_old * (1 if IoU < threshold else 1 - IoU)
  • Gaussian: score_new = score_old * exp(- IoU^2 / sigma)

Axis-aligned bounding boxes are represented by its upper-left corner coordinate (x1,y1) and lower-right corner coordinate (x2,y2). A valid bounding box should satisfy x1 <= x2 and y1 <= y2.

Supported tensor OperandCode:

Inputs:

  • 0: A 2-D Tensor of shape [num_rois, num_classes], specifying the score of each bounding box proposal. The boxes are grouped by batches in the first dimension. Zero num_rois is supported for this tensor.
  • 1: A 2-D Tensor specifying the bounding boxes of shape [num_rois, num_classes * 4], organized in the order [x1, y1, x2, y2]. The boxes are grouped by batches in the first dimension. The sequential order of the boxes corresponds with input0. For input0 of type ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, this tensor should be of ANEURALNETWORKS_TENSOR_QUANT16_ASYMM, with zeroPoint of 0 and scale of 0.125. For input0 of type ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED, this tensor should be of ANEURALNETWORKS_TENSOR_QUANT16_ASYMM, with zeroPoint of -128 and scale of 0.125. Zero num_rois is supported for this tensor.
  • 2: A 1-D ANEURALNETWORKS_TENSOR_INT32 tensor, of shape [num_rois], specifying the batch index of each box. Boxes with the same batch index are grouped together.
  • 3: An ANEURALNETWORKS_FLOAT32 scalar, score_threshold. Boxes with scores lower than the threshold are filtered before sending to the NMS algorithm.
  • 4: An ANEURALNETWORKS_INT32 scalar, specifying the maximum number of selected bounding boxes for each image. Set to a negative value for unlimited number of output bounding boxes.
  • 5: An ANEURALNETWORKS_INT32 scalar, specifying the NMS kernel method, options are 0:hard, 1:linear, 2:gaussian.
  • 6: An ANEURALNETWORKS_FLOAT32 scalar, specifying the IoU threshold in hard and linear NMS kernel. This field is ignored if gaussian kernel is selected.
  • 7: An ANEURALNETWORKS_FLOAT32 scalar, specifying the sigma in gaussian NMS kernel. This field is ignored if gaussian kernel is not selected.
  • 8: An ANEURALNETWORKS_FLOAT32 scalar, nms_score_threshold. Boxes with scores lower than the threshold are dropped during the score updating phase in soft NMS.

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_CAST

Casts a tensor to a type.

This operation ignores the scale and zeroPoint of quanized tensors, e.g. it treats a ANEURALNETWORKS_TENSOR_QUANT8_ASYMM input as a tensor of uint8 values.

Supported tensor OperandCode:

Supported tensor rank: from 1

Inputs:

  • 0: A tensor.

Outputs:

  • 0: A tensor with the same shape as input0.

Available since NNAPI feature level 3.

ANEURALNETWORKS_CHANNEL_SHUFFLE

Shuffle the channels of the input tensor.

Given an input tensor and a integer value of num_groups, CHANNEL_SHUFFLE divide the channel dimension into num_groups groups, and reorganize the channels by grouping channels with the same index in each group.

Along the channel dimension, the output is calculated using this formula:

output_channel[k * num_groups + g] = input_channel[g * group_size + k]

where group_size = num_channels / num_groups

The number of channels must be divisible by num_groups.

Supported tensor OperandCode:

Supported tensor rank: up to 4

Inputs:

  • 0: An n-D tensor, specifying the tensor to be shuffled.
  • 1: An ANEURALNETWORKS_INT32 scalar, specifying the number of groups.
  • 2: An ANEURALNETWORKS_INT32 scalar, specifying the dimension channel shuffle would be performed on. Negative index is used to specify axis from the end (e.g. -1 for the last axis). Must be in the range [-n, n).

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_CONCATENATION

Concatenates the input tensors along the given dimension.

The input tensors must have identical OperandCode and the same dimensions except the dimension along the concatenation axis.

Supported tensor OperandCode:

Supported tensor rank: up to 4

Inputs:

Outputs:

  • 0: The output, a tensor of the same OperandCode as the input tensors. The output shape is [D0, D1, ..., sum(Daxis(i)), ..., Dm]. Since NNAPI feature level 3, for a ANEURALNETWORKS_TENSOR_QUANT8_ASYMM tensor, the scale and zeroPoint values can be different from input tensors. Before NNAPI feature level 3 they have to be the same as for the input tensors.

Available since NNAPI feature level 1.

ANEURALNETWORKS_CONV_2D

Performs a 2-D convolution operation.

The CONV_2D op sweeps a 2-D filter that can mix channels together over a batch of images, applying the filter to each window of each image of the appropriate size.

The output dimensions are functions of the filter dimensions, stride, and padding.

The values in the output tensor are computed as:

output[b, i, j, channel] =
    sum_{di, dj, k} (
        input[b, strides[1] * i + di, strides[2] * j + dj, k] *
        filter[channel, di, dj, k]
    ) + bias[channel]

Supported tensor OperandCode configurations:

Available since NNAPI feature level 3:

Available since NNAPI feature level 4:

Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. With the default data layout NHWC, the data is stored in the order of: [batch, height, width, channels]. Alternatively, the data layout could be NCHW, the data storage order of: [batch, channels, height, width]. NCHW is supported since NNAPI feature level 3.

Both explicit padding and implicit padding are supported.

Inputs (explicit padding):

Inputs (implicit padding):

Outputs:

  • 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out]. Before NNAPI feature level 3, for output tensor of ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, the following condition must be satisfied: output_scale > input_scale * filter_scale

Available since NNAPI feature level 1.

ANEURALNETWORKS_DEPTHWISE_CONV_2D

Performs a depthwise 2-D convolution operation.

Given an input tensor of shape [batches, height, width, depth_in] and a filter tensor of shape [1, filter_height, filter_width, depth_out] containing depth_out convolutional filters of depth 1, DEPTHWISE_CONV applies a different filter to each input channel (expanding from 1 channel to channel_multiplier channels for each), then concatenates the results together.

The output has depth_out = depth_in * depth_multiplier channels. The output dimensions are functions of the filter dimensions, stride, and padding.

The values in the output tensor are computed as:

output[b, i, j, k * channel_multiplier + q] =
    sum_{di, dj} (
        input[b, strides[1] * i + di, strides[2] * j + dj, k] *
        filter[1, di, dj, k * channel_multiplier + q]
    ) + bias[k * channel_multiplier + q]

Supported tensor OperandCode configurations:

Available since NNAPI feature level 3:

Available since NNAPI feature level 4:

Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. With the default data layout NHWC, the data is stored in the order of: [batch, height, width, channels]. Alternatively, the data layout could be NCHW, the data storage order of: [batch, channels, height, width]. NCHW is supported since NNAPI feature level 3.

Both explicit padding and implicit padding are supported.

Inputs (explicit padding):

Inputs (implicit padding):

  • 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
  • 1: A 4-D tensor, of shape [1, filter_height, filter_width, depth_out], specifying the filter.
  • 2: A 1-D tensor, of shape [depth_out], specifying the bias. For input tensor of type ANEURALNETWORKS_TENSOR_FLOAT32 or ANEURALNETWORKS_TENSOR_FLOAT16 the bias must be of the same type. For filter tensor of ANEURALNETWORKS_TENSOR_QUANT8_ASYMM and ANEURALNETWORKS_TENSOR_QUANT8_ASYMM_SIGNED, the bias should be of ANEURALNETWORKS_TENSOR_INT32, with zeroPoint of 0 and bias_scale == input_scale * filter_scale. For filter tensor of ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL, the bias should be of ANEURALNETWORKS_TENSOR_INT32, with zeroPoint of 0 and bias_scale of 0. The actual scale of each value 'i' is equal to bias_scale[i] = input_scale * filter_scale[i].
  • 3: An ANEURALNETWORKS_INT32 scalar, specifying the implicit padding scheme, has to be one of the PaddingCode values.
  • 4: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘width’ dimension.
  • 5: An ANEURALNETWORKS_INT32 scalar, specifying the stride when walking through input in the ‘height’ dimension.
  • 6: An ANEURALNETWORKS_INT32 scalar, specifying the depthwise multiplier.
  • 7: An ANEURALNETWORKS_INT32 scalar, and has to be one of the FuseCode values. Specifies the activation to invoke on the result.
  • 8: An optional ANEURALNETWORKS_BOOL scalar, default to false. Set to true to specify NCHW data layout for input0 and output0. Available since NNAPI feature level 3.
  • 9: An optional ANEURALNETWORKS_INT32 scalar, specifying the dilation factor for width. Defaults to 1. If set to k > 1, there will be k-1 skipped cells between each filter element on width dimension. If this input is set, input 10 (dilation factor for height) must be specified as well. Available since NNAPI feature level 3.
  • 10: An optional ANEURALNETWORKS_INT32 scalar, specifying the dilation factor for height. Defaults to 1. If set to k > 1, there will be k-1 skipped cells between each filter element on height dimension. If this input is set, input 9 (dilation factor for width) must be specified as well. Available since NNAPI feature level 3.

Outputs:

  • 0: The output 4-D tensor, of shape [batches, out_height, out_width, depth_out]. Before NNAPI feature level 3, for output tensor of ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, the following condition must be satisfied: output_scale > input_scale * filter_scale

Available since NNAPI feature level 1.

ANEURALNETWORKS_DEPTH_TO_SPACE

Rearranges data from depth into blocks of spatial data.

More specifically, this op outputs a copy of the input tensor where values from the depth dimension are moved in spatial blocks to the height and width dimensions. The value block_size indicates the input block size and how the data is moved.

Chunks of data of size block_size * block_size from depth are rearranged into non-overlapping blocks of size block_size x block_size.

The width of the output tensor is input_depth * block_size, whereas the height is input_height * block_size. The depth of the input tensor must be divisible by block_size * block_size

Supported tensor OperandCode:

Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. With the default data layout NHWC, the data is stored in the order of: [batch, height, width, channels]. Alternatively, the data layout could be NCHW, the data storage order of: [batch, channels, height, width]. NCHW is supported since NNAPI feature level 3.

Inputs:

  • 0: A 4-D tensor, of shape [batches, height, width, depth_in], specifying the input.
  • 1: An ANEURALNETWORKS_INT32 scalar, specifying the block_size. block_size must be >=1 and block_size * block_size must be a divisor of the input depth.
  • 2: An optional ANEURALNETWORKS_BOOL scalar, default to false. Set to true to specify NCHW data layout for input0 and output0. Available since NNAPI feature level 3.

Outputs:

Available since NNAPI feature level 1.

ANEURALNETWORKS_DEQUANTIZE

Dequantizes the input tensor.

The formula is:

output = (input - zeroPoint) * scale.

Supported input tensor OperandCode:

Supported output tensor OperandCode:

Supported tensor rank: up to 4

Inputs:

  • 0: A tensor. Since NNAPI feature level 3, this tensor may be zero-sized.

Outputs:

  • 0: A tensor with the same shape as input0.

Available since NNAPI feature level 1.

ANEURALNETWORKS_DETECTION_POSTPROCESSING

Apply postprocessing steps to bounding box detections.

Bounding box detections are generated by applying transformation on a set of predefined anchors with the bounding box deltas from bounding box regression. A final step of hard NMS is applied to limit the number of returned boxes.

Supported tensor OperandCode:

Inputs:

  • 0: A 3-D Tensor of shape [batches, num_anchors, num_classes], specifying the score of each anchor with each class. Class 0 for each [batches, num_anchors, 0] is background and will be ignored.
  • 1: A 3-D Tensor of shape [batches, num_anchors, length_box_encoding], with the first four values in length_box_encoding specifying the bounding box deltas. The box deltas are encoded in the order of [dy, dx, dh, dw], where dy and dx is the linear-scale relative correction factor for the center position of the bounding box with respect to the width and height, dh and dw is the log-scale relative correction factor for the width and height. All the entries in length_box_encoding beyond the first four values are ignored in this operation.
  • 2: A 2-D Tensor of shape [num_anchors, 4], specifying the shape of each predefined anchor, with format [ctr_y, ctr_x, h, w], where ctr_y and ctr_x are the center position of the box, and h and w are the height and the width.
  • 3: An ANEURALNETWORKS_FLOAT32 scalar, specifying the scaling factor for dy in bounding box deltas.
  • 4: An ANEURALNETWORKS_FLOAT32 scalar, specifying the scaling factor for dx in bounding box deltas.
  • 5: An ANEURALNETWORKS_FLOAT32 scalar, specifying the scaling factor for dh in bounding box deltas.
  • 6: An ANEURALNETWORKS_FLOAT32 scalar, specifying the scaling factor for dw in bounding box deltas.
  • 7: An ANEURALNETWORKS_BOOL scalar, set to true to use regular multi-class NMS algorithm that do NMS separately for each class, set to false for a faster algorithm that only do one single NMS using the highest class score..
  • 8: An ANEURALNETWORKS_INT32 scalar, max_num_detections, specifying the maximum number of boxes for the output. Boxes with the lowest scores are discarded to meet the limit.
  • 9: An ANEURALNETWORKS_INT32 scalar, only used when input7 is set to false, specifying the maximum number of classes per detection.
  • 10: An ANEURALNETWORKS_INT32 scalar, only used when input7 is set to true, specifying the maximum number of detections when applying NMS algorithm for each single class.
  • 11: A scalar, score_threshold. Boxes with scores lower than the threshold are filtered before sending to the NMS algorithm. The scalar must be of ANEURALNETWORKS_FLOAT16 if input0 is of ANEURALNETWORKS_TENSOR_FLOAT16 and of ANEURALNETWORKS_FLOAT32 if input0 is of ANEURALNETWORKS_TENSOR_FLOAT32.
  • 12: A scalar, specifying the IoU threshold for hard NMS. The scalar must be of ANEURALNETWORKS_FLOAT16 if input0 is of ANEURALNETWORKS_TENSOR_FLOAT16 and of ANEURALNETWORKS_FLOAT32 if input0 is of ANEURALNETWORKS_TENSOR_FLOAT32.
  • 13: An ANEURALNETWORKS_BOOL scalar, set to true to include background class in the list of label map for the output, set to false to not include the background. When the background class is included, it has label 0 and the output classes start at 1 in the label map, otherwise, the output classes start at 0.

Outputs:

  • 0: A 2-D tensor of the same OperandCode as input0, with shape [batches, max_num_detections], specifying the score of each output detections.
  • 1: A 3-D tensor of shape [batches, max_num_detections, 4], specifying the coordinates of each output bounding box, with format [y1, x1, y2, x2].
  • 2: A 2-D ANEURALNETWORKS_TENSOR_INT32 tensor, of shape [batches, max_num_detections], specifying the class label for each output detection.
  • 3: An 1-D ANEURALNETWORKS_TENSOR_INT32 tensor, of shape [batches], specifying the number of valid output detections for each batch.

Available since NNAPI feature level 3.

ANEURALNETWORKS_DIV

Element-wise division of two tensors.

Takes two input tensors of identical OperandCode and compatible dimensions. The output is the result of dividing the first input tensor by the second, optionally modified by an activation function.

For inputs of ANEURALNETWORKS_TENSOR_INT32, performs "floor division" ("//" in Python). For example, 5 // 2 = 2 -5 // 2 = -3

Two dimensions are compatible when:

  1. they are equal, or
  2. one of them is 1

The size of the output is the maximum size along each dimension of the input operands. It starts with the trailing dimensions, and works its way forward.

Example: input1.dimension = {4, 1, 2} input2.dimension = {5, 4, 3, 1} output.dimension = {5, 4, 3, 2}

Since NNAPI feature level 3, generic zero-sized input tensor is supported. Zero dimension is only compatible with 0 or 1. The size of the output dimension is zero if either of corresponding input dimension is zero.

Supported tensor OperandCode:

Supported tensor rank: up to 4

Inputs:

Outputs:

Available since NNAPI feature level 2.

ANEURALNETWORKS_ELU

Computes exponential linear activation on the input tensor element-wise.

The output is calculated using the following formula:

ELU(x) = max(0, x) + min(0, alpha * (exp(x) - 1))

Supported tensor OperandCode:

Supported tensor rank: from 1.

Inputs:

Outputs:

  • 0: The output tensor of same shape and type as input0.

Available since NNAPI feature level 4.

ANEURALNETWORKS_EMBEDDING_LOOKUP

Looks up sub-tensors in the input tensor.

This operator takes for input a tensor of values (Values) and a one-dimensional tensor of selection indices (Lookups). The output tensor is the concatenation of sub-tensors of Values as selected by Lookups.

Think of Values as being sliced along its first dimension: The entries in Lookups select which slices are concatenated together to create the output tensor.

For example, if Values has shape of [40, 200, 300] and Lookups has shape of [3], all three values found in Lookups are expected to be between 0 and 39. The resulting tensor must have shape of [3, 200, 300].

If a value in Lookups is out of bounds, the operation must fail and an error must be reported.

Supported value tensor OperandCode:

Supported value tensor rank: from 2

Inputs:

  • 0: Lookups. A 1-D tensor of ANEURALNETWORKS_TENSOR_INT32. The values are indices into the first dimension of Values.
  • 1: Values. An n-D tensor, where n >= 2, from which sub-tensors are extracted.

Output:

Available since NNAPI feature level 1.

ANEURALNETWORKS_EQUAL

For input tensors x and y, computes x == y elementwise.

Supported tensor OperandCode:

Supported tensor rank: from 1

This operation supports broadcasting.

Inputs:

  • 0: A tensor.
  • 1: A tensor of the same OperandCode and dimensions compatible with input0.

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_EXP

Computes exponential of x element-wise.

Supported tensor OperandCode:

Supported tensor rank: from 1.

Inputs:

  • 0: A tensor.

Outputs:

  • 0: The output tensor of same shape as input0.

Available since NNAPI feature level 3.

ANEURALNETWORKS_EXPAND_DIMS

Inserts a dimension of 1 into a tensor's shape.

Given a tensor input, this operation inserts a dimension of 1 at the given dimension index of input's shape. The dimension index starts at zero; if you specify a negative dimension index, it is counted backward from the end.

Supported tensor OperandCode:

Supported tensor rank: from 1

Inputs:

  • 0: An n-D tensor.
  • 1: An ANEURALNETWORKS_INT32 scalar specifying the dimension index to expand. Must be in the range [-(n + 1), (n + 1)).

Outputs:

Available since NNAPI feature level 3.

ANEURALNETWORKS_FILL

Creates a tensor filled with a scalar value.

Supported output tensor OperandCode:

Supported tensor rank: from 1.

Inputs:

Outputs:

  • 0: The output tensor.

Available since NNAPI feature level 4.

ANEURALNETWORKS_FLOOR

Computes element-wise floor() on the input tensor.

Supported tensor