-
Notifications
You must be signed in to change notification settings - Fork 797
Expand file tree
/
Copy pathNeuralNetwork.proto
More file actions
2331 lines (2147 loc) · 64.8 KB
/
Copy pathNeuralNetwork.proto
File metadata and controls
2331 lines (2147 loc) · 64.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2017, Apple Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-3-clause license that can be
// found in LICENSE.txt or at https://opensource.org/licenses/BSD-3-Clause
/**
* A neural network is defined through a collection of layers
* and represents a directed acyclic graph (DAG).
* Each layer has a name, a layer type,
* a list of input names, a list of output names,
* and a collection of parameters specific to the layer type.
*
* The graph structure and connectivity of the neural network
* is inferred from the input and output names.
* A neural network starts with the layer
* whose input name is equal to the value specified in
* ``Model.description.input.name``,
* and ends with the layer
* whose output name is equal to the value specified in
* ``Model.description.output.name``.
* Layers must have unique input and output names,
* and a layer may not have input or output names that
* refer to layers that are not yet defined.
*
* CoreML supports sequential data that can be 1- or 3-dimensional.
* 3-dimensional data typically represents an image feature map,
* whose shape is denoted by ``[C, H, W]``,
* which corresponds to the channel, height, and width, respectively.
* 1-dimensional data is a set of features
* whose shape is denoted by ``[C]``,
* and is equivalent to 3-dimensional data
* with the shape ``[C, 1, 1]``.
*
* For the purposes of this specification,
* batch dimension is ignored.
* Thus, a sequence of 3-dimensional data
* is to be understood as a 4-dimensional array,
* whose shape is denoted by ``[Seq_length, C, H, W]``,
* and a sequence of 1-dimensional data
* is to be understood as a 2-dimensional array,
* whose shape is denoted by ``[Seq_length, C]``,
* which is equivalent to a 4-dimensional array
* with the shape ``[Seq_length, C, 1, 1]``. This axes order is important to
* remember while setting parameters for layers such as "reshape" and "permute".
*
*
* At runtime, all data blobs are internally represented
* as 5-dimensional blobs
* with the shape ``[Seq_length, Batch, C, H, W]``.
*
* A layer may process input data differently if operating over a sequence;
* details of this behavior is documented in the layer's message.
* Otherwise, sequential data is processed like a batch ---
* that is, the sequence of inputs are processed independently and in parallel.
*
* The network input shape specified by ``Model.description.input.type``
* must be compatible with the expected input shape
* of the network input layer, i.e. the last dimension is the fastest moving one.
*
* All data blobs, as well as weight parameters,
* are stored using row-major ordering, i.e. the last dimension is the fastest moving one.
*/
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
import public "DataStructures.proto";
package CoreML.Specification;
/**
A neural network.
*/
message NeuralNetwork {
repeated NeuralNetworkLayer layers = 1;
repeated NeuralNetworkPreprocessing preprocessing = 2;
}
/// Preprocessing
/// -------------
/**
* A neural network preprocessor that
* performs a scalar multiplication of an image
* followed by addition of scalar biases to the channels.
*
* Input: X
* An image in BGR or RGB format with shape ``[3, H, W]``
* or in grayscale format with shape ``[1, H, W]``.
* Output: Y
* An image with format and shape corresponding to the input.
*
* If the input image is in BGR format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + blueBias
* Y[1, :, :] = channelScale * X[1, :, :] + greenBias
* Y[2, :, :] = channelScale * X[2, :, :] + redBias
*
* If the input image is in RGB format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + redBias
* Y[1, :, :] = channelScale * X[1, :, :] + greenBias
* Y[2, :, :] = channelScale * X[2, :, :] + blueBias
*
* If the input image is in grayscale format:
*
* .. code::
*
* Y[0, :, :] = channelScale * X[0, :, :] + grayBias
*/
message NeuralNetworkImageScaler {
float channelScale = 10; ///Scalar to be multiplied.
float blueBias = 20; ///Scalar blue bias to be added.
float greenBias = 21; ///Scalar green bias to be added.
float redBias = 22; ///Scalar red bias to be added.
float grayBias = 30; ///Scalar bias to be added for grayscale images.
}
/**
* A neural network preprocessor that
* subtracts the provided mean image from the input image.
* The mean image is subtracted from the input named
* ``NeuralNetworkPreprocessing.featureName``.
*/
message NeuralNetworkMeanImage {
/**
* Mean image stored as a flattened array of floats,
* representing shape [Channel,Height,Width].
*/
repeated float meanImage = 1;
}
/// Preprocessing parameters for image inputs.
message NeuralNetworkPreprocessing {
string featureName = 1; /// must be equal to the input name to which the preprocessing is applied
oneof preprocessor {
NeuralNetworkImageScaler scaler = 10;
NeuralNetworkMeanImage meanImage = 11;
}
}
/// Activation Functions
/// --------------------
/**
* A rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{max}(0, x)
*/
message ActivationReLU {
}
/**
* A leaky rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq 0 \\
* \alpha x & \text{if } x < 0
* \end{cases}
*/
message ActivationLeakyReLU {
float alpha = 1; //negative slope value for leakyReLU
}
/**
* A hyperbolic tangent activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{1 - e^{-2x}}{1 + e^{-2x}}
*/
message ActivationTanh {
}
/**
* A scaled hyperbolic tangent activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \alpha \tanh(\beta x)
*/
message ActivationScaledTanh {
float alpha = 1;
float beta = 2;
}
/**
* A sigmoid activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{1}{1 + e^{-x}}
*/
message ActivationSigmoid {
}
/**
* A linear activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \alpha x + \beta
*/
message ActivationLinear {
float alpha = 1;
float beta = 2;
}
/**
* A hard sigmoid activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{min}(\text{max}(\alpha x + \beta, 0), 1)
*/
message ActivationSigmoidHard {
float alpha = 1;
float beta = 2;
}
/**
* A parameterized rectified linear unit (PReLU) activation function,
* which takes ``[C]`` or ``[C,H,W]`` as an input and
* applies different parameters in each channel dimension
* (shared across the ``H`` and ``W`` components).
*
* This function has the following formula:
*
* .. math::
* f(x_i) = \begin{cases}
* x_i & \text{if } x_i \geq 0 \\
* \alpha_i x_i & \text{if } x_i < 0
* \end{cases} \;,\;i=1,...,C
*/
message ActivationPReLU {
// parameter of length C or 1.
// If length is 1, same value is used for all channels
WeightParams alpha = 1;
}
/**
* An exponential linear unit (ELU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq 0 \\
* \alpha (e^x - 1) & \text{if } x < 0
* \end{cases}
*/
message ActivationELU {
float alpha = 1;
}
/**
* A thresholded rectified linear unit (ReLU) activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \begin{cases}
* x & \text{if } x \geq \alpha \\
* 0 & \text{if } x < \alpha
* \end{cases}
*/
message ActivationThresholdedReLU {
float alpha = 1;
}
/**
* A softsign activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \dfrac{x}{1 + |x|}
*/
message ActivationSoftsign {
}
/**
* A softplus activation function.
*
* This function has the following formula:
*
* .. math::
* f(x) = \text{log}(1 + e^x)
*/
message ActivationSoftplus {
}
/**
* A parametric softplus activation function,
* which takes ``[C]`` or ``[C,H,W]`` as an input and
* applies different parameters in each channel dimension
* (shared across the ``H`` and ``W`` components).
*
* This function has the following formula:
*
* .. math::
* f(x_i) = \alpha_i \text{log}(1 + e^{\beta_i x_i}) \;,\;i=1,...,C
*/
message ActivationParametricSoftplus {
// If length is 1, same value is used for all channels
WeightParams alpha = 1; //parameter of length C or 1
WeightParams beta = 2; //parameter of length C or 1
}
message ActivationParams {
oneof NonlinearityType {
ActivationLinear linear = 5;
ActivationReLU ReLU = 10;
ActivationLeakyReLU leakyReLU = 15;
ActivationThresholdedReLU thresholdedReLU = 20;
ActivationPReLU PReLU = 25;
ActivationTanh tanh = 30;
ActivationScaledTanh scaledTanh = 31;
ActivationSigmoid sigmoid = 40;
ActivationSigmoidHard sigmoidHard = 41;
ActivationELU ELU = 50;
ActivationSoftsign softsign = 60;
ActivationSoftplus softplus = 70;
ActivationParametricSoftplus parametricSoftplus = 71;
}
}
/**
* A single neural network layer.
*/
message NeuralNetworkLayer {
string name = 1; //descriptive name of the layer
repeated string input = 2;
repeated string output = 3;
oneof layer {
// start at 100 here
ConvolutionLayerParams convolution = 100;
PoolingLayerParams pooling = 120;
ActivationParams activation = 130;
InnerProductLayerParams innerProduct = 140;
EmbeddingLayerParams embedding = 150;
//normalization related layers
BatchnormLayerParams batchnorm = 160;
MeanVarianceNormalizeLayerParams mvn = 165;
L2NormalizeLayerParams l2normalize = 170;
SoftmaxLayerParams softmax = 175;
LRNLayerParams lrn = 180;
CropLayerParams crop = 190;
PaddingLayerParams padding = 200;
UpsampleLayerParams upsample = 210;
UnaryFunctionLayerParams unary = 220;
//elementwise operations
AddLayerParams add = 230;
MultiplyLayerParams multiply = 231;
AverageLayerParams average = 240;
ScaleLayerParams scale = 245;
BiasLayerParams bias = 250;
MaxLayerParams max = 260;
MinLayerParams min = 261;
DotProductLayerParams dot = 270;
ReduceLayerParams reduce = 280;
LoadConstantLayerParams loadConstant = 290;
//data reorganization
ReshapeLayerParams reshape = 300;
FlattenLayerParams flatten = 301;
PermuteLayerParams permute = 310;
ConcatLayerParams concat = 320;
SplitLayerParams split = 330;
SequenceRepeatLayerParams sequenceRepeat = 340;
ReorganizeDataLayerParams reorganizeData = 345;
SliceLayerParams slice = 350;
//Recurrent Layers
SimpleRecurrentLayerParams simpleRecurrent = 400;
GRULayerParams gru = 410;
UniDirectionalLSTMLayerParams uniDirectionalLSTM = 420;
BiDirectionalLSTMLayerParams biDirectionalLSTM = 430;
// Custom (user-implemented) Layer
CustomLayerParams custom = 500;
}
}
/// Border Amounts
/// --------------
/**
* Specifies the amount of spatial border to be either padded or cropped.
*
* For padding:
*
* .. code::
*
* H_out = borderAmounts[0].startEdgeSize + H_in + borderAmounts[0].endEdgeSize
* W_out = borderAmounts[1].startEdgeSize + W_in + borderAmounts[1].endEdgeSize
*
* topPaddingAmount == Height startEdgeSize
* bottomPaddingAmount == Height endEdgeSize
* leftPaddingAmount == Width startEdgeSize
* rightPaddingAmount == Width endEdgeSize
*
* For cropping:
*
* .. code::
*
* H_out = (-borderAmounts[0].startEdgeSize) + H_in + (-borderAmounts[0].endEdgeSize)
* W_out = (-borderAmounts[1].startEdgeSize) + W_in + (-borderAmounts[1].endEdgeSize)
*
* topCropAmount == Height startEdgeSize
* bottomCropAmount == Height endEdgeSize
* leftCropAmount == Width startEdgeSize
* rightCropAmount == Width endEdgeSize
*/
message BorderAmounts {
message EdgeSizes {
/**
* The amount to be padded or cropped from the beginning.
*/
uint64 startEdgeSize = 1;
/**
* The amount to be padded or cropped from the end.
*/
uint64 endEdgeSize = 2;
}
/**
* The border amounts.
* This must be length 2 in the order ``[H, W]``.
*/
repeated EdgeSizes borderAmounts = 10;
}
/**
* Specifies the type of padding to be used with Convolution/Deconvolution and Pooling layers.
* After padding, input spatial shape: ``[H_in, W_in]``, gets modified to the
* output spatial shape ``[H_out, W_out]``.
*
* .. code::
*
* topPaddingAmount == Height startEdgeSize == borderAmounts[0].startEdgeSize
* bottomPaddingAmount == Height endEdgeSize == borderAmounts[0].endEdgeSize
* leftPaddingAmount == Width startEdgeSize == borderAmounts[1].startEdgeSize
* rightPaddingAmount == Width endEdgeSize == borderAmounts[1].endEdgeSize
*
* With Convolution or Pooling:
*
* .. code::
*
* H_out = int_division_round_down((H_in + topPaddingAmount + bottomPaddingAmount - KernelSize[0]),stride[0]) + 1
*
* which is same as:
*
* .. code::
*
* H_out = int_division_round_up((H_in + topPaddingAmount + bottomPaddingAmount - KernelSize[0] + 1),stride[0])
*
* With Deconvolution:
*
* .. code::
*
* H_out = (H_in-1) * stride[0] + kernelSize[0] - (topPaddingAmount + bottomPaddingAmount)
*
*
* The equivalent expressions hold true for ``W_out`` as well.
*
*
* By default, the values of ``paddingAmounts`` are set to ``0``,
* which results in a "true" valid padding.
* If non-zero values are provided for ``paddingAmounts``,
* "valid" convolution/pooling is performed within the spatially expanded input.
*
*/
message ValidPadding {
BorderAmounts paddingAmounts = 1;
}
/**
* Specifies the type of padding to be used with Convolution/Deconvolution and pooling layers.
* After padding, input spatial shape: ``[H_in, W_in]``, gets modified to the
* output spatial shape ``[H_out, W_out]``.
* With Convolution or pooling:
*
* .. code::
*
* H_out = int_division_round_up(H_in,stride[0])
* W_out = int_division_round_up(W_in,stride[1])
*
* This is achieved by using the following padding amounts:
*
* .. code::
*
* totalPaddingHeight = max(0,(H_out-1) * stride[0] + KernelSize[0] - Hin)
* totalPaddingWidth = max(0,(W_out-1) * stride[1] + KernelSize[1] - Win)
*
* There are two modes of asymmetry:
* ``BOTTOM_RIGHT_HEAVY``, and ``TOP_LEFT_HEAVY``.
*
* If the mode is ``BOTTOM_RIGHT_HEAVY``:
*
* .. code::
*
* topPaddingAmount = floor(totalPaddingHeight / 2)
* bottomPaddingAmount = totalPaddingHeight - topPaddingAmount
* leftPaddingAmount = floor(totalPaddingWidth / 2)
* rightPaddingAmount = totalPaddingWidth - leftPaddingAmount
*
* If the mode is ``TOP_LEFT_HEAVY``:
*
* .. code::
*
* bottomPaddingAmount = floor(totalPaddingHeight / 2)
* topPaddingAmount = totalPaddingHeight - bottomPaddingAmount
* rightPaddingAmount = floor(totalPaddingWidth / 2)
* leftPaddingAmount = totalPaddingWidth - rightPaddingAmount
*
*
* With Deconvolution:
*
* .. code::
*
* H_out = H_in * stride[0]
* W_out = W_in * stride[1]
*/
message SamePadding {
enum SamePaddingMode {
BOTTOM_RIGHT_HEAVY = 0;
TOP_LEFT_HEAVY = 1;
}
SamePaddingMode asymmetryMode = 1;
}
/**
* Weights for layer parameters.
* Weights are stored as repeated floating point numbers
* using row-major ordering
* and can represent 1-, 2-, 3-, or 4-dimensional data.
*/
message WeightParams {
/**
* Values specified in single / float / FP32 precision.
*/
repeated float floatValue = 1;
/**
* Values in 16-bit half precision floating point.
*/
bytes float16Value = 2;
/**
* Raw value specification for smaller types. Currently only supported by custom layer implementations.
*/
bytes rawValue = 30;
}
/// Layers
/// ------
/**
* A layer that performs spatial convolution or deconvolution.
*
* .. code::
*
* y = ConvolutionLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with shape ``[inputChannels,inputHeight,inputWidth]`` or ``[C_in, H_in, W_in]``.
*
* Output
* A blob with shape ``[outputChannels,outputHeight,outputWidth]`` or ``[C_out, H_out, W_out]``.
*
*
* If ``dilationFactor`` is not 1, effective kernel size is
* modified as follows:
*
* .. code::
*
* KernelSize[0] <-- (kernelSize[0]-1) * dilationFactor[0] + 1
* KernelSize[1] <-- (kernelSize[1]-1) * dilationFactor[1] + 1
*
* Type of padding can be ``valid`` or ``same``. Output spatial dimensions depend on the
* the type of padding. For details, refer to the descriptions of the messages "ValidPadding"
* and "SamePadding". Padded values are all zeros.
*
* For Deconvolution, ``ConvolutionPaddingType`` (``valid`` or ``same``) is ignored when ``outputShape`` is set.
*
*
*/
message ConvolutionLayerParams {
/**
* The number of kernels.
* Same as ``C_out`` used in the layer description.
*/
uint64 outputChannels = 1;
/**
* Channel dimension of the kernels.
* Must be equal to ``inputChannels / nGroups``, if isDeconvolution == False
* Must be equal to ``inputChannels``, if isDeconvolution == True
*/
uint64 kernelChannels = 2;
/**
* Group convolution, i.e. weight reuse along channel axis.
* Input and kernels are divided into g groups
* and convolution / deconvoltuion is applied within the groups independently.
* If not set or 0, it is set to the default value 1.
*/
uint64 nGroups = 10;
/**
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[3, 3]`` is used.
*/
repeated uint64 kernelSize = 20;
/**
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 stride = 30;
/**
* Must be length 2 in order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
* It is ignored if ``isDeconvolution == true``.
*/
repeated uint64 dilationFactor = 40;
/**
* The type of padding.
*/
oneof ConvolutionPaddingType {
ValidPadding valid = 50;
SamePadding same = 51;
}
/**
* Flag to specify whether it is a deconvolution layer.
*/
bool isDeconvolution = 60;
/**
* Flag to specify whether a bias is to be added or not.
*/
bool hasBias = 70;
/**
* Weights associated with this layer.
* If convolution (``isDeconvolution == false``), weights have the shape
* ``[outputChannels, kernelChannels, kernelHeight, kernelWidth]``, where kernelChannels == inputChannels / nGroups
* If deconvolution (``isDeconvolution == true``) weights have the shape
* ``[kernelChannels, outputChannels / nGroups, kernelHeight, kernelWidth]``, where kernelChannels == inputChannels
*/
WeightParams weights = 90;
WeightParams bias = 91; /// Must be of size [outputChannels].
/**
* The output shape, which has length 2 ``[H_out, W_out]``.
* This is used only for deconvolution (``isDeconvolution == true``).
* If not set, the deconvolution output shape is calculated
* based on ``ConvolutionPaddingType``.
*/
repeated uint64 outputShape = 100;
}
/**
* A layer that performs a matrix vector product.
* This is equivalent to a fully-connected, or dense layer.
*
* .. code::
*
* y = InnerProductLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with shape ``[C_in]`` or ``[C_in, 1, 1]``, where ``C_in`` is equal to ``inputChannels``.
*
* Output
* A blob with shape ``[C_out]``, where ``C_out`` is equal to ``outputChannels``.
*/
message InnerProductLayerParams {
uint64 inputChannels = 1; /// Input size: C_in.
uint64 outputChannels = 2; /// Output size: C_out.
bool hasBias = 10; /// Whether a bias is added or not.
WeightParams weights = 20; /// Weight matrix [C_out, C_in].
WeightParams bias = 21; /// Bias vector [C_out].
}
/**
* A layer that performs a matrix lookup and optionally adds a bias.
*
* .. code::
*
* y = EmbeddingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A sequence of integers with shape ``[1]`` or ``[1, 1, 1]``, (equivalent to ``[Seq_length, 1, 1, 1]``).
* Input values must be in the range ``[0, inputDim - 1]``.
*
* Output
* A sequence of 1-dimensional features of size ``outputChannels``
* (equivalent to ``[Seq_length, outputChannels, 1, 1]``).
*/
message EmbeddingLayerParams {
uint64 inputDim = 1; /// Size of the input dictionary.
uint64 outputChannels = 2; /// Size of the output vectors.
bool hasBias = 10; /// Whether a bias is added or not.
WeightParams weights = 20; /// 2-D weights of dimensions [outputChannels, inputDim].
WeightParams bias = 21; /// Bias of size [outputChannels].
}
/**
* A layer that performs batch normalization,
* which is performed along the channel axis,
* and repeated along the other axes, if present.
*
* .. code::
*
* y = BatchnormLayer(x)
*
* Requires 1 input and produces 1 output.
*
* This operation is described by the following formula:
*
* .. math::
* y_i = \gamma_i \dfrac{ (x_i - \mu_i)}{\sqrt{\sigma_i^2 + \epsilon}} + \beta_i \;,\;i=1,....,C
*
* Input
* A blob with shape ``[C]`` or ``[C, H, W]``.
*
* Output
* A blob with the same shape as the input.
*/
message BatchnormLayerParams {
uint64 channels = 1; /// Size of the channel dimension in the input.
/**
* If ``computeMeanVar == true``,
* the mean and variance are calculated from either
* the single input instance, if ``instanceNormalization == true``,
* or the whole batch, if ``instanceNormalization = false``.
* and the values provided in parameters "mean" and "variance" are ignored.
*/
bool computeMeanVar = 5;
bool instanceNormalization = 6;
/**
* A small constant to avoid division by 0 while normalizing by variance.
* Defaults to ``1e-5`` if not set or set to ``0``.
*/
float epsilon = 10;
WeightParams gamma=15; /// Parameter of length [channels]
WeightParams beta=16; /// Parameter of length [channels]
WeightParams mean=17; /// Parameter of length [channels]
WeightParams variance=18; /// Parameter of length [channels]
}
/**
* A spatial pooling layer.
*
* .. code::
*
* y = PoolingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with shape ``[C, H_in, W_in]``.
* Output
* A blob with shape ``[C, H_out, W_out]``.
*
* Padding options are similar to ``ConvolutionLayerParams``
* with the additional option of ``ValidCompletePadding`` (``includeLastPixel``),
* which ensures that the last application of the kernel
* always includes the last pixel of the input image, if there is padding.
*
* .. code::
*
* H_out = int_division_round_up((H_in + 2 * paddingAmounts[0] - kernelSize[0]),Stride[0]) + 1)
* if (paddingAmounts[0] > 0 or paddingAmounts[1] > 0)
* if ((H_out - 1) * Stride >= H_in + paddingAmounts[0]) {
* H_out = H_out - 1
* }
* }
*
* The equivalent expressions hold true for ``W_out`` as well.
* Only symmetric padding is supported with this option.
*/
message PoolingLayerParams {
enum PoolingType{
MAX = 0;
AVERAGE = 1;
L2 = 2;
}
PoolingType type = 1; /// Type of pooling operation.
/**
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[3, 3]`` is used.
*/
repeated uint64 kernelSize = 10;
/**
* Must be length 2 in the order ``[H, W]``.
* If not set, default value ``[1, 1]`` is used.
*/
repeated uint64 stride = 20;
message ValidCompletePadding {
/**
* Must be length 2 in order ``[H, W]``.
* If not set, value ``[0, 0]`` is used.
*/
repeated uint64 paddingAmounts = 10;
}
oneof PoolingPaddingType {
ValidPadding valid = 30;
SamePadding same = 31;
ValidCompletePadding includeLastPixel = 32;
}
/**
* If true, padded values are excluded from the count (denominator)
* when computing average pooling.
*/
bool avgPoolExcludePadding = 50;
/**
* If true, global pooling is performed.
* Kernel size is inferred from the input data spatial dimensions.
*/
bool globalPooling = 60;
}
/**
* A layer that performs padding along spatial dimensions.
*
* .. code::
*
* y = PaddingLayer(x)
*
* Requires 1 input and produces 1 output.
*
* Input
* A blob with shape ``[C, H_in, W_in]``.
*
* Output
* A blob with shape ``[C, H_out, W_out]``.
*
* Output dimensions are calculated as follows:
*
* .. code::
*
* H_out = H_in + topPaddingAmount + bottomPaddingAmount
* W_out = W_in + leftPaddingAmount + rightPaddingAmount
*
* topPaddingAmount == Height startEdgeSize == borderAmounts[0].startEdgeSize
* bottomPaddingAmount == Height endEdgeSize == borderAmounts[0].endEdgeSize
* leftPaddingAmount == Width startEdgeSize == borderAmounts[1].startEdgeSize
* rightPaddingAmount == Width endEdgeSize == borderAmounts[1].endEdgeSize
*
* There are three types of padding:
*
* - ``PaddingConstant``, which fills a constant value at the border.
* - ``PaddingReflection``, which reflects the values at the border.
* - ``PaddingReplication``, which replicates the values at the border.
*
* Given the following input:
*
* .. code::
*
* [1, 3, 4] : 1 2 3 4
* 5 6 7 8
* 9 10 11 12
*
* Here is the output of applying the padding
* ``(top=2, left=2, bottom=0, right=0)``
* with each of the supported types:
*
* - ``PaddingConstant`` (``value = 0``):
* .. code::
*
* [1, 5, 6] : 0 0 0 0 0 0
* 0 0 0 0 0 0
* 0 0 1 2 3 4
* 0 0 5 6 7 8
* 0 0 9 10 11 12
*
* - ``PaddingReflection``:
* .. code::
*
* [1, 5, 6] : 11 10 9 10 11 12
* 7 6 5 6 7 8
* 3 2 1 2 3 4
* 7 6 5 6 7 8
* 11 10 9 10 11 12
*
* - ``PaddingReplication``:
* .. code::
*
* [1, 5, 6] : 1 1 1 2 3 4
* 1 1 1 2 3 4
* 1 1 1 2 3 4
* 5 5 5 6 7 8
* 9 9 9 10 11 12
*/
message PaddingLayerParams {
/**
* Fill a constant value in the padded region.
*/
message PaddingConstant {
float value = 1;
}
/**
* Reflect the values at the border for padding.
*/
message PaddingReflection {
}
/**
* Replicate the values at the border for padding.
*/
message PaddingReplication {
}
oneof PaddingType {
PaddingConstant constant = 1;
PaddingReflection reflection = 2;
PaddingReplication replication = 3;
}
BorderAmounts paddingAmounts = 10; /// Amounts to be padded to the input.
}
/**
* A layer that concatenates along the channel axis (default) or sequence axis.
*
* .. code::
*
* y = ConcatLayer(x1,x2,....)
*
* Requires more than 1 input and produces 1 output.
*
* The input and output formats are dependent on ``sequenceConcat``.
*
* If ``sequenceConcat == true``:
*
* Input
* Sequences of length ``Seq_i`` of blobs with shape ``[C, H, W]``.
* Output
* A Sequence of length ``summation(Seq_i)`` of blobs with shape ``[C, H, W]``.
*
* If ``sequenceConcat == false``: