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