erik.andersson@arm.com | 460c689 | 2021-02-24 14:38:09 +0100 | [diff] [blame] | 1 | # Copyright (C) 2020-2021 Arm Limited or its affiliates. All rights reserved. |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 2 | # |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | # not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 16 | # Description: |
| 17 | # TensorFlow Lite mapping functions used by both reader and writer. |
| 18 | # Contains a mapping from the various TensorFlow Lite enums and options structs, generated by the FlatBuffer code |
| 19 | # generator, to Vela's internal format. |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 20 | import struct |
| 21 | |
Diego Russo | ea6111a | 2020-04-14 18:41:58 +0100 | [diff] [blame] | 22 | import numpy as np |
| 23 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 24 | from .data_type import DataType |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 25 | from .operation import CustomType |
| 26 | from .operation import Op |
Michael McGeagh | 1689548 | 2020-12-14 15:51:20 +0000 | [diff] [blame] | 27 | from .operation import Padding as opPad |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 28 | from .operation import TensorIndices |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 29 | from .tflite import AbsOptions |
| 30 | from .tflite import AddNOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 31 | from .tflite import AddOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 32 | from .tflite import ArgMaxOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 33 | from .tflite import ArgMinOptions |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 34 | from .tflite import AssignVariableOptions |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 35 | from .tflite import ATan2Options |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 36 | from .tflite import BatchMatMulOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 37 | from .tflite import BatchToSpaceNDOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 38 | from .tflite import BidirectionalSequenceLSTMOptions |
| 39 | from .tflite import BidirectionalSequenceRNNOptions |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 40 | from .tflite import BroadcastToOptions |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 41 | from .tflite import BucketizeOptions |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 42 | from .tflite import CallOnceOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 43 | from .tflite import CallOptions |
| 44 | from .tflite import CastOptions |
| 45 | from .tflite import ConcatEmbeddingsOptions |
| 46 | from .tflite import ConcatenationOptions |
| 47 | from .tflite import Conv2DOptions |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 48 | from .tflite import Conv3DOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 49 | from .tflite import CosOptions |
Tim Hall | 42abec1 | 2021-02-04 21:31:57 +0000 | [diff] [blame] | 50 | from .tflite import CumsumOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 51 | from .tflite import DensifyOptions |
| 52 | from .tflite import DepthToSpaceOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 53 | from .tflite import DepthwiseConv2DOptions |
| 54 | from .tflite import DequantizeOptions |
| 55 | from .tflite import DivOptions |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 56 | from .tflite import DynamicUpdateSliceOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 57 | from .tflite import EmbeddingLookupSparseOptions |
| 58 | from .tflite import EqualOptions |
| 59 | from .tflite import ExpandDimsOptions |
| 60 | from .tflite import ExpOptions |
| 61 | from .tflite import FakeQuantOptions |
| 62 | from .tflite import FillOptions |
| 63 | from .tflite import FloorDivOptions |
| 64 | from .tflite import FloorModOptions |
| 65 | from .tflite import FullyConnectedOptions |
| 66 | from .tflite import GatherNdOptions |
| 67 | from .tflite import GatherOptions |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 68 | from .tflite import GeluOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 69 | from .tflite import GreaterEqualOptions |
| 70 | from .tflite import GreaterOptions |
Louis Verhaard | 678645b | 2020-06-15 15:22:47 +0200 | [diff] [blame] | 71 | from .tflite import HardSwishOptions |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 72 | from .tflite import HashtableFindOptions |
| 73 | from .tflite import HashtableImportOptions |
| 74 | from .tflite import HashtableOptions |
| 75 | from .tflite import HashtableSizeOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 76 | from .tflite import IfOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 77 | from .tflite import L2NormOptions |
| 78 | from .tflite import LeakyReluOptions |
| 79 | from .tflite import LessEqualOptions |
| 80 | from .tflite import LessOptions |
| 81 | from .tflite import LocalResponseNormalizationOptions |
| 82 | from .tflite import LogicalAndOptions |
| 83 | from .tflite import LogicalNotOptions |
| 84 | from .tflite import LogicalOrOptions |
| 85 | from .tflite import LogSoftmaxOptions |
| 86 | from .tflite import LSHProjectionOptions |
| 87 | from .tflite import LSTMOptions |
| 88 | from .tflite import MatrixDiagOptions |
| 89 | from .tflite import MatrixSetDiagOptions |
| 90 | from .tflite import MaximumMinimumOptions |
| 91 | from .tflite import MirrorPadOptions |
| 92 | from .tflite import MulOptions |
| 93 | from .tflite import NegOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 94 | from .tflite import NonMaxSuppressionV4Options |
| 95 | from .tflite import NonMaxSuppressionV5Options |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 96 | from .tflite import NotEqualOptions |
| 97 | from .tflite import OneHotOptions |
| 98 | from .tflite import PackOptions |
| 99 | from .tflite import PadOptions |
| 100 | from .tflite import PadV2Options |
| 101 | from .tflite import Pool2DOptions |
| 102 | from .tflite import PowOptions |
| 103 | from .tflite import QuantizeOptions |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 104 | from .tflite import RandomOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 105 | from .tflite import RangeOptions |
| 106 | from .tflite import RankOptions |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 107 | from .tflite import ReadVariableOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 108 | from .tflite import ReducerOptions |
| 109 | from .tflite import ReshapeOptions |
| 110 | from .tflite import ResizeBilinearOptions |
| 111 | from .tflite import ResizeNearestNeighborOptions |
| 112 | from .tflite import ReverseSequenceOptions |
| 113 | from .tflite import ReverseV2Options |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 114 | from .tflite import Rfft2dOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 115 | from .tflite import RNNOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 116 | from .tflite import ScatterNdOptions |
| 117 | from .tflite import SegmentSumOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 118 | from .tflite import SelectOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 119 | from .tflite import SelectV2Options |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 120 | from .tflite import SequenceRNNOptions |
| 121 | from .tflite import ShapeOptions |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 122 | from .tflite import SignOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 123 | from .tflite import SkipGramOptions |
| 124 | from .tflite import SliceOptions |
| 125 | from .tflite import SoftmaxOptions |
| 126 | from .tflite import SpaceToBatchNDOptions |
| 127 | from .tflite import SpaceToDepthOptions |
| 128 | from .tflite import SparseToDenseOptions |
| 129 | from .tflite import SplitOptions |
| 130 | from .tflite import SplitVOptions |
| 131 | from .tflite import SquaredDifferenceOptions |
| 132 | from .tflite import SquareOptions |
| 133 | from .tflite import SqueezeOptions |
| 134 | from .tflite import StridedSliceOptions |
| 135 | from .tflite import SubOptions |
| 136 | from .tflite import SVDFOptions |
| 137 | from .tflite import TileOptions |
| 138 | from .tflite import TopKV2Options |
| 139 | from .tflite import TransposeConvOptions |
| 140 | from .tflite import TransposeOptions |
| 141 | from .tflite import UnidirectionalSequenceLSTMOptions |
| 142 | from .tflite import UniqueOptions |
| 143 | from .tflite import UnpackOptions |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 144 | from .tflite import UnsortedSegmentMaxOptions |
| 145 | from .tflite import UnsortedSegmentMinOptions |
erik.andersson@arm.com | dd49a72 | 2022-08-10 15:26:48 +0200 | [diff] [blame] | 146 | from .tflite import UnsortedSegmentProdOptions |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 147 | from .tflite import UnsortedSegmentSumOptions |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 148 | from .tflite import VarHandleOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 149 | from .tflite import WhereOptions |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 150 | from .tflite import WhileOptions |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 151 | from .tflite import ZerosLikeOptions |
| 152 | from .tflite.ActivationFunctionType import ActivationFunctionType |
Diego Russo | ea6111a | 2020-04-14 18:41:58 +0100 | [diff] [blame] | 153 | from .tflite.BuiltinOperator import BuiltinOperator |
| 154 | from .tflite.BuiltinOptions import BuiltinOptions |
| 155 | from .tflite.Padding import Padding |
Diego Russo | e8a1045 | 2020-04-21 17:39:10 +0100 | [diff] [blame] | 156 | from .tflite.TensorType import TensorType |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 157 | |
| 158 | |
| 159 | def inverse_map(map): |
| 160 | return {v: k for k, v in map.items()} |
| 161 | |
| 162 | |
| 163 | datatype_map = { |
| 164 | TensorType.UINT8: DataType.uint8, |
| 165 | TensorType.INT8: DataType.int8, |
| 166 | TensorType.INT16: DataType.int16, |
| 167 | TensorType.INT32: DataType.int32, |
| 168 | TensorType.INT64: DataType.int64, |
| 169 | TensorType.FLOAT16: DataType.float16, |
| 170 | TensorType.FLOAT32: DataType.float32, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 171 | TensorType.FLOAT64: DataType.float64, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 172 | TensorType.STRING: DataType.string, |
| 173 | TensorType.BOOL: DataType.bool, |
Jacob Bohlin | f767b93 | 2020-08-13 15:32:45 +0200 | [diff] [blame] | 174 | TensorType.COMPLEX64: DataType.complex64, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 175 | TensorType.COMPLEX128: DataType.complex128, |
Dwight Lidman | f53b332 | 2021-10-08 11:58:08 +0200 | [diff] [blame] | 176 | TensorType.UINT64: DataType.uint64, |
| 177 | TensorType.RESOURCE: DataType.resource, |
| 178 | TensorType.VARIANT: DataType.variant, |
| 179 | TensorType.UINT32: DataType.uint32, |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 180 | TensorType.UINT16: DataType.uint16, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | datatype_inv_map = inverse_map(datatype_map) |
| 184 | datatype_inv_map[DataType.quint8] = TensorType.UINT8 |
| 185 | |
| 186 | datatype_inv_map[DataType.qint8] = TensorType.INT8 |
| 187 | datatype_inv_map[DataType.qint16] = TensorType.INT16 |
| 188 | datatype_inv_map[DataType.qint32] = TensorType.INT32 |
| 189 | |
| 190 | |
| 191 | datatype_map_numpy = { |
| 192 | TensorType.UINT8: np.uint8, |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 193 | TensorType.UINT16: np.uint16, |
Dwight Lidman | f53b332 | 2021-10-08 11:58:08 +0200 | [diff] [blame] | 194 | TensorType.UINT32: np.uint32, |
| 195 | TensorType.UINT64: np.uint64, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 196 | TensorType.INT8: np.int8, |
| 197 | TensorType.INT16: np.int16, |
| 198 | TensorType.INT32: np.int32, |
| 199 | TensorType.INT64: np.int64, |
| 200 | TensorType.FLOAT16: np.float16, |
| 201 | TensorType.FLOAT32: np.float32, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 202 | TensorType.FLOAT64: np.float64, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 203 | TensorType.BOOL: np.bool, |
Jacob Bohlin | f767b93 | 2020-08-13 15:32:45 +0200 | [diff] [blame] | 204 | TensorType.COMPLEX64: np.complex64, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 205 | TensorType.COMPLEX128: np.complex128, |
Louis Verhaard | f4e12be | 2020-12-18 14:23:06 +0100 | [diff] [blame] | 206 | TensorType.STRING: np.uint8, |
Dwight Lidman | f53b332 | 2021-10-08 11:58:08 +0200 | [diff] [blame] | 207 | TensorType.RESOURCE: None, # experimental type |
| 208 | TensorType.VARIANT: None, # experimental type |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | |
| 212 | builtin_options_map = { |
| 213 | BuiltinOptions.Conv2DOptions: Conv2DOptions.Conv2DOptions, |
| 214 | BuiltinOptions.DepthwiseConv2DOptions: DepthwiseConv2DOptions.DepthwiseConv2DOptions, |
| 215 | BuiltinOptions.ConcatEmbeddingsOptions: ConcatEmbeddingsOptions.ConcatEmbeddingsOptions, |
| 216 | BuiltinOptions.LSHProjectionOptions: LSHProjectionOptions.LSHProjectionOptions, |
| 217 | BuiltinOptions.Pool2DOptions: Pool2DOptions.Pool2DOptions, |
| 218 | BuiltinOptions.SVDFOptions: SVDFOptions.SVDFOptions, |
| 219 | BuiltinOptions.RNNOptions: RNNOptions.RNNOptions, |
| 220 | BuiltinOptions.FullyConnectedOptions: FullyConnectedOptions.FullyConnectedOptions, |
| 221 | BuiltinOptions.SoftmaxOptions: SoftmaxOptions.SoftmaxOptions, |
| 222 | BuiltinOptions.ConcatenationOptions: ConcatenationOptions.ConcatenationOptions, |
| 223 | BuiltinOptions.AddOptions: AddOptions.AddOptions, |
| 224 | BuiltinOptions.L2NormOptions: L2NormOptions.L2NormOptions, |
| 225 | BuiltinOptions.LocalResponseNormalizationOptions: LocalResponseNormalizationOptions.LocalResponseNormalizationOptions, # noqa: E501 |
| 226 | BuiltinOptions.LSTMOptions: LSTMOptions.LSTMOptions, |
| 227 | BuiltinOptions.ResizeBilinearOptions: ResizeBilinearOptions.ResizeBilinearOptions, |
| 228 | BuiltinOptions.CallOptions: CallOptions.CallOptions, |
| 229 | BuiltinOptions.ReshapeOptions: ReshapeOptions.ReshapeOptions, |
| 230 | BuiltinOptions.SkipGramOptions: SkipGramOptions.SkipGramOptions, |
| 231 | BuiltinOptions.SpaceToDepthOptions: SpaceToDepthOptions.SpaceToDepthOptions, |
| 232 | BuiltinOptions.EmbeddingLookupSparseOptions: EmbeddingLookupSparseOptions.EmbeddingLookupSparseOptions, |
| 233 | BuiltinOptions.MulOptions: MulOptions.MulOptions, |
| 234 | BuiltinOptions.PadOptions: PadOptions.PadOptions, |
| 235 | BuiltinOptions.GatherOptions: GatherOptions.GatherOptions, |
| 236 | BuiltinOptions.BatchToSpaceNDOptions: BatchToSpaceNDOptions.BatchToSpaceNDOptions, |
| 237 | BuiltinOptions.SpaceToBatchNDOptions: SpaceToBatchNDOptions.SpaceToBatchNDOptions, |
| 238 | BuiltinOptions.TransposeOptions: TransposeOptions.TransposeOptions, |
| 239 | BuiltinOptions.ReducerOptions: ReducerOptions.ReducerOptions, |
| 240 | BuiltinOptions.SubOptions: SubOptions.SubOptions, |
| 241 | BuiltinOptions.DivOptions: DivOptions.DivOptions, |
| 242 | BuiltinOptions.SqueezeOptions: SqueezeOptions.SqueezeOptions, |
| 243 | BuiltinOptions.SequenceRNNOptions: SequenceRNNOptions.SequenceRNNOptions, |
| 244 | BuiltinOptions.StridedSliceOptions: StridedSliceOptions.StridedSliceOptions, |
| 245 | BuiltinOptions.ExpOptions: ExpOptions.ExpOptions, |
| 246 | BuiltinOptions.TopKV2Options: TopKV2Options.TopKV2Options, |
| 247 | BuiltinOptions.SplitOptions: SplitOptions.SplitOptions, |
| 248 | BuiltinOptions.LogSoftmaxOptions: LogSoftmaxOptions.LogSoftmaxOptions, |
| 249 | BuiltinOptions.CastOptions: CastOptions.CastOptions, |
| 250 | BuiltinOptions.DequantizeOptions: DequantizeOptions.DequantizeOptions, |
| 251 | BuiltinOptions.MaximumMinimumOptions: MaximumMinimumOptions.MaximumMinimumOptions, |
| 252 | BuiltinOptions.ArgMaxOptions: ArgMaxOptions.ArgMaxOptions, |
| 253 | BuiltinOptions.LessOptions: LessOptions.LessOptions, |
| 254 | BuiltinOptions.NegOptions: NegOptions.NegOptions, |
| 255 | BuiltinOptions.PadV2Options: PadV2Options.PadV2Options, |
| 256 | BuiltinOptions.GreaterOptions: GreaterOptions.GreaterOptions, |
| 257 | BuiltinOptions.GreaterEqualOptions: GreaterEqualOptions.GreaterEqualOptions, |
| 258 | BuiltinOptions.LessEqualOptions: LessEqualOptions.LessEqualOptions, |
| 259 | BuiltinOptions.SelectOptions: SelectOptions.SelectOptions, |
| 260 | BuiltinOptions.SliceOptions: SliceOptions.SliceOptions, |
| 261 | BuiltinOptions.TransposeConvOptions: TransposeConvOptions.TransposeConvOptions, |
| 262 | BuiltinOptions.SparseToDenseOptions: SparseToDenseOptions.SparseToDenseOptions, |
| 263 | BuiltinOptions.TileOptions: TileOptions.TileOptions, |
| 264 | BuiltinOptions.ExpandDimsOptions: ExpandDimsOptions.ExpandDimsOptions, |
| 265 | BuiltinOptions.EqualOptions: EqualOptions.EqualOptions, |
| 266 | BuiltinOptions.NotEqualOptions: NotEqualOptions.NotEqualOptions, |
| 267 | BuiltinOptions.ShapeOptions: ShapeOptions.ShapeOptions, |
| 268 | BuiltinOptions.PowOptions: PowOptions.PowOptions, |
| 269 | BuiltinOptions.ArgMinOptions: ArgMinOptions.ArgMinOptions, |
| 270 | BuiltinOptions.FakeQuantOptions: FakeQuantOptions.FakeQuantOptions, |
| 271 | BuiltinOptions.PackOptions: PackOptions.PackOptions, |
| 272 | BuiltinOptions.LogicalOrOptions: LogicalOrOptions.LogicalOrOptions, |
| 273 | BuiltinOptions.OneHotOptions: OneHotOptions.OneHotOptions, |
| 274 | BuiltinOptions.LogicalAndOptions: LogicalAndOptions.LogicalAndOptions, |
| 275 | BuiltinOptions.LogicalNotOptions: LogicalNotOptions.LogicalNotOptions, |
| 276 | BuiltinOptions.UnpackOptions: UnpackOptions.UnpackOptions, |
| 277 | BuiltinOptions.FloorDivOptions: FloorDivOptions.FloorDivOptions, |
| 278 | BuiltinOptions.SquareOptions: SquareOptions.SquareOptions, |
| 279 | BuiltinOptions.ZerosLikeOptions: ZerosLikeOptions.ZerosLikeOptions, |
| 280 | BuiltinOptions.FillOptions: FillOptions.FillOptions, |
| 281 | BuiltinOptions.BidirectionalSequenceLSTMOptions: BidirectionalSequenceLSTMOptions.BidirectionalSequenceLSTMOptions, |
| 282 | BuiltinOptions.BidirectionalSequenceRNNOptions: BidirectionalSequenceRNNOptions.BidirectionalSequenceRNNOptions, |
| 283 | BuiltinOptions.UnidirectionalSequenceLSTMOptions: UnidirectionalSequenceLSTMOptions.UnidirectionalSequenceLSTMOptions, # noqa: E501 |
| 284 | BuiltinOptions.FloorModOptions: FloorModOptions.FloorModOptions, |
| 285 | BuiltinOptions.RangeOptions: RangeOptions.RangeOptions, |
| 286 | BuiltinOptions.ResizeNearestNeighborOptions: ResizeNearestNeighborOptions.ResizeNearestNeighborOptions, |
| 287 | BuiltinOptions.LeakyReluOptions: LeakyReluOptions.LeakyReluOptions, |
| 288 | BuiltinOptions.SquaredDifferenceOptions: SquaredDifferenceOptions.SquaredDifferenceOptions, |
| 289 | BuiltinOptions.MirrorPadOptions: MirrorPadOptions.MirrorPadOptions, |
| 290 | BuiltinOptions.AbsOptions: AbsOptions.AbsOptions, |
| 291 | BuiltinOptions.SplitVOptions: SplitVOptions.SplitVOptions, |
| 292 | BuiltinOptions.UniqueOptions: UniqueOptions.UniqueOptions, |
| 293 | BuiltinOptions.ReverseV2Options: ReverseV2Options.ReverseV2Options, |
| 294 | BuiltinOptions.AddNOptions: AddNOptions.AddNOptions, |
| 295 | BuiltinOptions.GatherNdOptions: GatherNdOptions.GatherNdOptions, |
| 296 | BuiltinOptions.CosOptions: CosOptions.CosOptions, |
| 297 | BuiltinOptions.WhereOptions: WhereOptions.WhereOptions, |
| 298 | BuiltinOptions.RankOptions: RankOptions.RankOptions, |
| 299 | BuiltinOptions.ReverseSequenceOptions: ReverseSequenceOptions.ReverseSequenceOptions, |
| 300 | BuiltinOptions.MatrixDiagOptions: MatrixDiagOptions.MatrixDiagOptions, |
| 301 | BuiltinOptions.QuantizeOptions: QuantizeOptions.QuantizeOptions, |
| 302 | BuiltinOptions.MatrixSetDiagOptions: MatrixSetDiagOptions.MatrixSetDiagOptions, |
| 303 | BuiltinOptions.DensifyOptions: DensifyOptions.DensifyOptions, |
| 304 | BuiltinOptions.DepthToSpaceOptions: DepthToSpaceOptions.DepthToSpaceOptions, |
Louis Verhaard | 678645b | 2020-06-15 15:22:47 +0200 | [diff] [blame] | 305 | BuiltinOptions.HardSwishOptions: HardSwishOptions.HardSwishOptions, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 306 | BuiltinOptions.IfOptions: IfOptions.IfOptions, |
| 307 | BuiltinOptions.NonMaxSuppressionV4Options: NonMaxSuppressionV4Options.NonMaxSuppressionV4Options, |
| 308 | BuiltinOptions.NonMaxSuppressionV5Options: NonMaxSuppressionV5Options.NonMaxSuppressionV5Options, |
| 309 | BuiltinOptions.ScatterNdOptions: ScatterNdOptions.ScatterNdOptions, |
| 310 | BuiltinOptions.SegmentSumOptions: SegmentSumOptions.SegmentSumOptions, |
| 311 | BuiltinOptions.SelectV2Options: SelectV2Options.SelectV2Options, |
| 312 | BuiltinOptions.WhileOptions: WhileOptions.WhileOptions, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 313 | BuiltinOptions.BatchMatMulOptions: BatchMatMulOptions.BatchMatMulOptions, |
Tim Hall | 42abec1 | 2021-02-04 21:31:57 +0000 | [diff] [blame] | 314 | BuiltinOptions.CumsumOptions: CumsumOptions.CumsumOptions, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 315 | BuiltinOptions.CallOnceOptions: CallOnceOptions.CallOnceOptions, |
| 316 | BuiltinOptions.BroadcastToOptions: BroadcastToOptions.BroadcastToOptions, |
| 317 | BuiltinOptions.Rfft2dOptions: Rfft2dOptions.Rfft2dOptions, |
| 318 | BuiltinOptions.Conv3DOptions: Conv3DOptions.Conv3DOptions, |
| 319 | BuiltinOptions.HashtableOptions: HashtableOptions.HashtableOptions, |
| 320 | BuiltinOptions.HashtableFindOptions: HashtableFindOptions.HashtableFindOptions, |
| 321 | BuiltinOptions.HashtableImportOptions: HashtableImportOptions.HashtableImportOptions, |
| 322 | BuiltinOptions.HashtableSizeOptions: HashtableSizeOptions.HashtableSizeOptions, |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 323 | BuiltinOptions.VarHandleOptions: VarHandleOptions.VarHandleOptions, |
| 324 | BuiltinOptions.ReadVariableOptions: ReadVariableOptions.ReadVariableOptions, |
| 325 | BuiltinOptions.AssignVariableOptions: AssignVariableOptions.AssignVariableOptions, |
| 326 | BuiltinOptions.RandomOptions: RandomOptions.RandomOptions, |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 327 | BuiltinOptions.BucketizeOptions: BucketizeOptions.BucketizeOptions, |
| 328 | BuiltinOptions.DynamicUpdateSliceOptions: DynamicUpdateSliceOptions.DynamicUpdateSliceOptions, |
| 329 | BuiltinOptions.GeluOptions: GeluOptions.GeluOptions, |
erik.andersson@arm.com | dd49a72 | 2022-08-10 15:26:48 +0200 | [diff] [blame] | 330 | BuiltinOptions.UnsortedSegmentProdOptions: UnsortedSegmentProdOptions.UnsortedSegmentProdOptions, |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 331 | BuiltinOptions.UnsortedSegmentMaxOptions: UnsortedSegmentMaxOptions.UnsortedSegmentMaxOptions, |
| 332 | BuiltinOptions.UnsortedSegmentMinOptions: UnsortedSegmentMinOptions.UnsortedSegmentMinOptions, |
| 333 | BuiltinOptions.UnsortedSegmentSumOptions: UnsortedSegmentSumOptions.UnsortedSegmentSumOptions, |
| 334 | BuiltinOptions.ATan2Options: ATan2Options.ATan2Options, |
| 335 | BuiltinOptions.SignOptions: SignOptions.SignOptions, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 338 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 339 | builtin_options_inv_map = inverse_map(builtin_options_map) |
| 340 | |
| 341 | |
| 342 | def underscore_to_camel_case(s): |
| 343 | return "".join(x.title() for x in s.split("_")) |
| 344 | |
| 345 | |
| 346 | def padding_deserialize(x): |
| 347 | return padding_map[x] |
| 348 | |
| 349 | |
| 350 | def padding_serialize(builder, x): |
| 351 | return padding_inv_map[x] |
| 352 | |
| 353 | |
| 354 | def activation_deserialize(x): |
| 355 | return activation_function_map[x] |
| 356 | |
| 357 | |
| 358 | def activation_serialize(builder, x): |
| 359 | return activation_function_inv_map[x] |
| 360 | |
| 361 | |
| 362 | def datatype_deserialize(x): |
| 363 | return datatype_map[x] |
| 364 | |
| 365 | |
| 366 | def datatype_serialize(builder, x): |
| 367 | return datatype_inv_map[x] |
| 368 | |
| 369 | |
| 370 | def identity(x): |
| 371 | return x |
| 372 | |
| 373 | |
| 374 | def identity_serialize(builder, x): |
| 375 | return x |
| 376 | |
| 377 | |
| 378 | def write_byte_vector(builder, v): |
| 379 | builder.StartVector(1, len(v), 1) |
| 380 | for e in v[::-1]: |
| 381 | builder.PrependByte(e) |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 382 | return builder.EndVector() |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 383 | |
| 384 | |
| 385 | def write_int_vector(builder, v): |
| 386 | builder.StartVector(4, len(v), 4) |
| 387 | for e in v[::-1]: |
| 388 | builder.PrependInt32(e) |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 389 | return builder.EndVector() |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 390 | |
| 391 | |
| 392 | class OptionsSerializer: |
Michael McGeagh | 6f72526 | 2020-12-03 15:21:36 +0000 | [diff] [blame] | 393 | def __init__(self, name, members=None): |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 394 | self.name = name |
| 395 | self.module = globals()[self.name] |
| 396 | self.cls = getattr(self.module, self.name) |
| 397 | self.builtin_opt_type = builtin_options_inv_map[self.cls] |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 398 | self.members = [] |
Michael McGeagh | 6f72526 | 2020-12-03 15:21:36 +0000 | [diff] [blame] | 399 | if members is not None: |
| 400 | for mem in members: |
| 401 | deserialize = identity |
| 402 | serialize = identity_serialize |
| 403 | is_vector = False |
| 404 | if isinstance(mem, tuple): |
| 405 | if len(mem) == 3: |
| 406 | mem, deserialize, serialize = mem |
| 407 | elif len(mem) == 2: |
| 408 | mem, is_vector = mem |
| 409 | deserialize = tuple |
| 410 | serialize = write_int_vector |
| 411 | else: |
| 412 | assert 0 |
| 413 | underscore_mem = mem |
| 414 | camelcase_mem = underscore_to_camel_case(mem) |
| 415 | self.members.append((underscore_mem, camelcase_mem, deserialize, serialize, is_vector)) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 416 | |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 417 | def deserialize(self, op_data): |
| 418 | builtin_options = op_data.BuiltinOptions() |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 419 | attrs = {} |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 420 | if builtin_options: |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 421 | tfattrs = self.cls() |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 422 | tfattrs.Init(builtin_options.Bytes, builtin_options.Pos) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 423 | for underscore_mem, camelcase_mem, deserialize, serialize, is_vector in self.members: |
| 424 | fun = camelcase_mem |
| 425 | if is_vector: |
| 426 | fun += "AsNumpy" |
| 427 | |
Fredrik Svedberg | 4bb989b | 2020-11-16 15:32:25 +0100 | [diff] [blame] | 428 | attr = getattr(tfattrs, fun)() |
| 429 | try: |
| 430 | attrs[underscore_mem] = deserialize(attr) |
| 431 | except TypeError: |
| 432 | print("Warning: {0} could not read attribute '{1}'.".format(self.name, underscore_mem)) |
| 433 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 434 | return attrs |
| 435 | |
| 436 | def serialize(self, builder, attrs): |
| 437 | ser_attrs = [] |
| 438 | for underscore_mem, camelcase_mem, deserialize, serialize, is_vector in self.members: |
| 439 | a = serialize(builder, attrs[underscore_mem]) |
| 440 | ser_attrs.append((camelcase_mem, a)) |
| 441 | |
| 442 | getattr(self.module, self.name + "Start")(builder) |
| 443 | |
| 444 | for camelcase_mem, a in ser_attrs: |
| 445 | getattr(self.module, self.name + "Add" + camelcase_mem)(builder, a) |
| 446 | |
| 447 | return getattr(self.module, self.name + "End")(builder), None |
| 448 | |
| 449 | |
| 450 | class CustomOptionsSerializer: |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 451 | CUSTOM_OPTIONS_NPU_OP = [0x01, 0x04, 0x01] # NpuOp=1, FlexbufferFormat.UINT8=4, byte length=1 |
| 452 | CUSTOM_OPTIONS_FORMAT_DEFAULT = 0 |
| 453 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 454 | def __init__(self): |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 455 | self.custom_opt_format = 0 |
| 456 | |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 457 | def deserialize(self, op_data): |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 458 | attrs = {} |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 459 | custom_options = op_data.CustomOptionsAsNumpy() |
| 460 | attrs["custom_options"] = custom_options |
| 461 | attrs["custom_options_format"] = op_data.CustomOptionsFormat() |
| 462 | |
| 463 | if np.array_equal(custom_options, self.CUSTOM_OPTIONS_NPU_OP): |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 464 | attrs["custom_type"] = CustomType.ExistingNpuOp |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 465 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 466 | return attrs |
| 467 | |
| 468 | def serialize(self, builder, attrs): |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 469 | custom_type = attrs.get("custom_type", CustomType.ThirdPartyOp) |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 470 | self.custom_opt_format = attrs.get("custom_options_format", self.CUSTOM_OPTIONS_FORMAT_DEFAULT) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 471 | |
| 472 | # Set NPU op custom options for the TensorFlow Lite custom operator |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 473 | if custom_type == CustomType.NpuOp: |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 474 | custom_options = self.CUSTOM_OPTIONS_NPU_OP |
| 475 | else: |
| 476 | custom_options = attrs.get("custom_options", []) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 477 | |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 478 | custom_options_bytes = struct.pack("<{0}B".format(len(custom_options)), *custom_options) |
| 479 | custom_offset = write_byte_vector(builder, custom_options_bytes) |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 480 | |
| 481 | return None, custom_offset |
| 482 | |
| 483 | |
| 484 | padding_map = { |
Michael McGeagh | 1689548 | 2020-12-14 15:51:20 +0000 | [diff] [blame] | 485 | Padding.SAME: opPad.SAME, |
| 486 | Padding.VALID: opPad.VALID, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | padding_inv_map = inverse_map(padding_map) |
| 490 | |
| 491 | |
| 492 | activation_function_map = { |
| 493 | ActivationFunctionType.NONE: None, |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 494 | ActivationFunctionType.RELU: Op.Relu, |
| 495 | ActivationFunctionType.RELU_N1_TO_1: Op.ReluN1To1, |
| 496 | ActivationFunctionType.RELU6: Op.Relu6, |
| 497 | ActivationFunctionType.TANH: Op.Tanh, |
| 498 | ActivationFunctionType.SIGN_BIT: Op.SignBit, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | activation_function_inv_map = inverse_map(activation_function_map) |
| 502 | |
| 503 | fused_act = ("fused_activation_function", activation_deserialize, activation_serialize) |
| 504 | padding = ("padding", padding_deserialize, padding_serialize) |
| 505 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 506 | is_int_vec = True |
| 507 | |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 508 | TFLITE_NO_INDICES = TensorIndices([], [], []) |
| 509 | TFLITE_IFM_INDICES = TensorIndices([0], [], []) |
| 510 | TFLITE_IFM_WEIGHTS_INDICES = TensorIndices([0], [1], []) |
| 511 | TFLITE_IFM_WEIGHTS_BIAS_INDICES = TensorIndices([0], [1], [2]) |
| 512 | TFLITE_IFM_IFM2_INDICES = TensorIndices([0, 1], [], []) |
| 513 | TFLITE_CONV2D_BACKPROP_INDICES = TensorIndices([2], [1], [3]) |
| 514 | TFLITE_TRANSPOSE_CONV_INDICES = TensorIndices([0], [1], [3]) |
| 515 | TFLITE_CONCAT_INDICES = TensorIndices([1, 2], [], []) |
| 516 | TFLITE_SPLIT_IFM_INDICES = TensorIndices([1], [], []) |
| 517 | TFLITE_BLOCK_LSTM_INDICES = TensorIndices([3], [4], []) |
| 518 | |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 519 | builtin_operator_map = { |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 520 | BuiltinOperator.ADD: ( |
| 521 | Op.Add, |
| 522 | OptionsSerializer("AddOptions", (fused_act, "pot_scale_int16")), |
| 523 | TFLITE_IFM_IFM2_INDICES, |
| 524 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 525 | BuiltinOperator.AVERAGE_POOL_2D: ( |
| 526 | Op.AvgPool, |
| 527 | OptionsSerializer( |
| 528 | "Pool2DOptions", ("filter_height", "filter_width", fused_act, padding, "stride_h", "stride_w") |
| 529 | ), |
| 530 | TFLITE_IFM_INDICES, |
| 531 | ), |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 532 | BuiltinOperator.ATAN2: (Op.Atan2, OptionsSerializer("ATan2Options", ()), TFLITE_IFM_IFM2_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 533 | BuiltinOperator.CONCATENATION: ( |
| 534 | Op.ConcatTFLite, |
| 535 | OptionsSerializer("ConcatenationOptions", ("axis", fused_act)), |
| 536 | TFLITE_CONCAT_INDICES, |
| 537 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 538 | BuiltinOperator.CONV_2D: ( |
| 539 | Op.Conv2DBias, |
| 540 | OptionsSerializer( |
| 541 | "Conv2DOptions", ("dilation_h_factor", "dilation_w_factor", fused_act, padding, "stride_h", "stride_w") |
| 542 | ), |
| 543 | TFLITE_IFM_WEIGHTS_BIAS_INDICES, |
| 544 | ), |
| 545 | BuiltinOperator.DEPTHWISE_CONV_2D: ( |
| 546 | Op.DepthwiseConv2DBias, |
| 547 | OptionsSerializer( |
| 548 | "DepthwiseConv2DOptions", |
| 549 | ("depth_multiplier", "dilation_h_factor", "dilation_w_factor", fused_act, padding, "stride_h", "stride_w"), |
| 550 | ), |
| 551 | TFLITE_IFM_WEIGHTS_BIAS_INDICES, |
| 552 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 553 | BuiltinOperator.DEPTH_TO_SPACE: ( |
| 554 | Op.DepthToSpace, |
| 555 | OptionsSerializer("DepthToSpaceOptions", ("block_size",)), |
| 556 | TFLITE_NO_INDICES, |
| 557 | ), |
| 558 | BuiltinOperator.DEQUANTIZE: (Op.Dequantize, OptionsSerializer("DequantizeOptions"), TFLITE_IFM_INDICES), |
| 559 | BuiltinOperator.EMBEDDING_LOOKUP: (Op.EmbeddingLookup, None, TFLITE_NO_INDICES), |
| 560 | BuiltinOperator.FLOOR: (Op.Floor, None, TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 561 | BuiltinOperator.FULLY_CONNECTED: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 562 | Op.FullyConnected, |
erik.andersson@arm.com | 0cbb166 | 2021-02-22 15:47:07 +0100 | [diff] [blame] | 563 | OptionsSerializer( |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 564 | "FullyConnectedOptions", ("asymmetric_quantize_inputs", fused_act, "keep_num_dims", "weights_format") |
erik.andersson@arm.com | 0cbb166 | 2021-02-22 15:47:07 +0100 | [diff] [blame] | 565 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 566 | TFLITE_IFM_WEIGHTS_BIAS_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 567 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 568 | BuiltinOperator.HASHTABLE_LOOKUP: (Op.HashtableLookup, None, TFLITE_NO_INDICES), |
| 569 | BuiltinOperator.L2_NORMALIZATION: (Op.L2Norm, OptionsSerializer("L2NormOptions", (fused_act,)), TFLITE_NO_INDICES), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 570 | BuiltinOperator.L2_POOL_2D: ( |
| 571 | Op.L2Pool2D, |
| 572 | OptionsSerializer( |
| 573 | "Pool2DOptions", ("filter_height", "filter_width", fused_act, padding, "stride_h", "stride_w") |
| 574 | ), |
| 575 | TFLITE_NO_INDICES, |
| 576 | ), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 577 | BuiltinOperator.LOCAL_RESPONSE_NORMALIZATION: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 578 | Op.LRN, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 579 | OptionsSerializer("LocalResponseNormalizationOptions", ("alpha", "beta", "bias", "radius")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 580 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 581 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 582 | BuiltinOperator.LOGISTIC: (Op.Sigmoid, None, TFLITE_IFM_INDICES), |
| 583 | BuiltinOperator.LSH_PROJECTION: ( |
| 584 | Op.LSHProjection, |
| 585 | OptionsSerializer("LSHProjectionOptions", ("type",)), |
| 586 | TFLITE_NO_INDICES, |
| 587 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 588 | BuiltinOperator.LSTM: ( |
| 589 | Op.Lstm, |
| 590 | OptionsSerializer( |
| 591 | "LSTMOptions", ("asymmetric_quantize_inputs", "cell_clip", fused_act, "kernel_type", "proj_clip") |
| 592 | ), |
| 593 | TFLITE_IFM_WEIGHTS_INDICES, |
| 594 | ), |
| 595 | BuiltinOperator.MAX_POOL_2D: ( |
| 596 | Op.MaxPool, |
| 597 | OptionsSerializer( |
| 598 | "Pool2DOptions", ("filter_height", "filter_width", fused_act, padding, "stride_h", "stride_w") |
| 599 | ), |
| 600 | TFLITE_IFM_INDICES, |
| 601 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 602 | BuiltinOperator.MUL: (Op.Mul, OptionsSerializer("MulOptions", (fused_act,)), TFLITE_IFM_IFM2_INDICES), |
| 603 | BuiltinOperator.RELU: (Op.Relu, None, TFLITE_IFM_INDICES), |
erik.andersson@arm.com | dd49a72 | 2022-08-10 15:26:48 +0200 | [diff] [blame] | 604 | BuiltinOperator.RELU_0_TO_1: (Op.Relu0To1, None, TFLITE_IFM_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 605 | BuiltinOperator.RELU_N1_TO_1: (Op.ReluN1To1, None, TFLITE_IFM_INDICES), |
| 606 | BuiltinOperator.RELU6: (Op.Relu6, None, TFLITE_IFM_INDICES), |
| 607 | BuiltinOperator.RESHAPE: ( |
| 608 | Op.Reshape, |
Dwight Lidman | cfb4262 | 2021-08-11 12:28:51 +0200 | [diff] [blame] | 609 | OptionsSerializer("ReshapeOptions", (("new_shape", is_int_vec),)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 610 | TFLITE_IFM_INDICES, |
| 611 | ), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 612 | BuiltinOperator.RESIZE_BILINEAR: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 613 | Op.ResizeBilinear, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 614 | OptionsSerializer("ResizeBilinearOptions", ("align_corners", "half_pixel_centers")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 615 | TFLITE_IFM_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 616 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 617 | BuiltinOperator.RNN: ( |
| 618 | Op.Rnn, |
| 619 | OptionsSerializer("RNNOptions", ("asymmetric_quantize_inputs", fused_act)), |
| 620 | TFLITE_IFM_WEIGHTS_INDICES, |
| 621 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 622 | BuiltinOperator.SOFTMAX: (Op.Softmax, OptionsSerializer("SoftmaxOptions", ("beta",)), TFLITE_IFM_INDICES), |
| 623 | BuiltinOperator.SPACE_TO_DEPTH: ( |
| 624 | Op.SpaceToDepth, |
| 625 | OptionsSerializer("SpaceToDepthOptions", ("block_size",)), |
| 626 | TFLITE_NO_INDICES, |
| 627 | ), |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 628 | BuiltinOperator.SVDF: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 629 | Op.Svdf, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 630 | OptionsSerializer("SVDFOptions", ("asymmetric_quantize_inputs", fused_act, "rank")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 631 | TFLITE_NO_INDICES, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 632 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 633 | BuiltinOperator.TANH: (Op.Tanh, None, TFLITE_IFM_INDICES), |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 634 | BuiltinOperator.CONCAT_EMBEDDINGS: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 635 | Op.ConcatEmbeddings, |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 636 | OptionsSerializer( |
| 637 | "ConcatEmbeddingsOptions", |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 638 | ( |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 639 | "embedding_dim_per_channel", |
| 640 | "embedding_dim_per_channel_as_numpy", |
| 641 | "embedding_dim_per_channel_is_none", |
| 642 | "embedding_dim_per_channel_length", |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 643 | "num_channels", |
| 644 | "num_columns_per_channel", |
| 645 | "num_columns_per_channel_as_numpy", |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 646 | "num_columns_per_channel_is_none", |
| 647 | "num_columns_per_channel_length", |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 648 | ), |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 649 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 650 | TFLITE_NO_INDICES, |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 651 | ), |
| 652 | BuiltinOperator.SKIP_GRAM: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 653 | Op.SkipGram, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 654 | OptionsSerializer("SkipGramOptions", ("include_all_ngrams", "max_skip_size", "ngram_size")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 655 | TFLITE_NO_INDICES, |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 656 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 657 | BuiltinOperator.CALL: (Op.Call, OptionsSerializer("CallOptions", ("subgraph",)), TFLITE_NO_INDICES), |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 658 | BuiltinOperator.EMBEDDING_LOOKUP_SPARSE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 659 | Op.EmbeddingLookupSparse, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 660 | OptionsSerializer("EmbeddingLookupSparseOptions", ("combiner",)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 661 | TFLITE_NO_INDICES, |
Dwight Lidman | d2a972d | 2020-08-18 14:08:10 +0200 | [diff] [blame] | 662 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 663 | BuiltinOperator.PAD: (Op.Pad, OptionsSerializer("PadOptions"), TFLITE_IFM_INDICES), |
| 664 | BuiltinOperator.UNIDIRECTIONAL_SEQUENCE_RNN: ( |
| 665 | Op.UnidirectionalSequenceRnn, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 666 | OptionsSerializer("SequenceRNNOptions", ("asymmetric_quantize_inputs", fused_act, "time_major")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 667 | TFLITE_IFM_WEIGHTS_INDICES, |
| 668 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 669 | BuiltinOperator.GATHER: ( |
| 670 | Op.GatherV2, |
| 671 | OptionsSerializer("GatherOptions", ("axis", "batch_dims")), |
| 672 | TFLITE_NO_INDICES, |
| 673 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 674 | BuiltinOperator.BATCH_TO_SPACE_ND: ( |
| 675 | Op.BatchToSpaceND, |
| 676 | OptionsSerializer("BatchToSpaceNDOptions"), |
| 677 | TFLITE_NO_INDICES, |
| 678 | ), |
| 679 | BuiltinOperator.SPACE_TO_BATCH_ND: ( |
| 680 | Op.SpaceToBatchND, |
| 681 | OptionsSerializer("SpaceToBatchNDOptions"), |
| 682 | TFLITE_NO_INDICES, |
| 683 | ), |
James Ward | 6bf1613 | 2021-09-08 11:14:20 +0100 | [diff] [blame] | 684 | BuiltinOperator.TRANSPOSE: (Op.Transpose, OptionsSerializer("TransposeOptions"), TFLITE_IFM_IFM2_INDICES), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 685 | BuiltinOperator.MEAN: (Op.Mean, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_IFM_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 686 | BuiltinOperator.SUB: ( |
| 687 | Op.Sub, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 688 | OptionsSerializer("SubOptions", (fused_act, "pot_scale_int16")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 689 | TFLITE_IFM_IFM2_INDICES, |
| 690 | ), |
| 691 | BuiltinOperator.DIV: (Op.Div, OptionsSerializer("DivOptions", (fused_act,)), TFLITE_NO_INDICES), |
| 692 | BuiltinOperator.SQUEEZE: ( |
| 693 | Op.Squeeze, |
Jonas Ohlsson | d857507 | 2022-03-30 10:30:25 +0200 | [diff] [blame] | 694 | OptionsSerializer( |
| 695 | "SqueezeOptions", |
| 696 | (("squeeze_dims", is_int_vec),), |
| 697 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 698 | TFLITE_IFM_INDICES, |
| 699 | ), |
| 700 | BuiltinOperator.UNIDIRECTIONAL_SEQUENCE_LSTM: ( |
| 701 | Op.UnidirectionalSequenceLstm, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 702 | OptionsSerializer( |
| 703 | "UnidirectionalSequenceLSTMOptions", |
| 704 | ("asymmetric_quantize_inputs", "cell_clip", fused_act, "proj_clip", "time_major"), |
| 705 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 706 | TFLITE_IFM_WEIGHTS_INDICES, |
| 707 | ), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 708 | BuiltinOperator.STRIDED_SLICE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 709 | Op.StridedSlice, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 710 | OptionsSerializer( |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 711 | "StridedSliceOptions", ("begin_mask", "ellipsis_mask", "end_mask", "new_axis_mask", "shrink_axis_mask") |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 712 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 713 | TFLITE_IFM_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 714 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 715 | BuiltinOperator.BIDIRECTIONAL_SEQUENCE_RNN: ( |
| 716 | Op.BidirectionalSequenceRnn, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 717 | OptionsSerializer( |
| 718 | "BidirectionalSequenceRNNOptions", ("asymmetric_quantize_inputs", fused_act, "merge_outputs", "time_major") |
| 719 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 720 | TFLITE_IFM_WEIGHTS_INDICES, |
| 721 | ), |
James Ward | 6bf1613 | 2021-09-08 11:14:20 +0100 | [diff] [blame] | 722 | BuiltinOperator.EXP: (Op.Exp, OptionsSerializer("ExpOptions"), TFLITE_NO_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 723 | BuiltinOperator.TOPK_V2: (Op.TopKV2, OptionsSerializer("TopKV2Options"), TFLITE_NO_INDICES), |
| 724 | BuiltinOperator.SPLIT: (Op.Split, OptionsSerializer("SplitOptions", ("num_splits",)), TFLITE_SPLIT_IFM_INDICES), |
| 725 | BuiltinOperator.LOG_SOFTMAX: (Op.LogSoftmax, OptionsSerializer("LogSoftmaxOptions"), TFLITE_NO_INDICES), |
| 726 | BuiltinOperator.DELEGATE: (Op.Delegate, None, TFLITE_NO_INDICES), |
| 727 | BuiltinOperator.BIDIRECTIONAL_SEQUENCE_LSTM: ( |
| 728 | Op.BidirectionalSequenceLstm, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 729 | OptionsSerializer( |
| 730 | "BidirectionalSequenceLSTMOptions", |
| 731 | ("asymmetric_quantize_inputs", "cell_clip", fused_act, "merge_outputs", "proj_clip", "time_major"), |
| 732 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 733 | TFLITE_IFM_WEIGHTS_INDICES, |
| 734 | ), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 735 | BuiltinOperator.CAST: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 736 | Op.Cast, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 737 | OptionsSerializer( |
| 738 | "CastOptions", |
| 739 | ( |
| 740 | ("in_data_type", datatype_deserialize, datatype_serialize), |
| 741 | ("out_data_type", datatype_deserialize, datatype_serialize), |
| 742 | ), |
| 743 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 744 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 745 | ), |
Fredrik Svedberg | 8ddd489 | 2022-08-19 16:06:04 +0200 | [diff] [blame] | 746 | BuiltinOperator.PRELU: (Op.Prelu, None, TFLITE_IFM_IFM2_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 747 | BuiltinOperator.MAXIMUM: (Op.Maximum, OptionsSerializer("MaximumMinimumOptions"), TFLITE_IFM_IFM2_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 748 | BuiltinOperator.ARG_MAX: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 749 | Op.ArgMax, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 750 | OptionsSerializer("ArgMaxOptions", (("output_type", datatype_deserialize, datatype_serialize),)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 751 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 752 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 753 | BuiltinOperator.MINIMUM: (Op.Minimum, OptionsSerializer("MaximumMinimumOptions"), TFLITE_IFM_IFM2_INDICES), |
| 754 | BuiltinOperator.LESS: (Op.Less, OptionsSerializer("LessOptions"), TFLITE_NO_INDICES), |
| 755 | BuiltinOperator.NEG: (Op.Neg, OptionsSerializer("NegOptions"), TFLITE_NO_INDICES), |
| 756 | BuiltinOperator.PADV2: (Op.PadV2, OptionsSerializer("PadV2Options"), TFLITE_NO_INDICES), |
| 757 | BuiltinOperator.GREATER: (Op.Greater, OptionsSerializer("GreaterOptions"), TFLITE_NO_INDICES), |
| 758 | BuiltinOperator.GREATER_EQUAL: (Op.GreaterEqual, OptionsSerializer("GreaterEqualOptions"), TFLITE_NO_INDICES), |
| 759 | BuiltinOperator.LESS_EQUAL: (Op.LessEqual, OptionsSerializer("LessEqualOptions"), TFLITE_NO_INDICES), |
| 760 | BuiltinOperator.SELECT: (Op.Select, OptionsSerializer("SelectOptions"), TFLITE_NO_INDICES), |
| 761 | BuiltinOperator.SLICE: (Op.Slice, OptionsSerializer("SliceOptions"), TFLITE_IFM_INDICES), |
| 762 | BuiltinOperator.SIN: (Op.Sin, None, TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 763 | BuiltinOperator.TRANSPOSE_CONV: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 764 | Op.Conv2DBackpropInput, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 765 | OptionsSerializer("TransposeConvOptions", (padding, "stride_h", "stride_w")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 766 | TFLITE_CONV2D_BACKPROP_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 767 | ), |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 768 | BuiltinOperator.SIGN: (Op.Sign, OptionsSerializer("SignOptions"), TFLITE_IFM_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 769 | BuiltinOperator.SPARSE_TO_DENSE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 770 | Op.SparseToDense, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 771 | OptionsSerializer("SparseToDenseOptions", ("validate_indices",)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 772 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 773 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 774 | BuiltinOperator.TILE: (Op.Tile, OptionsSerializer("TileOptions"), TFLITE_NO_INDICES), |
| 775 | BuiltinOperator.EXPAND_DIMS: (Op.ExpandDims, OptionsSerializer("ExpandDimsOptions"), TFLITE_IFM_INDICES), |
| 776 | BuiltinOperator.EQUAL: (Op.Equal, OptionsSerializer("EqualOptions"), TFLITE_NO_INDICES), |
| 777 | BuiltinOperator.NOT_EQUAL: (Op.NotEqual, OptionsSerializer("NotEqualOptions"), TFLITE_NO_INDICES), |
| 778 | BuiltinOperator.LOG: (Op.Log, None, TFLITE_NO_INDICES), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 779 | BuiltinOperator.SUM: (Op.Sum, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 780 | BuiltinOperator.SQRT: (Op.Sqrt, None, TFLITE_NO_INDICES), |
| 781 | BuiltinOperator.RSQRT: (Op.Rsqrt, None, TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 782 | BuiltinOperator.SHAPE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 783 | Op.Shape, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 784 | OptionsSerializer("ShapeOptions", (("out_type", datatype_deserialize, datatype_serialize),)), |
Ayaan Masood | 4965fae | 2022-06-29 11:30:57 +0100 | [diff] [blame] | 785 | TFLITE_IFM_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 786 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 787 | BuiltinOperator.POW: (Op.Pow, OptionsSerializer("PowOptions"), TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 788 | BuiltinOperator.ARG_MIN: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 789 | Op.ArgMin, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 790 | OptionsSerializer("ArgMinOptions", (("output_type", datatype_deserialize, datatype_serialize),)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 791 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 792 | ), |
| 793 | BuiltinOperator.FAKE_QUANT: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 794 | Op.FakeQuantWithMinMaxArgs, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 795 | OptionsSerializer("FakeQuantOptions", ("max", "min", "narrow_range", "num_bits")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 796 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 797 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 798 | BuiltinOperator.REDUCE_PROD: (Op.Prod, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
| 799 | BuiltinOperator.REDUCE_MAX: (Op.Max, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
| 800 | BuiltinOperator.PACK: (Op.Pack, OptionsSerializer("PackOptions", ("axis", "values_count")), TFLITE_IFM_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 801 | BuiltinOperator.LOGICAL_OR: (Op.LogicalOr, OptionsSerializer("LogicalOrOptions"), TFLITE_NO_INDICES), |
| 802 | BuiltinOperator.ONE_HOT: (Op.OneHot, OptionsSerializer("OneHotOptions", ("axis",)), TFLITE_NO_INDICES), |
| 803 | BuiltinOperator.LOGICAL_AND: (Op.LogicalAnd, OptionsSerializer("LogicalAndOptions"), TFLITE_NO_INDICES), |
| 804 | BuiltinOperator.LOGICAL_NOT: (Op.LogicalNot, OptionsSerializer("LogicalNotOptions"), TFLITE_NO_INDICES), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 805 | BuiltinOperator.UNPACK: (Op.Unpack, OptionsSerializer("UnpackOptions", ("axis", "num")), TFLITE_IFM_INDICES), |
| 806 | BuiltinOperator.REDUCE_MIN: (Op.Min, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 807 | BuiltinOperator.FLOOR_DIV: (Op.FloorDiv, OptionsSerializer("FloorDivOptions"), TFLITE_NO_INDICES), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 808 | BuiltinOperator.REDUCE_ANY: (Op.Any, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 809 | BuiltinOperator.SQUARE: (Op.Square, OptionsSerializer("SquareOptions"), TFLITE_NO_INDICES), |
| 810 | BuiltinOperator.ZEROS_LIKE: (Op.ZerosLike, OptionsSerializer("ZerosLikeOptions"), TFLITE_NO_INDICES), |
| 811 | BuiltinOperator.FILL: (Op.Fill, OptionsSerializer("FillOptions"), TFLITE_NO_INDICES), |
| 812 | BuiltinOperator.FLOOR_MOD: (Op.FloorMod, OptionsSerializer("FloorModOptions"), TFLITE_NO_INDICES), |
| 813 | BuiltinOperator.RANGE: (Op.Range, OptionsSerializer("RangeOptions"), TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 814 | BuiltinOperator.RESIZE_NEAREST_NEIGHBOR: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 815 | Op.ResizeNearestNeighbor, |
Jacob Bohlin | 8daf6b7 | 2020-09-15 16:28:35 +0200 | [diff] [blame] | 816 | OptionsSerializer("ResizeNearestNeighborOptions", ("align_corners", "half_pixel_centers")), |
Tim Hall | 885033b | 2022-07-21 11:46:03 +0100 | [diff] [blame] | 817 | TFLITE_IFM_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 818 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 819 | BuiltinOperator.LEAKY_RELU: (Op.LeakyRelu, OptionsSerializer("LeakyReluOptions", ("alpha",)), TFLITE_IFM_INDICES), |
| 820 | BuiltinOperator.SQUARED_DIFFERENCE: ( |
| 821 | Op.SquaredDifference, |
| 822 | OptionsSerializer("SquaredDifferenceOptions"), |
| 823 | TFLITE_NO_INDICES, |
| 824 | ), |
| 825 | BuiltinOperator.MIRROR_PAD: (Op.MirrorPad, OptionsSerializer("MirrorPadOptions", ("mode",)), TFLITE_NO_INDICES), |
| 826 | BuiltinOperator.ABS: (Op.Abs, OptionsSerializer("AbsOptions"), TFLITE_IFM_INDICES), |
| 827 | BuiltinOperator.SPLIT_V: (Op.SplitV, OptionsSerializer("SplitVOptions", ("num_splits",)), TFLITE_IFM_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 828 | BuiltinOperator.UNIQUE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 829 | Op.Unique, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 830 | OptionsSerializer("UniqueOptions", (("idx_out_type", datatype_deserialize, datatype_serialize),)), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 831 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 832 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 833 | BuiltinOperator.CEIL: (Op.Ceil, None, TFLITE_NO_INDICES), |
| 834 | BuiltinOperator.REVERSE_V2: (Op.ReverseV2, OptionsSerializer("ReverseV2Options"), TFLITE_NO_INDICES), |
| 835 | BuiltinOperator.ADD_N: (Op.AddN, OptionsSerializer("AddNOptions"), TFLITE_NO_INDICES), |
| 836 | BuiltinOperator.GATHER_ND: (Op.GatherNd, OptionsSerializer("GatherNdOptions"), TFLITE_NO_INDICES), |
| 837 | BuiltinOperator.COS: (Op.Cos, OptionsSerializer("CosOptions"), TFLITE_NO_INDICES), |
| 838 | BuiltinOperator.WHERE: (Op.Where, OptionsSerializer("WhereOptions"), TFLITE_NO_INDICES), |
| 839 | BuiltinOperator.RANK: (Op.Rank, OptionsSerializer("RankOptions"), TFLITE_NO_INDICES), |
| 840 | BuiltinOperator.ELU: (Op.Elu, None, TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 841 | BuiltinOperator.REVERSE_SEQUENCE: ( |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 842 | Op.ReverseSequence, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 843 | OptionsSerializer("ReverseSequenceOptions", ("batch_dim", "seq_dim")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 844 | TFLITE_NO_INDICES, |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 845 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 846 | BuiltinOperator.MATRIX_DIAG: (Op.MatrixDiag, OptionsSerializer("MatrixDiagOptions"), TFLITE_NO_INDICES), |
| 847 | BuiltinOperator.QUANTIZE: (Op.Quantize, OptionsSerializer("QuantizeOptions"), TFLITE_IFM_INDICES), |
| 848 | BuiltinOperator.MATRIX_SET_DIAG: (Op.MatrixSetDiag, OptionsSerializer("MatrixSetDiagOptions"), TFLITE_NO_INDICES), |
| 849 | BuiltinOperator.ROUND: (Op.Round, None, TFLITE_NO_INDICES), |
| 850 | BuiltinOperator.HARD_SWISH: (Op.HardSwish, OptionsSerializer("HardSwishOptions"), TFLITE_IFM_INDICES), |
| 851 | BuiltinOperator.IF: ( |
| 852 | Op.If, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 853 | OptionsSerializer("IfOptions", ("else_subgraph_index", "then_subgraph_index")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 854 | TFLITE_NO_INDICES, |
| 855 | ), |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 856 | BuiltinOperator.WHILE: ( |
| 857 | Op.While, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 858 | OptionsSerializer("WhileOptions", ("body_subgraph_index", "cond_subgraph_index")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 859 | TFLITE_NO_INDICES, |
Louis Verhaard | aee5d75 | 2020-09-30 09:01:52 +0200 | [diff] [blame] | 860 | ), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 861 | BuiltinOperator.NON_MAX_SUPPRESSION_V4: ( |
| 862 | Op.NonMaxSuppressionV4, |
| 863 | OptionsSerializer("NonMaxSuppressionV4Options"), |
| 864 | TFLITE_NO_INDICES, |
| 865 | ), |
| 866 | BuiltinOperator.NON_MAX_SUPPRESSION_V5: ( |
| 867 | Op.NonMaxSuppressionV5, |
| 868 | OptionsSerializer("NonMaxSuppressionV5Options"), |
| 869 | TFLITE_NO_INDICES, |
| 870 | ), |
| 871 | BuiltinOperator.SCATTER_ND: (Op.ScatterNd, OptionsSerializer("ScatterNdOptions"), TFLITE_NO_INDICES), |
| 872 | BuiltinOperator.SELECT_V2: (Op.SelectV2, OptionsSerializer("SelectV2Options"), TFLITE_NO_INDICES), |
| 873 | BuiltinOperator.DENSIFY: (Op.Densify, OptionsSerializer("DensifyOptions"), TFLITE_NO_INDICES), |
| 874 | BuiltinOperator.SEGMENT_SUM: (Op.SegmentSum, OptionsSerializer("SegmentSumOptions"), TFLITE_NO_INDICES), |
| 875 | BuiltinOperator.BATCH_MATMUL: ( |
| 876 | Op.BatchMatMul, |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 877 | OptionsSerializer("BatchMatMulOptions", ("adj_x", "adj_y", "asymmetric_quantize_inputs")), |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 878 | TFLITE_NO_INDICES, |
| 879 | ), |
| 880 | BuiltinOperator.CUMSUM: ( |
| 881 | Op.Cumsum, |
| 882 | OptionsSerializer("CumsumOptions", ("exclusive", "reverse")), |
| 883 | TFLITE_NO_INDICES, |
| 884 | ), |
Dwight Lidman | 8a12da1 | 2021-07-19 13:43:05 +0200 | [diff] [blame] | 885 | BuiltinOperator.CALL_ONCE: ( |
| 886 | Op.CallOnce, |
| 887 | OptionsSerializer("CallOnceOptions", ("init_subgraph_index",)), |
| 888 | TFLITE_NO_INDICES, |
| 889 | ), |
| 890 | BuiltinOperator.BROADCAST_TO: (Op.BroadcastTo, OptionsSerializer("BroadcastToOptions"), TFLITE_NO_INDICES), |
| 891 | BuiltinOperator.RFFT2D: (Op.Rfft2D, OptionsSerializer("Rfft2dOptions"), TFLITE_NO_INDICES), |
| 892 | BuiltinOperator.CONV_3D: ( |
| 893 | Op.Conv3D, |
| 894 | OptionsSerializer( |
| 895 | "Conv3DOptions", |
| 896 | ( |
| 897 | "dilation_d_factor", |
| 898 | "dilation_h_factor", |
| 899 | "dilation_w_factor", |
| 900 | fused_act, |
| 901 | padding, |
| 902 | "stride_d", |
| 903 | "stride_h", |
| 904 | "stride_w", |
| 905 | ), |
| 906 | ), |
| 907 | TFLITE_NO_INDICES, |
| 908 | ), |
| 909 | BuiltinOperator.IMAG: (Op.Imag, None, TFLITE_NO_INDICES), |
| 910 | BuiltinOperator.REAL: (Op.Real, None, TFLITE_NO_INDICES), |
| 911 | BuiltinOperator.COMPLEX_ABS: (Op.ComplexAbs, None, TFLITE_NO_INDICES), |
| 912 | BuiltinOperator.HASHTABLE: ( |
| 913 | Op.Hashtable, |
| 914 | OptionsSerializer("HashtableOptions", ("key_dtype", "table_id", "value_dtype")), |
| 915 | TFLITE_NO_INDICES, |
| 916 | ), |
| 917 | BuiltinOperator.HASHTABLE_FIND: (Op.HashtableFind, OptionsSerializer("HashtableFindOptions"), TFLITE_NO_INDICES), |
| 918 | BuiltinOperator.HASHTABLE_IMPORT: ( |
| 919 | Op.HashtableImport, |
| 920 | OptionsSerializer("HashtableImportOptions"), |
| 921 | TFLITE_NO_INDICES, |
| 922 | ), |
| 923 | BuiltinOperator.HASHTABLE_SIZE: (Op.HashtableSize, OptionsSerializer("HashtableSizeOptions"), TFLITE_NO_INDICES), |
| 924 | BuiltinOperator.REDUCE_ALL: (Op.ReduceAll, OptionsSerializer("ReducerOptions", ("keep_dims",)), TFLITE_NO_INDICES), |
| 925 | BuiltinOperator.CONV_3D_TRANSPOSE: ( |
| 926 | Op.Conv3DTranspose, |
| 927 | OptionsSerializer( |
| 928 | "Conv3DOptions", |
| 929 | ( |
| 930 | "dilation_d_factor", |
| 931 | "dilation_h_factor", |
| 932 | "dilation_w_factor", |
| 933 | fused_act, |
| 934 | padding, |
| 935 | "stride_d", |
| 936 | "stride_h", |
| 937 | "stride_w", |
| 938 | ), |
| 939 | ), |
| 940 | TFLITE_NO_INDICES, |
| 941 | ), |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 942 | BuiltinOperator.VAR_HANDLE: ( |
| 943 | Op.VarHandle, |
Jonas Ohlsson | d857507 | 2022-03-30 10:30:25 +0200 | [diff] [blame] | 944 | OptionsSerializer( |
| 945 | "VarHandleOptions", |
| 946 | ( |
| 947 | "container", |
| 948 | "shared_name", |
| 949 | ), |
| 950 | ), |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 951 | TFLITE_NO_INDICES, |
| 952 | ), |
| 953 | BuiltinOperator.READ_VARIABLE: (Op.ReadVariable, OptionsSerializer("ReadVariableOptions"), TFLITE_NO_INDICES), |
| 954 | BuiltinOperator.ASSIGN_VARIABLE: (Op.AssignVariable, OptionsSerializer("AssignVariableOptions"), TFLITE_NO_INDICES), |
| 955 | BuiltinOperator.BROADCAST_ARGS: (Op.BroadcastArgs, None, TFLITE_NO_INDICES), |
| 956 | BuiltinOperator.RANDOM_STANDARD_NORMAL: ( |
| 957 | Op.RandomStandardNormal, |
Jonas Ohlsson | d857507 | 2022-03-30 10:30:25 +0200 | [diff] [blame] | 958 | OptionsSerializer( |
| 959 | "RandomOptions", |
| 960 | ( |
| 961 | "seed", |
| 962 | "seed2", |
| 963 | ), |
| 964 | ), |
Rickard Bolin | 2de898a | 2021-12-20 08:35:23 +0000 | [diff] [blame] | 965 | TFLITE_NO_INDICES, |
| 966 | ), |
Rickard Bolin | d66f801 | 2022-04-21 07:36:55 +0000 | [diff] [blame] | 967 | BuiltinOperator.BUCKETIZE: ( |
| 968 | Op.Bucketize, |
| 969 | OptionsSerializer( |
| 970 | "BucketizeOptions", |
| 971 | ("boundaries", "boundaries_as_numpy", "boundaries_length", "boundaries_is_none"), |
| 972 | ), |
| 973 | TFLITE_NO_INDICES, |
| 974 | ), |
| 975 | BuiltinOperator.RANDOM_UNIFORM: (Op.RandomUniform, None, TFLITE_NO_INDICES), |
| 976 | BuiltinOperator.MULTINOMIAL: (Op.Multinomial, None, TFLITE_NO_INDICES), |
| 977 | BuiltinOperator.GELU: (Op.Gelu, OptionsSerializer("GeluOptions", ("approximate",)), TFLITE_NO_INDICES), |
| 978 | BuiltinOperator.DYNAMIC_UPDATE_SLICE: ( |
| 979 | Op.DynamicUpdateSlice, |
| 980 | OptionsSerializer("DynamicUpdateSliceOptions"), |
| 981 | TFLITE_NO_INDICES, |
| 982 | ), |
erik.andersson@arm.com | dd49a72 | 2022-08-10 15:26:48 +0200 | [diff] [blame] | 983 | BuiltinOperator.UNSORTED_SEGMENT_PROD: ( |
| 984 | Op.UnsortedSegmentProd, |
erik.andersson@arm.com | 61f05d9 | 2022-09-27 12:06:32 +0200 | [diff] [blame] | 985 | OptionsSerializer("UnsortedSegmentProdOptions"), |
| 986 | TFLITE_NO_INDICES, |
| 987 | ), |
| 988 | BuiltinOperator.UNSORTED_SEGMENT_MAX: ( |
| 989 | Op.UnsortedSegmentMax, |
| 990 | OptionsSerializer("UnsortedSegmentMaxOptions"), |
| 991 | TFLITE_NO_INDICES, |
| 992 | ), |
| 993 | BuiltinOperator.UNSORTED_SEGMENT_MIN: ( |
| 994 | Op.UnsortedSegmentMin, |
| 995 | OptionsSerializer("UnsortedSegmentMinOptions"), |
| 996 | TFLITE_NO_INDICES, |
| 997 | ), |
| 998 | BuiltinOperator.UNSORTED_SEGMENT_SUM: ( |
| 999 | Op.UnsortedSegmentSum, |
| 1000 | OptionsSerializer("UnsortedSegmentSumOptions"), |
erik.andersson@arm.com | dd49a72 | 2022-08-10 15:26:48 +0200 | [diff] [blame] | 1001 | TFLITE_NO_INDICES, |
| 1002 | ), |
Tim Hall | b94bcd4 | 2021-09-07 14:24:51 +0100 | [diff] [blame] | 1003 | BuiltinOperator.CUSTOM: (Op.Custom, CustomOptionsSerializer(), TFLITE_NO_INDICES), |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 1006 | builtin_operator_inv_map = {v[0]: (k, v[1], v[2]) for k, v in builtin_operator_map.items()} |
Tim Hall | 79d07d2 | 2020-04-27 18:20:16 +0100 | [diff] [blame] | 1007 | |
Patrik Gustavsson | 5e26eda | 2021-06-30 09:07:16 +0200 | [diff] [blame] | 1008 | builtin_operator_inv_map[Op.CustomNpuOp] = (BuiltinOperator.CUSTOM, CustomOptionsSerializer(), TFLITE_NO_INDICES) |
Michael McGeagh | 219ec07 | 2020-11-09 11:11:26 +0000 | [diff] [blame] | 1009 | |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 1010 | BUILTIN_OPERATOR_UNKNOWN = "UNKNOWN" |
| 1011 | |
Tim Hall | a3fe665 | 2022-03-03 17:43:16 +0000 | [diff] [blame] | 1012 | builtin_operator_name_map = {v: k for k, v in vars(BuiltinOperator).items()} |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 1013 | |
Michael McGeagh | 219ec07 | 2020-11-09 11:11:26 +0000 | [diff] [blame] | 1014 | |
Tim Hall | a3fe665 | 2022-03-03 17:43:16 +0000 | [diff] [blame] | 1015 | def optype_to_builtintype(op_type: Op): |
Michael McGeagh | 219ec07 | 2020-11-09 11:11:26 +0000 | [diff] [blame] | 1016 | if op_type in builtin_operator_inv_map: |
Tim Hall | a3fe665 | 2022-03-03 17:43:16 +0000 | [diff] [blame] | 1017 | return builtin_operator_name_map[builtin_operator_inv_map[op_type][0]] |
Michael McGeagh | 219ec07 | 2020-11-09 11:11:26 +0000 | [diff] [blame] | 1018 | else: |
Michael McGeagh | 837dc1b | 2020-11-10 12:38:25 +0000 | [diff] [blame] | 1019 | return BUILTIN_OPERATOR_UNKNOWN |