bad95cfc560282184c27f051af7e7ed101be4eaf
[platform/upstream/armnn.git] / src / armnnSerializer / ArmnnSchema.fbs
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 namespace armnnSerializer;
7
8 file_identifier "ARMN";
9
10 file_extension "armnn";
11
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
25 enum ArgMinMaxFunction : byte {
26     Min = 0,
27     Max = 1
28 }
29
30 enum DataType : byte {
31     Float16 = 0,
32     Float32 = 1,
33     QuantisedAsymm8 = 2,
34     Signed32 = 3,
35     Boolean = 4,
36     QuantisedSymm16 = 5
37 }
38
39 enum DataLayout : byte {
40     NHWC = 0,
41     NCHW = 1
42 }
43
44 enum ResizeMethod: byte {
45     NearestNeighbor = 0,
46     Bilinear = 1,
47 }
48
49 table TensorInfo {
50     dimensions:[uint];
51     dataType:DataType;
52     quantizationScale:float = 1.0;
53     quantizationOffset:int = 0;
54 }
55
56 struct Connection {
57     sourceLayerIndex:uint;
58     outputSlotIndex:uint;
59 }
60
61 table ByteData {
62     data:[byte];
63 }
64
65 table ShortData {
66     data:[short];
67 }
68
69 table IntData {
70     data:[int];
71 }
72
73 table LongData {
74     data:[long];
75 }
76
77 union ConstTensorData { ByteData, ShortData, IntData, LongData }
78
79 table ConstTensor {
80     info:TensorInfo;
81     data:ConstTensorData;
82 }
83
84 table InputSlot {
85     index:uint;
86     connection:Connection;
87 }
88
89 table OutputSlot {
90     index:uint;
91     tensorInfo:TensorInfo;
92 }
93
94 enum LayerType : uint {
95     Addition = 0,
96     Input = 1,
97     Multiplication = 2,
98     Output = 3,
99     Pooling2d = 4,
100     Reshape = 5,
101     Softmax = 6,
102     Convolution2d = 7,
103     DepthwiseConvolution2d = 8,
104     Activation = 9,
105     Permute = 10,
106     FullyConnected = 11,
107     Constant = 12,
108     SpaceToBatchNd = 13,
109     BatchToSpaceNd = 14,
110     Division = 15,
111     Minimum = 16,
112     Equal = 17,
113     Maximum = 18,
114     Normalization = 19,
115     Pad = 20,
116     Rsqrt = 21,
117     Floor = 22,
118     BatchNormalization = 23,
119     Greater = 24,
120     ResizeBilinear = 25,
121     Subtraction = 26,
122     StridedSlice = 27,
123     Gather = 28,
124     Mean = 29,
125     Merger = 30,
126     L2Normalization = 31,
127     Splitter = 32,
128     DetectionPostProcess = 33,
129     Lstm = 34,
130     Quantize = 35,
131     Dequantize = 36,
132     Merge = 37,
133     Switch = 38,
134     Concat = 39,
135     SpaceToDepth = 40,
136     Prelu = 41,
137     TransposeConvolution2d = 42,
138     Resize = 43,
139     Stack = 44,
140     QuantizedLstm = 45,
141     Abs = 46,
142     ArgMinMax = 47,
143     Slice = 48,
144     DepthToSpace = 49,
145     InstanceNormalization = 50,
146     LogSoftmax = 51,
147     Comparison = 52,
148     StandIn = 53
149 }
150
151 // Base layer table to be used as part of other layers
152 table LayerBase {
153     index:uint;
154     layerName:string;
155     layerType:LayerType;
156     inputSlots:[InputSlot];
157     outputSlots:[OutputSlot];
158 }
159
160 table BindableLayerBase {
161     base:LayerBase;
162     layerBindingId:int;
163 }
164
165 // Table for each layer defined below
166
167 table AbsLayer {
168     base:LayerBase;
169 }
170
171 table ActivationLayer {
172     base:LayerBase;
173     descriptor:ActivationDescriptor;
174 }
175
176 table ActivationDescriptor {
177     activationFunction:ActivationFunction = Sigmoid;
178     a:float;
179     b:float;
180 }
181
182 table AdditionLayer {
183     base:LayerBase;
184 }
185
186 table ArgMinMaxLayer {
187     base:LayerBase;
188     descriptor:ArgMinMaxDescriptor;
189 }
190
191 table ArgMinMaxDescriptor{
192     argMinMaxFunction:ArgMinMaxFunction;
193     axis:int;
194 }
195
196 enum ComparisonOperation : byte {
197     Equal = 0,
198     Greater = 1,
199     GreaterOrEqual = 2,
200     Less = 3,
201     LessOrEqual = 4,
202     NotEqual = 5
203 }
204
205 table ComparisonDescriptor {
206     operation:ComparisonOperation;
207 }
208
209 table ComparisonLayer {
210     base:LayerBase;
211     descriptor:ComparisonDescriptor;
212 }
213
214 table ConstantLayer {
215     base:LayerBase;
216     input:ConstTensor;
217 }
218
219 table Convolution2dLayer {
220     base:LayerBase;
221     descriptor:Convolution2dDescriptor;
222     weights:ConstTensor;
223     biases:ConstTensor;
224 }
225
226 table Convolution2dDescriptor {
227     padLeft:uint;
228     padRight:uint;
229     padTop:uint;
230     padBottom:uint;
231     strideX:uint;
232     strideY:uint;
233     dilationX:uint = 1;
234     dilationY:uint = 1;
235     biasEnabled:bool = false;
236     dataLayout:DataLayout = NCHW;
237 }
238
239 table DepthToSpaceLayer {
240     base:LayerBase;
241     descriptor:DepthToSpaceDescriptor;
242 }
243
244 table DepthToSpaceDescriptor {
245     blockSize:uint;
246     dataLayout:DataLayout;
247 }
248
249 table DivisionLayer {
250     base:LayerBase;
251 }
252
253 /// @deprecated Use ComparisonLayer instead
254 table EqualLayer {
255     base:LayerBase;
256 }
257
258 table FloorLayer{
259     base:LayerBase;
260 }
261
262 table FullyConnectedLayer {
263     base:LayerBase;
264     descriptor:FullyConnectedDescriptor;
265     weights:ConstTensor;
266     biases:ConstTensor;
267 }
268
269 table FullyConnectedDescriptor {
270     biasEnabled:bool = false;
271     transposeWeightsMatrix:bool = false;
272 }
273
274 table GatherLayer {
275     base:LayerBase;
276 }
277
278 /// @deprecated Use ComparisonLayer instead
279 table GreaterLayer {
280     base:LayerBase;
281 }
282
283 table InputLayer {
284     base:BindableLayerBase;
285 }
286
287 table InstanceNormalizationLayer {
288     base:LayerBase;
289     descriptor:InstanceNormalizationDescriptor;
290 }
291
292 table InstanceNormalizationDescriptor {
293     gamma:float;
294     beta:float;
295     eps:float;
296     dataLayout:DataLayout;
297 }
298
299 table LogSoftmaxLayer {
300     base:LayerBase;
301     descriptor:LogSoftmaxDescriptor;
302 }
303
304 table LogSoftmaxDescriptor {
305     beta:float = 1;
306     axis:int = -1;
307 }
308
309 table L2NormalizationLayer {
310     base:LayerBase;
311     descriptor:L2NormalizationDescriptor;
312 }
313
314 table L2NormalizationDescriptor {
315     dataLayout:DataLayout = NCHW;
316     eps:float = 1e-12;
317 }
318
319 table MinimumLayer {
320     base:LayerBase;
321 }
322
323 table MaximumLayer {
324     base:LayerBase;
325 }
326
327 table MultiplicationLayer {
328     base:LayerBase;
329 }
330
331 table Pooling2dLayer {
332     base:LayerBase;
333     descriptor:Pooling2dDescriptor;
334 }
335
336 enum PoolingAlgorithm : byte {
337     Max = 0,
338     Average = 1,
339     L2 = 2
340 }
341
342 enum OutputShapeRounding : byte {
343     Floor = 0,
344     Ceiling = 1
345 }
346
347 enum PaddingMethod : byte {
348     IgnoreValue = 0,
349     Exclude = 1
350 }
351
352 table Pooling2dDescriptor {
353     poolType:PoolingAlgorithm;
354     padLeft:uint;
355     padRight:uint;
356     padTop:uint;
357     padBottom:uint;
358     poolWidth:uint;
359     poolHeight:uint;
360     strideX:uint;
361     strideY:uint;
362     outputShapeRounding:OutputShapeRounding;
363     paddingMethod:PaddingMethod;
364     dataLayout:DataLayout;
365 }
366
367 table QuantizeLayer {
368     base:LayerBase;
369 }
370
371 table SoftmaxLayer {
372     base:LayerBase;
373     descriptor:SoftmaxDescriptor;
374 }
375
376 table SoftmaxDescriptor {
377     beta:float;
378 }
379
380 table DepthwiseConvolution2dLayer {
381     base:LayerBase;
382     descriptor:DepthwiseConvolution2dDescriptor;
383     weights:ConstTensor;
384     biases:ConstTensor;
385 }
386
387 table DepthwiseConvolution2dDescriptor {
388     padLeft:uint;
389     padRight:uint;
390     padTop:uint;
391     padBottom:uint;
392     strideX:uint;
393     strideY:uint;
394     dilationX:uint = 1;
395     dilationY:uint = 1;
396     biasEnabled:bool = false;
397     dataLayout:DataLayout = NCHW;
398 }
399
400 table OutputLayer {
401     base:BindableLayerBase;
402 }
403
404 table ReshapeLayer {
405     base:LayerBase;
406     descriptor:ReshapeDescriptor;
407 }
408
409 table ReshapeDescriptor {
410   targetShape:[uint];
411 }
412
413 table PermuteLayer {
414     base:LayerBase;
415     descriptor:PermuteDescriptor;
416 }
417
418 table PermuteDescriptor {
419     dimMappings:[uint];
420 }
421
422 table SpaceToBatchNdLayer {
423     base:LayerBase;
424     descriptor:SpaceToBatchNdDescriptor;
425 }
426
427 table SpaceToBatchNdDescriptor {
428     blockShape:[uint];
429     padList:[uint];
430     dataLayout:DataLayout;
431 }
432
433 table SpaceToDepthLayer {
434     base:LayerBase;
435     descriptor:SpaceToDepthDescriptor;
436 }
437
438 table SpaceToDepthDescriptor {
439     blockSize:uint;
440     dataLayout:DataLayout;
441 }
442
443 table SubtractionLayer {
444     base:LayerBase;
445 }
446
447 table BatchToSpaceNdLayer {
448     base:LayerBase;
449     descriptor:BatchToSpaceNdDescriptor;
450 }
451
452 table BatchToSpaceNdDescriptor {
453     blockShape:[uint];
454     crops:[uint];
455     dataLayout:DataLayout;
456 }
457
458 enum NormalizationAlgorithmChannel : byte {
459     Across = 0,
460     Within = 1
461 }
462
463 enum NormalizationAlgorithmMethod : byte {
464     LocalBrightness = 0,
465     LocalContrast = 1
466 }
467
468 table NormalizationLayer {
469     base:LayerBase;
470     descriptor:NormalizationDescriptor;
471 }
472
473 table NormalizationDescriptor {
474     normChannelType:NormalizationAlgorithmChannel = Across;
475     normMethodType:NormalizationAlgorithmMethod = LocalBrightness;
476     normSize:uint;
477     alpha:float;
478     beta:float;
479     k:float;
480     dataLayout:DataLayout = NCHW;
481 }
482
483 table MeanLayer {
484     base:LayerBase;
485     descriptor:MeanDescriptor;
486 }
487
488 table MeanDescriptor {
489     axis:[uint];
490     keepDims:bool = false;
491 }
492
493 table PadLayer {
494     base:LayerBase;
495     descriptor:PadDescriptor;
496 }
497
498 table PadDescriptor {
499     padList:[uint];
500     padValue:float = 0;
501 }
502
503 table RsqrtLayer {
504     base:LayerBase;
505 }
506
507 table BatchNormalizationLayer {
508     base:LayerBase;
509     descriptor:BatchNormalizationDescriptor;
510     mean:ConstTensor;
511     variance:ConstTensor;
512     beta:ConstTensor;
513     gamma:ConstTensor;
514 }
515
516 table BatchNormalizationDescriptor {
517     eps:float;
518     dataLayout:DataLayout;
519 }
520
521 /// @deprecated Use ResizeLayer instead
522 table ResizeBilinearLayer {
523     base:LayerBase;
524     descriptor:ResizeBilinearDescriptor;
525 }
526
527 table ResizeBilinearDescriptor {
528     targetWidth:uint;
529     targetHeight:uint;
530     dataLayout:DataLayout;
531 }
532
533 table SliceLayer {
534     base:LayerBase;
535     descriptor:SliceDescriptor;
536 }
537
538 table SliceDescriptor {
539     begin:[uint];
540     size:[uint];
541 }
542
543 table StridedSliceLayer {
544     base:LayerBase;
545     descriptor:StridedSliceDescriptor;
546 }
547
548 table StridedSliceDescriptor {
549     begin:[int];
550     end:[int];
551     stride:[int];
552     beginMask:int;
553     endMask:int;
554     shrinkAxisMask:int;
555     ellipsisMask:int;
556     newAxisMask:int;
557     dataLayout:DataLayout;
558 }
559
560 table ConcatLayer {
561     base:LayerBase;
562     descriptor:OriginsDescriptor;
563 }
564
565 /// @deprecated Use ConcatLayer instead
566 table MergerLayer {
567     base:LayerBase;
568     descriptor:OriginsDescriptor;
569 }
570
571 table UintVector {
572    data:[uint];
573 }
574
575 table OriginsDescriptor {
576    concatAxis:uint;
577    numViews:uint;
578    numDimensions:uint;
579    viewOrigins:[UintVector];
580 }
581
582 table ViewsDescriptor {
583    origins:OriginsDescriptor;
584    viewSizes:[UintVector];
585 }
586
587 table SplitterLayer {
588    base:LayerBase;
589    descriptor:ViewsDescriptor;
590 }
591
592 table DetectionPostProcessLayer {
593     base:LayerBase;
594     descriptor:DetectionPostProcessDescriptor;
595     anchors:ConstTensor;
596 }
597
598 table DetectionPostProcessDescriptor {
599     maxDetections:uint;
600     maxClassesPerDetection:uint;
601     detectionsPerClass:uint;
602     nmsScoreThreshold:float;
603     nmsIouThreshold:float;
604     numClasses:uint;
605     useRegularNms:bool;
606     scaleX:float;
607     scaleY:float;
608     scaleW:float;
609     scaleH:float;
610 }
611
612 table LstmInputParams {
613     inputToForgetWeights:ConstTensor;
614     inputToCellWeights:ConstTensor;
615     inputToOutputWeights:ConstTensor;
616     recurrentToForgetWeights:ConstTensor;
617     recurrentToCellWeights:ConstTensor;
618     recurrentToOutputWeights:ConstTensor;
619     forgetGateBias:ConstTensor;
620     cellBias:ConstTensor;
621     outputGateBias:ConstTensor;
622
623     inputToInputWeights:ConstTensor;
624     recurrentToInputWeights:ConstTensor;
625     cellToInputWeights:ConstTensor;
626     inputGateBias:ConstTensor;
627
628     projectionWeights:ConstTensor;
629     projectionBias:ConstTensor;
630
631     cellToForgetWeights:ConstTensor;
632     cellToOutputWeights:ConstTensor;
633
634     inputLayerNormWeights:ConstTensor;
635     forgetLayerNormWeights:ConstTensor;
636     cellLayerNormWeights:ConstTensor;
637     outputLayerNormWeights:ConstTensor;
638 }
639
640 table QuantizedLstmInputParams {
641     inputToInputWeights:ConstTensor;
642     inputToForgetWeights:ConstTensor;
643     inputToCellWeights:ConstTensor;
644     inputToOutputWeights:ConstTensor;
645
646     recurrentToInputWeights:ConstTensor;
647     recurrentToForgetWeights:ConstTensor;
648     recurrentToCellWeights:ConstTensor;
649     recurrentToOutputWeights:ConstTensor;
650
651     inputGateBias:ConstTensor;
652     forgetGateBias:ConstTensor;
653     cellBias:ConstTensor;
654     outputGateBias:ConstTensor;
655 }
656
657 table LstmDescriptor {
658     activationFunc:uint;
659     clippingThresCell:float;
660     clippingThresProj:float;
661     cifgEnabled:bool = true;
662     peepholeEnabled:bool = false;
663     projectionEnabled:bool = false;
664     layerNormEnabled:bool = false;
665 }
666
667 table LstmLayer {
668     base:LayerBase;
669     descriptor:LstmDescriptor;
670     inputParams:LstmInputParams;
671 }
672
673 table QuantizedLstmLayer {
674     base:LayerBase;
675     inputParams:QuantizedLstmInputParams;
676 }
677
678 table DequantizeLayer {
679     base:LayerBase;
680 }
681
682 table MergeLayer {
683     base:LayerBase;
684 }
685
686 table SwitchLayer {
687     base:LayerBase;
688 }
689
690 table PreluLayer {
691     base:LayerBase;
692 }
693
694 table TransposeConvolution2dLayer {
695     base:LayerBase;
696     descriptor:TransposeConvolution2dDescriptor;
697     weights:ConstTensor;
698     biases:ConstTensor;
699 }
700
701 table TransposeConvolution2dDescriptor {
702     padLeft:uint;
703     padRight:uint;
704     padTop:uint;
705     padBottom:uint;
706     strideX:uint;
707     strideY:uint;
708     biasEnabled:bool = false;
709     dataLayout:DataLayout = NCHW;
710 }
711
712 table ResizeLayer {
713     base:LayerBase;
714     descriptor:ResizeDescriptor;
715 }
716
717 table ResizeDescriptor {
718     targetHeight:uint;
719     targetWidth:uint;
720     method:ResizeMethod = NearestNeighbor;
721     dataLayout:DataLayout;
722 }
723
724 table StackLayer {
725     base:LayerBase;
726     descriptor:StackDescriptor;
727 }
728
729 table StackDescriptor {
730     axis:uint;
731     numInputs:uint;
732     inputShape:[uint];
733 }
734
735 table StandInDescriptor {
736     numInputs:uint;
737     numOutputs:uint;
738 }
739
740 table StandInLayer {
741     base:LayerBase;
742     descriptor:StandInDescriptor;
743 }
744
745 union Layer {
746     ActivationLayer,
747     AdditionLayer,
748     BatchToSpaceNdLayer,
749     BatchNormalizationLayer,
750     ConstantLayer,
751     Convolution2dLayer,
752     DepthwiseConvolution2dLayer,
753     FullyConnectedLayer,
754     InputLayer,
755     MultiplicationLayer,
756     OutputLayer,
757     PermuteLayer,
758     Pooling2dLayer,
759     ReshapeLayer,
760     SoftmaxLayer,
761     SpaceToBatchNdLayer,
762     DivisionLayer,
763     MinimumLayer,
764     EqualLayer,
765     MaximumLayer,
766     NormalizationLayer,
767     PadLayer,
768     RsqrtLayer,
769     FloorLayer,
770     GreaterLayer,
771     ResizeBilinearLayer,
772     SubtractionLayer,
773     StridedSliceLayer,
774     GatherLayer,
775     MeanLayer,
776     MergerLayer,
777     L2NormalizationLayer,
778     SplitterLayer,
779     DetectionPostProcessLayer,
780     LstmLayer,
781     QuantizedLstmLayer,
782     QuantizeLayer,
783     DequantizeLayer,
784     MergeLayer,
785     SwitchLayer,
786     ConcatLayer,
787     SpaceToDepthLayer,
788     PreluLayer,
789     TransposeConvolution2dLayer,
790     ResizeLayer,
791     StackLayer,
792     AbsLayer,
793     ArgMinMaxLayer,
794     SliceLayer,
795     DepthToSpaceLayer,
796     InstanceNormalizationLayer,
797     LogSoftmaxLayer,
798     ComparisonLayer,
799     StandInLayer
800 }
801
802 table AnyLayer {
803     layer:Layer;
804 }
805
806 // Root type for serialized data is the graph of the network
807 table SerializedGraph {
808     layers:[AnyLayer];
809     inputIds:[uint];
810     outputIds:[uint];
811 }
812
813 root_type SerializedGraph;