Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 6 | namespace armnnSerializer; |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 7 | |
| 8 | file_identifier "ARMN"; |
| 9 | |
| 10 | file_extension "armnn"; |
| 11 | |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 12 | enum ActivationFunction : byte { |
| 13 | Sigmoid = 0, |
| 14 | TanH = 1, |
| 15 | Linear = 2, |
| 16 | ReLu = 3, |
| 17 | BoundedReLu = 4, |
| 18 | SoftReLu = 5, |
| 19 | LeakyReLu = 6, |
| 20 | Abs = 7, |
| 21 | Sqrt = 8, |
| 22 | Square = 9 |
| 23 | } |
| 24 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 25 | enum DataType : byte { |
| 26 | Float16 = 0, |
| 27 | Float32 = 1, |
| 28 | QuantisedAsymm8 = 2, |
| 29 | Signed32 = 3, |
| 30 | Boolean = 4 |
| 31 | } |
| 32 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 33 | enum DataLayout : byte { |
| 34 | NHWC = 0, |
| 35 | NCHW = 1 |
| 36 | } |
| 37 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 38 | table TensorInfo { |
| 39 | dimensions:[uint]; |
| 40 | dataType:DataType; |
| 41 | quantizationScale:float = 1.0; |
| 42 | quantizationOffset:int = 0; |
| 43 | } |
| 44 | |
| 45 | struct Connection { |
| 46 | sourceLayerIndex:uint; |
| 47 | outputSlotIndex:uint; |
| 48 | } |
| 49 | |
| 50 | table ByteData { |
| 51 | data:[byte]; |
| 52 | } |
| 53 | |
| 54 | table ShortData { |
| 55 | data:[short]; |
| 56 | } |
| 57 | |
| 58 | table IntData { |
| 59 | data:[int]; |
| 60 | } |
| 61 | |
| 62 | table LongData { |
| 63 | data:[long]; |
| 64 | } |
| 65 | |
| 66 | union ConstTensorData { ByteData, ShortData, IntData, LongData } |
| 67 | |
| 68 | table ConstTensor { |
| 69 | info:TensorInfo; |
| 70 | data:ConstTensorData; |
| 71 | } |
| 72 | |
| 73 | table InputSlot { |
| 74 | index:uint; |
| 75 | connection:Connection; |
| 76 | } |
| 77 | |
| 78 | table OutputSlot { |
| 79 | index:uint; |
| 80 | tensorInfo:TensorInfo; |
| 81 | } |
| 82 | |
| 83 | enum LayerType : uint { |
| 84 | Addition = 0, |
| 85 | Input = 1, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 86 | Multiplication = 2, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 87 | Output = 3, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 88 | Pooling2d = 4, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 89 | Reshape = 5, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 90 | Softmax = 6, |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 91 | Convolution2d = 7, |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 92 | DepthwiseConvolution2d = 8, |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 93 | Activation = 9, |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 94 | Permute = 10, |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 95 | FullyConnected = 11, |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 96 | Constant = 12, |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 97 | SpaceToBatchNd = 13, |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 98 | BatchToSpaceNd = 14, |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 99 | Division = 15, |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 100 | Minimum = 16, |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame^] | 101 | Equal = 17, |
| 102 | Maximum = 18 |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Base layer table to be used as part of other layers |
| 106 | table LayerBase { |
| 107 | index:uint; |
| 108 | layerName:string; |
| 109 | layerType:LayerType; |
| 110 | inputSlots:[InputSlot]; |
| 111 | outputSlots:[OutputSlot]; |
| 112 | } |
| 113 | |
| 114 | table BindableLayerBase { |
| 115 | base:LayerBase; |
| 116 | layerBindingId:int; |
| 117 | } |
| 118 | |
| 119 | // Table for each layer defined below |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 120 | table ActivationLayer { |
| 121 | base:LayerBase; |
| 122 | descriptor:ActivationDescriptor; |
| 123 | } |
| 124 | |
| 125 | table ActivationDescriptor { |
| 126 | function:ActivationFunction = Sigmoid; |
| 127 | a:float; |
| 128 | b:float; |
| 129 | } |
| 130 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 131 | table AdditionLayer { |
| 132 | base:LayerBase; |
| 133 | } |
| 134 | |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 135 | table ConstantLayer { |
| 136 | base:LayerBase; |
| 137 | input:ConstTensor; |
| 138 | } |
| 139 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 140 | table Convolution2dLayer { |
| 141 | base:LayerBase; |
| 142 | descriptor:Convolution2dDescriptor; |
| 143 | weights:ConstTensor; |
| 144 | biases:ConstTensor; |
| 145 | } |
| 146 | |
| 147 | table Convolution2dDescriptor { |
| 148 | padLeft:uint; |
| 149 | padRight:uint; |
| 150 | padTop:uint; |
| 151 | padBottom:uint; |
| 152 | strideX:uint; |
| 153 | strideY:uint; |
| 154 | biasEnabled:bool = false; |
| 155 | dataLayout:DataLayout = NCHW; |
| 156 | } |
| 157 | |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 158 | table DivisionLayer { |
| 159 | base:LayerBase; |
| 160 | } |
| 161 | |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 162 | table EqualLayer { |
| 163 | base:LayerBase; |
| 164 | } |
| 165 | |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 166 | table FullyConnectedLayer { |
| 167 | base:LayerBase; |
| 168 | descriptor:FullyConnectedDescriptor; |
| 169 | weights:ConstTensor; |
| 170 | biases:ConstTensor; |
| 171 | } |
| 172 | |
| 173 | table FullyConnectedDescriptor { |
| 174 | biasEnabled:bool = false; |
| 175 | transposeWeightsMatrix:bool = false; |
| 176 | } |
| 177 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 178 | table InputLayer { |
| 179 | base:BindableLayerBase; |
| 180 | } |
| 181 | |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 182 | table MinimumLayer { |
| 183 | base:LayerBase; |
| 184 | } |
| 185 | |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame^] | 186 | table MaximumLayer { |
| 187 | base:LayerBase; |
| 188 | } |
| 189 | |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 190 | table MultiplicationLayer { |
| 191 | base:LayerBase; |
| 192 | } |
| 193 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 194 | table Pooling2dLayer { |
| 195 | base:LayerBase; |
| 196 | descriptor:Pooling2dDescriptor; |
| 197 | } |
| 198 | |
| 199 | enum PoolingAlgorithm : byte { |
| 200 | Max = 0, |
| 201 | Average = 1, |
| 202 | L2 = 2 |
| 203 | } |
| 204 | |
| 205 | enum OutputShapeRounding : byte { |
| 206 | Floor = 0, |
| 207 | Ceiling = 1 |
| 208 | } |
| 209 | |
| 210 | enum PaddingMethod : byte { |
| 211 | IgnoreValue = 0, |
| 212 | Exclude = 1 |
| 213 | } |
| 214 | |
| 215 | table Pooling2dDescriptor { |
| 216 | poolType:PoolingAlgorithm; |
| 217 | padLeft:uint; |
| 218 | padRight:uint; |
| 219 | padTop:uint; |
| 220 | padBottom:uint; |
| 221 | poolWidth:uint; |
| 222 | poolHeight:uint; |
| 223 | strideX:uint; |
| 224 | strideY:uint; |
| 225 | outputShapeRounding:OutputShapeRounding; |
| 226 | paddingMethod:PaddingMethod; |
| 227 | dataLayout:DataLayout; |
| 228 | } |
| 229 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 230 | table SoftmaxLayer { |
| 231 | base:LayerBase; |
| 232 | descriptor:SoftmaxDescriptor; |
| 233 | } |
| 234 | |
| 235 | table SoftmaxDescriptor { |
| 236 | beta:float; |
| 237 | } |
| 238 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 239 | table DepthwiseConvolution2dLayer { |
| 240 | base:LayerBase; |
| 241 | descriptor:DepthwiseConvolution2dDescriptor; |
| 242 | weights:ConstTensor; |
| 243 | biases:ConstTensor; |
| 244 | } |
| 245 | |
| 246 | table DepthwiseConvolution2dDescriptor { |
| 247 | padLeft:uint; |
| 248 | padRight:uint; |
| 249 | padTop:uint; |
| 250 | padBottom:uint; |
| 251 | strideX:uint; |
| 252 | strideY:uint; |
| 253 | biasEnabled:bool = false; |
| 254 | dataLayout:DataLayout = NCHW; |
| 255 | } |
| 256 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 257 | table OutputLayer { |
| 258 | base:BindableLayerBase; |
| 259 | } |
| 260 | |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 261 | table ReshapeLayer { |
| 262 | base:LayerBase; |
| 263 | descriptor:ReshapeDescriptor; |
| 264 | } |
| 265 | |
| 266 | table ReshapeDescriptor { |
| 267 | targetShape:[uint]; |
| 268 | } |
| 269 | |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 270 | table PermuteLayer { |
| 271 | base:LayerBase; |
| 272 | descriptor:PermuteDescriptor; |
| 273 | } |
| 274 | |
| 275 | table PermuteDescriptor { |
| 276 | dimMappings:[uint]; |
| 277 | } |
| 278 | |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 279 | table SpaceToBatchNdLayer { |
| 280 | base:LayerBase; |
| 281 | descriptor:SpaceToBatchNdDescriptor; |
| 282 | } |
| 283 | |
| 284 | table SpaceToBatchNdDescriptor { |
| 285 | blockShape:[uint]; |
| 286 | padList:[uint]; |
| 287 | dataLayout:DataLayout; |
| 288 | } |
| 289 | |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 290 | table BatchToSpaceNdLayer { |
| 291 | base:LayerBase; |
| 292 | descriptor:BatchToSpaceNdDescriptor; |
| 293 | } |
| 294 | |
| 295 | table BatchToSpaceNdDescriptor { |
| 296 | blockShape:[uint]; |
| 297 | crops:[uint]; |
| 298 | dataLayout:DataLayout; |
| 299 | } |
| 300 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 301 | union Layer { |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 302 | ActivationLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 303 | AdditionLayer, |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 304 | BatchToSpaceNdLayer, |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 305 | ConstantLayer, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 306 | Convolution2dLayer, |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 307 | DepthwiseConvolution2dLayer, |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 308 | FullyConnectedLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 309 | InputLayer, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 310 | MultiplicationLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 311 | OutputLayer, |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 312 | PermuteLayer, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 313 | Pooling2dLayer, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 314 | ReshapeLayer, |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 315 | SoftmaxLayer, |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame] | 316 | SpaceToBatchNdLayer, |
Aron Virginas-Tar | 0fe3245 | 2019-02-28 13:12:47 +0000 | [diff] [blame] | 317 | DivisionLayer, |
Nattapat Chaimanowong | 235cea5 | 2019-02-28 16:27:30 +0000 | [diff] [blame] | 318 | MinimumLayer, |
Aron Virginas-Tar | 377351e | 2019-02-27 14:42:31 +0000 | [diff] [blame^] | 319 | EqualLayer, |
| 320 | MaximumLayer |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 323 | table AnyLayer { |
| 324 | layer:Layer; |
| 325 | } |
| 326 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 327 | // Root type for serialized data is the graph of the network |
| 328 | table SerializedGraph { |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 329 | layers:[AnyLayer]; |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 330 | inputIds:[uint]; |
| 331 | outputIds:[uint]; |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | root_type SerializedGraph; |