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