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, |
| 99 | Division = 15 |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | // Base layer table to be used as part of other layers |
| 103 | table LayerBase { |
| 104 | index:uint; |
| 105 | layerName:string; |
| 106 | layerType:LayerType; |
| 107 | inputSlots:[InputSlot]; |
| 108 | outputSlots:[OutputSlot]; |
| 109 | } |
| 110 | |
| 111 | table BindableLayerBase { |
| 112 | base:LayerBase; |
| 113 | layerBindingId:int; |
| 114 | } |
| 115 | |
| 116 | // Table for each layer defined below |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 117 | table ActivationLayer { |
| 118 | base:LayerBase; |
| 119 | descriptor:ActivationDescriptor; |
| 120 | } |
| 121 | |
| 122 | table ActivationDescriptor { |
| 123 | function:ActivationFunction = Sigmoid; |
| 124 | a:float; |
| 125 | b:float; |
| 126 | } |
| 127 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 128 | table AdditionLayer { |
| 129 | base:LayerBase; |
| 130 | } |
| 131 | |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 132 | table ConstantLayer { |
| 133 | base:LayerBase; |
| 134 | input:ConstTensor; |
| 135 | } |
| 136 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 137 | table Convolution2dLayer { |
| 138 | base:LayerBase; |
| 139 | descriptor:Convolution2dDescriptor; |
| 140 | weights:ConstTensor; |
| 141 | biases:ConstTensor; |
| 142 | } |
| 143 | |
| 144 | table Convolution2dDescriptor { |
| 145 | padLeft:uint; |
| 146 | padRight:uint; |
| 147 | padTop:uint; |
| 148 | padBottom:uint; |
| 149 | strideX:uint; |
| 150 | strideY:uint; |
| 151 | biasEnabled:bool = false; |
| 152 | dataLayout:DataLayout = NCHW; |
| 153 | } |
| 154 | |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame^] | 155 | table DivisionLayer { |
| 156 | base:LayerBase; |
| 157 | } |
| 158 | |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 159 | table FullyConnectedLayer { |
| 160 | base:LayerBase; |
| 161 | descriptor:FullyConnectedDescriptor; |
| 162 | weights:ConstTensor; |
| 163 | biases:ConstTensor; |
| 164 | } |
| 165 | |
| 166 | table FullyConnectedDescriptor { |
| 167 | biasEnabled:bool = false; |
| 168 | transposeWeightsMatrix:bool = false; |
| 169 | } |
| 170 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 171 | table InputLayer { |
| 172 | base:BindableLayerBase; |
| 173 | } |
| 174 | |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 175 | table MultiplicationLayer { |
| 176 | base:LayerBase; |
| 177 | } |
| 178 | |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 179 | table Pooling2dLayer { |
| 180 | base:LayerBase; |
| 181 | descriptor:Pooling2dDescriptor; |
| 182 | } |
| 183 | |
| 184 | enum PoolingAlgorithm : byte { |
| 185 | Max = 0, |
| 186 | Average = 1, |
| 187 | L2 = 2 |
| 188 | } |
| 189 | |
| 190 | enum OutputShapeRounding : byte { |
| 191 | Floor = 0, |
| 192 | Ceiling = 1 |
| 193 | } |
| 194 | |
| 195 | enum PaddingMethod : byte { |
| 196 | IgnoreValue = 0, |
| 197 | Exclude = 1 |
| 198 | } |
| 199 | |
| 200 | table Pooling2dDescriptor { |
| 201 | poolType:PoolingAlgorithm; |
| 202 | padLeft:uint; |
| 203 | padRight:uint; |
| 204 | padTop:uint; |
| 205 | padBottom:uint; |
| 206 | poolWidth:uint; |
| 207 | poolHeight:uint; |
| 208 | strideX:uint; |
| 209 | strideY:uint; |
| 210 | outputShapeRounding:OutputShapeRounding; |
| 211 | paddingMethod:PaddingMethod; |
| 212 | dataLayout:DataLayout; |
| 213 | } |
| 214 | |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 215 | table SoftmaxLayer { |
| 216 | base:LayerBase; |
| 217 | descriptor:SoftmaxDescriptor; |
| 218 | } |
| 219 | |
| 220 | table SoftmaxDescriptor { |
| 221 | beta:float; |
| 222 | } |
| 223 | |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 224 | table DepthwiseConvolution2dLayer { |
| 225 | base:LayerBase; |
| 226 | descriptor:DepthwiseConvolution2dDescriptor; |
| 227 | weights:ConstTensor; |
| 228 | biases:ConstTensor; |
| 229 | } |
| 230 | |
| 231 | table DepthwiseConvolution2dDescriptor { |
| 232 | padLeft:uint; |
| 233 | padRight:uint; |
| 234 | padTop:uint; |
| 235 | padBottom:uint; |
| 236 | strideX:uint; |
| 237 | strideY:uint; |
| 238 | biasEnabled:bool = false; |
| 239 | dataLayout:DataLayout = NCHW; |
| 240 | } |
| 241 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 242 | table OutputLayer { |
| 243 | base:BindableLayerBase; |
| 244 | } |
| 245 | |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 246 | table ReshapeLayer { |
| 247 | base:LayerBase; |
| 248 | descriptor:ReshapeDescriptor; |
| 249 | } |
| 250 | |
| 251 | table ReshapeDescriptor { |
| 252 | targetShape:[uint]; |
| 253 | } |
| 254 | |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 255 | table PermuteLayer { |
| 256 | base:LayerBase; |
| 257 | descriptor:PermuteDescriptor; |
| 258 | } |
| 259 | |
| 260 | table PermuteDescriptor { |
| 261 | dimMappings:[uint]; |
| 262 | } |
| 263 | |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 264 | table SpaceToBatchNdLayer { |
| 265 | base:LayerBase; |
| 266 | descriptor:SpaceToBatchNdDescriptor; |
| 267 | } |
| 268 | |
| 269 | table SpaceToBatchNdDescriptor { |
| 270 | blockShape:[uint]; |
| 271 | padList:[uint]; |
| 272 | dataLayout:DataLayout; |
| 273 | } |
| 274 | |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 275 | table BatchToSpaceNdLayer { |
| 276 | base:LayerBase; |
| 277 | descriptor:BatchToSpaceNdDescriptor; |
| 278 | } |
| 279 | |
| 280 | table BatchToSpaceNdDescriptor { |
| 281 | blockShape:[uint]; |
| 282 | crops:[uint]; |
| 283 | dataLayout:DataLayout; |
| 284 | } |
| 285 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 286 | union Layer { |
Mike Kelly | af48401 | 2019-02-20 16:53:11 +0000 | [diff] [blame] | 287 | ActivationLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 288 | AdditionLayer, |
Nattapat Chaimanowong | 6b4ed98 | 2019-02-26 17:24:13 +0000 | [diff] [blame] | 289 | BatchToSpaceNdLayer, |
Conor Kennedy | 7627788 | 2019-02-26 08:29:54 +0000 | [diff] [blame] | 290 | ConstantLayer, |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 291 | Convolution2dLayer, |
Aron Virginas-Tar | c04125f | 2019-02-19 16:31:08 +0000 | [diff] [blame] | 292 | DepthwiseConvolution2dLayer, |
Sadik Armagan | dbb0c0c | 2019-02-21 09:01:41 +0000 | [diff] [blame] | 293 | FullyConnectedLayer, |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 294 | InputLayer, |
Sadik Armagan | 5f45027 | 2019-02-12 14:31:45 +0000 | [diff] [blame] | 295 | MultiplicationLayer, |
Aron Virginas-Tar | fc413c0 | 2019-02-13 15:41:52 +0000 | [diff] [blame] | 296 | OutputLayer, |
Nattapat Chaimanowong | 30b0020 | 2019-02-20 17:31:34 +0000 | [diff] [blame] | 297 | PermuteLayer, |
Saoirse Stewart | 3166c3e | 2019-02-18 15:24:53 +0000 | [diff] [blame] | 298 | Pooling2dLayer, |
Saoirse Stewart | 263829c | 2019-02-19 15:54:14 +0000 | [diff] [blame] | 299 | ReshapeLayer, |
Nattapat Chaimanowong | 4528699 | 2019-02-26 15:53:02 +0000 | [diff] [blame] | 300 | SoftmaxLayer, |
Éanna Ó Catháin | 5888589 | 2019-02-27 16:16:39 +0000 | [diff] [blame^] | 301 | SpaceToBatchNdLayer, |
| 302 | DivisionLayer |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 305 | table AnyLayer { |
| 306 | layer:Layer; |
| 307 | } |
| 308 | |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 309 | // Root type for serialized data is the graph of the network |
| 310 | table SerializedGraph { |
Saoirse Stewart | 49dbe0e | 2019-02-05 17:27:06 +0000 | [diff] [blame] | 311 | layers:[AnyLayer]; |
Mike Kelly | 8c1701a | 2019-02-11 17:01:27 +0000 | [diff] [blame] | 312 | inputIds:[uint]; |
| 313 | outputIds:[uint]; |
Nattapat Chaimanowong | 969eea3 | 2019-01-30 13:33:11 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | root_type SerializedGraph; |