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