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