forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayersApi.cs
More file actions
1161 lines (1098 loc) · 66.6 KB
/
LayersApi.cs
File metadata and controls
1161 lines (1098 loc) · 66.6 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
using System;
using Tensorflow.Framework.Models;
using Tensorflow.Keras.ArgsDefinition;
using Tensorflow.Keras.ArgsDefinition.Core;
using Tensorflow.Keras.Engine;
using Tensorflow.Keras.Layers;
using Tensorflow.NumPy;
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
namespace Tensorflow.Keras.Layers
{
public partial class LayersApi : ILayersApi
{
public IPreprocessing preprocessing { get; } = new Preprocessing();
/// <summary>
/// Layer that normalizes its inputs.
/// Batch normalization applies a transformation that maintains the mean output close to 0 and the output standard deviation close to 1.
/// Importantly, batch normalization works differently during training and during inference.
///
/// http://arxiv.org/abs/1502.03167
/// </summary>
/// <param name="axis">The axis that should be normalized (typically the features axis).
/// For instance, after a Conv2D layer with data_format="channels_first", set axis=1 in BatchNormalization.
/// </param>
/// <param name="momentum">Momentum for the moving average.</param>
/// <param name="epsilon">Small float added to variance to avoid dividing by zero.</param>
/// <param name="center">If True, add offset of beta to normalized tensor. If False, beta is ignored.</param>
/// <param name="scale">If True, multiply by gamma. If False, gamma is not used. When the next layer is linear (also e.g. nn.relu), this can be disabled since the scaling will be done by the next layer.</param>
/// <param name="beta_initializer">Initializer for the beta weight.</param>
/// <param name="gamma_initializer">Initializer for the gamma weight.</param>
/// <param name="moving_mean_initializer">Initializer for the moving mean.</param>
/// <param name="moving_variance_initializer">Initializer for the moving variance.</param>
/// <param name="trainable">Boolean, if True the variables will be marked as trainable.</param>
/// <param name="name">Layer name.</param>
/// <param name="renorm">Whether to use Batch Renormalization. This adds extra variables during training. The inference is the same for either value of this parameter.</param>
/// <param name="renorm_momentum">Momentum used to update the moving means and standard deviations with renorm.
/// Unlike momentum, this affects training and should be neither too small (which would add noise) nor too large (which would give stale estimates).
/// Note that momentum is still applied to get the means and variances for inference.
/// </param>
/// <returns>Tensor of the same shape as input.</returns>
public ILayer BatchNormalization(int axis = -1,
float momentum = 0.99f,
float epsilon = 0.001f,
bool center = true,
bool scale = true,
IInitializer beta_initializer = null,
IInitializer gamma_initializer = null,
IInitializer moving_mean_initializer = null,
IInitializer moving_variance_initializer = null,
bool trainable = true,
string name = null,
bool renorm = false,
float renorm_momentum = 0.99f)
=> new BatchNormalization(new BatchNormalizationArgs
{
Axis = axis,
Momentum = momentum,
Epsilon = epsilon,
Center = center,
Scale = scale,
BetaInitializer = beta_initializer ?? tf.zeros_initializer,
GammaInitializer = gamma_initializer ?? tf.ones_initializer,
MovingMeanInitializer = moving_mean_initializer ?? tf.zeros_initializer,
MovingVarianceInitializer = moving_variance_initializer ?? tf.ones_initializer,
Renorm = renorm,
RenormMomentum = renorm_momentum,
Trainable = trainable,
Name = name
});
/// <summary>
/// 1D convolution layer (e.g. temporal convolution).
/// This layer creates a convolution kernel that is convolved with the layer input over a single spatial(or temporal) dimension to produce a tensor of outputs.If use_bias is True, a bias vector is created and added to the outputs.Finally, if activation is not None, it is applied to the outputs as well.
/// </summary>
/// <param name="filters">Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution)</param>
/// <param name="kernel_size">An integer specifying the width of the 1D convolution window.</param>
/// <param name="strides">An integer specifying the stride of the convolution window . Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.</param>
/// <param name="padding">one of "valid" or "same" (case-insensitive). "valid" means no padding. "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.</param>
/// <param name="data_format">A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be channels_last.</param>
/// <param name="dilation_rate">An integer specifying the dilation rate to use for dilated convolution.Currently, specifying any dilation_rate value != 1 is incompatible with specifying any stride value != 1.</param>
/// <param name="groups">A positive integer specifying the number of groups in which the input is split along the channel axis. Each group is convolved separately with filters / groups filters. The output is the concatenation of all the groups results along the channel axis. Input channels and filters must both be divisible by groups.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (see keras.activations).</param>
/// <param name="use_bias">Boolean, whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">Initializer for the kernel weights matrix (see keras.initializers).</param>
/// <param name="bias_initializer">Initializer for the bias vector (see keras.initializers).</param>
/// <returns>A tensor of rank 3 representing activation(conv1d(inputs, kernel) + bias).</returns>
public ILayer Conv1D(int filters,
Shape kernel_size,
int strides = 1,
string padding = "valid",
string data_format = "channels_last",
int dilation_rate = 1,
int groups = 1,
string activation = null,
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string bias_initializer = "zeros")
=> new Conv1D(new Conv1DArgs
{
Rank = 1,
Filters = filters,
KernelSize = kernel_size ?? new Shape(1, 5),
Strides = strides,
Padding = padding,
DataFormat = data_format,
DilationRate = dilation_rate,
Groups = groups,
UseBias = use_bias,
Activation = keras.activations.GetActivationFromName(activation),
KernelInitializer = GetInitializerByName(kernel_initializer),
BiasInitializer = GetInitializerByName(bias_initializer)
});
public ILayer Conv2D(int filters,
Shape kernel_size = null,
Shape strides = null,
string padding = "valid")
=> new Conv2D(new Conv2DArgs
{
Rank = 2,
Filters = filters,
KernelSize = (kernel_size == null) ? (5, 5) : kernel_size,
Strides = strides == null ? (1, 1) : strides,
Padding = padding,
DataFormat = null,
DilationRate = (1, 1),
Groups = 1,
UseBias = false,
KernelRegularizer = null,
KernelInitializer =tf.glorot_uniform_initializer,
BiasInitializer = tf.zeros_initializer,
BiasRegularizer = null,
ActivityRegularizer = null,
Activation = keras.activations.Linear,
});
/// <summary>
/// 2D convolution layer (e.g. spatial convolution over images).
/// This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs.
/// If use_bias is True, a bias vector is created and added to the outputs.Finally, if activation is not None, it is applied to the outputs as well.
/// </summary>
/// <param name="filters">Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution)</param>
/// <param name="kernel_size">An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.</param>
/// <param name="strides">An integer or tuple/list of 2 integers, specifying the strides of the convolution along the height and width. Can be a single integer to specify the same value for all spatial dimensions. Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.</param>
/// <param name="padding">one of "valid" or "same" (case-insensitive). "valid" means no padding. "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.</param>
/// <param name="data_format">A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be channels_last.</param>
/// <param name="dilation_rate">an integer or tuple/list of 2 integers, specifying the dilation rate to use for dilated convolution. Can be a single integer to specify the same value for all spatial dimensions. Currently, specifying any dilation_rate value != 1 is incompatible with specifying any stride value != 1.</param>
/// <param name="groups">A positive integer specifying the number of groups in which the input is split along the channel axis. Each group is convolved separately with filters / groups filters. The output is the concatenation of all the groups results along the channel axis. Input channels and filters must both be divisible by groups.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (see keras.activations).</param>
/// <param name="use_bias">Boolean, whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">Initializer for the kernel weights matrix (see keras.initializers).</param>
/// <param name="bias_initializer">Initializer for the bias vector (see keras.initializers).</param>
/// <param name="kernel_regularizer">Regularizer function applied to the kernel weights matrix (see keras.regularizers).</param>
/// <param name="bias_regularizer">Regularizer function applied to the bias vector (see keras.regularizers).</param>
/// <param name="activity_regularizer">Regularizer function applied to the output of the layer (its "activation") (see keras.regularizers).</param>
/// <returns>A tensor of rank 4+ representing activation(conv2d(inputs, kernel) + bias).</returns>
public ILayer Conv2D(int filters,
Shape kernel_size = null,
Shape strides = null,
string padding = "valid",
string data_format = null,
Shape dilation_rate = null,
int groups = 1,
Activation activation = null,
bool use_bias = true,
IInitializer kernel_initializer = null,
IInitializer bias_initializer = null,
IRegularizer kernel_regularizer = null,
IRegularizer bias_regularizer = null,
IRegularizer activity_regularizer = null)
=> new Conv2D(new Conv2DArgs
{
Rank = 2,
Filters = filters,
KernelSize = (kernel_size == null) ? (5, 5) : kernel_size,
Strides = strides == null ? (1, 1) : strides,
Padding = padding,
DataFormat = data_format,
DilationRate = dilation_rate == null ? (1, 1) : dilation_rate,
Groups = groups,
UseBias = use_bias,
KernelRegularizer = kernel_regularizer,
KernelInitializer = kernel_initializer == null ? tf.glorot_uniform_initializer : kernel_initializer,
BiasInitializer = bias_initializer == null ? tf.zeros_initializer : bias_initializer,
BiasRegularizer = bias_regularizer,
ActivityRegularizer = activity_regularizer,
Activation = activation ?? keras.activations.Linear,
});
/// <summary>
/// 2D convolution layer (e.g. spatial convolution over images).
/// This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs.
/// If use_bias is True, a bias vector is created and added to the outputs.Finally, if activation is not None, it is applied to the outputs as well.
/// </summary>
/// <param name="filters">Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution)</param>
/// <param name="kernel_size">An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.</param>
/// <param name="strides">An integer or tuple/list of 2 integers, specifying the strides of the convolution along the height and width. Can be a single integer to specify the same value for all spatial dimensions. Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.</param>
/// <param name="padding">one of "valid" or "same" (case-insensitive). "valid" means no padding. "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.</param>
/// <param name="data_format">A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be channels_last.</param>
/// <param name="dilation_rate">an integer or tuple/list of 2 integers, specifying the dilation rate to use for dilated convolution. Can be a single integer to specify the same value for all spatial dimensions. Currently, specifying any dilation_rate value != 1 is incompatible with specifying any stride value != 1.</param>
/// <param name="groups">A positive integer specifying the number of groups in which the input is split along the channel axis. Each group is convolved separately with filters / groups filters. The output is the concatenation of all the groups results along the channel axis. Input channels and filters must both be divisible by groups.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (see keras.activations).</param>
/// <param name="use_bias">Boolean, whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">The name of the initializer for the kernel weights matrix (see keras.initializers).</param>
/// <param name="bias_initializer">The name of the initializer for the bias vector (see keras.initializers).</param>
/// <returns>A tensor of rank 4+ representing activation(conv2d(inputs, kernel) + bias).</returns>
public ILayer Conv2D(int filters,
Shape kernel_size = null,
Shape strides = null,
string padding = "valid",
string data_format = null,
Shape dilation_rate = null,
int groups = 1,
string activation = null,
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string bias_initializer = "zeros")
=> new Conv2D(new Conv2DArgs
{
Rank = 2,
Filters = filters,
KernelSize = (kernel_size == null) ? (5,5) : kernel_size,
Strides = strides == null ? (1, 1) : strides,
Padding = padding,
DataFormat = data_format,
DilationRate = dilation_rate == null ? (1, 1) : dilation_rate,
Groups = groups,
UseBias = use_bias,
KernelInitializer = GetInitializerByName(kernel_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
Activation = keras.activations.GetActivationFromName(activation)
});
public ILayer DepthwiseConv2D(Shape kernel_size = null,
Shape strides = null,
string padding = "valid",
string data_format = null,
Shape dilation_rate = null,
int groups = 1,
int depth_multiplier = 1,
string activation = null,
bool use_bias = false,
string kernel_initializer = "glorot_uniform",
string bias_initializer = "zeros",
string depthwise_initializer = "glorot_uniform"
)
=> new DepthwiseConv2D(new DepthwiseConv2DArgs
{
Rank = 2,
Filters = 1,
KernelSize = (kernel_size == null) ? (5, 5) : kernel_size,
Strides = strides == null ? (1) : strides,
Padding = padding,
DepthMultiplier = depth_multiplier,
DataFormat = data_format,
DilationRate = dilation_rate == null ? (1) : dilation_rate,
Groups = groups,
UseBias = use_bias,
KernelInitializer = GetInitializerByName(kernel_initializer),
DepthwiseInitializer = GetInitializerByName(depthwise_initializer == null ? kernel_initializer : depthwise_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
Activation = keras.activations.GetActivationFromName(activation),
});
/// <summary>
/// Transposed convolution layer (sometimes called Deconvolution).
/// </summary>
/// <param name="filters">Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution)</param>
/// <param name="kernel_size">An integer or tuple/list of 2 integers, specifying the height and width of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.</param>
/// <param name="strides">An integer or tuple/list of 2 integers, specifying the strides of the convolution along the height and width. Can be a single integer to specify the same value for all spatial dimensions. Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.</param>
/// <param name="output_padding">one of "valid" or "same" (case-insensitive). "valid" means no padding. "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.</param>
/// <param name="data_format">A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch_size, height, width, channels) while channels_first corresponds to inputs with shape (batch_size, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be channels_last.</param>
/// <param name="dilation_rate">an integer or tuple/list of 2 integers, specifying the dilation rate to use for dilated convolution. Can be a single integer to specify the same value for all spatial dimensions. Currently, specifying any dilation_rate value != 1 is incompatible with specifying any stride value != 1.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (see keras.activations).</param>
/// <param name="use_bias">Boolean, whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">The name of the initializer for the kernel weights matrix (see keras.initializers).</param>
/// <param name="bias_initializer">The name of the initializer for the bias vector (see keras.initializers).</param>
/// <param name="kernel_regularizer">The name of the regularizer function applied to the kernel weights matrix (see keras.regularizers).</param>
/// <param name="bias_regularizer">The name of the regularizer function applied to the bias vector (see keras.regularizers).</param>
/// <param name="activity_regularizer">The name of the regularizer function applied to the output of the layer (its "activation") (see keras.regularizers).</param>
/// <returns>A tensor of rank 4+ representing activation(conv2d(inputs, kernel) + bias).</returns>
public ILayer Conv2DTranspose(int filters,
Shape kernel_size = null,
Shape strides = null,
string output_padding = "valid",
string data_format = null,
Shape dilation_rate = null,
string activation = null,
bool use_bias = false,
string kernel_initializer = null,
string bias_initializer = null,
string kernel_regularizer = null,
string bias_regularizer = null,
string activity_regularizer = null)
=> new Conv2DTranspose(new Conv2DTransposeArgs
{
Rank = 2,
Filters = filters,
KernelSize = (kernel_size == null) ? (5, 5) : kernel_size,
Strides = strides == null ? (1, 1) : strides,
Padding = output_padding,
DataFormat = data_format,
DilationRate = dilation_rate == null ? (1, 1) : dilation_rate,
UseBias = use_bias,
KernelInitializer = GetInitializerByName(kernel_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
Activation = keras.activations.GetActivationFromName(activation)
});
/// <summary>
/// Just your regular densely-connected NN layer.
///
/// Dense implements the operation: output = activation(dot(input, kernel) + bias) where activation is the
/// element-wise activation function passed as the activation argument, kernel is a weights matrix created by the layer,
/// and bias is a bias vector created by the layer (only applicable if use_bias is True).
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (ie. "linear" activation: a(x) = x).</param>
/// <param name="kernel_initializer">Initializer for the kernel weights matrix.</param>
/// <param name="use_bias">Boolean, whether the layer uses a bias vector.</param>
/// <param name="bias_initializer">Initializer for the bias vector.</param>
/// <param name="input_shape">N-D tensor with shape: (batch_size, ..., input_dim). The most common situation would be a 2D input with shape (batch_size, input_dim).</param>
/// <returns>N-D tensor with shape: (batch_size, ..., units). For instance, for a 2D input with shape (batch_size, input_dim), the output would have shape (batch_size, units).</returns>
public ILayer Dense(int units,
Activation activation = null,
IInitializer kernel_initializer = null,
bool use_bias = true,
IInitializer bias_initializer = null,
Shape input_shape = null)
=> new Dense(new DenseArgs
{
Units = units,
Activation = activation ?? keras.activations.Linear,
KernelInitializer = kernel_initializer ?? tf.glorot_uniform_initializer,
BiasInitializer = bias_initializer ?? (use_bias ? tf.zeros_initializer : null),
InputShape = input_shape
});
/// <summary>
/// Just your regular densely-connected NN layer.
///
/// Dense implements the operation: output = activation(dot(input, kernel) + bias) where activation is the
/// element-wise activation function passed as the activation argument, kernel is a weights matrix created by the layer,
/// and bias is a bias vector created by the layer (only applicable if use_bias is True).
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <returns>N-D tensor with shape: (batch_size, ..., units). For instance, for a 2D input with shape (batch_size, input_dim), the output would have shape (batch_size, units).</returns>
public ILayer Dense(int units)
=> new Dense(new DenseArgs
{
Units = units,
Activation = keras.activations.GetActivationFromName("linear")
});
/// <summary>
/// Just your regular densely-connected NN layer.
///
/// Dense implements the operation: output = activation(dot(input, kernel) + bias) where activation is the
/// element-wise activation function passed as the activation argument, kernel is a weights matrix created by the layer,
/// and bias is a bias vector created by the layer (only applicable if use_bias is True).
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <param name="activation">Activation function to use. If you don't specify anything, no activation is applied (ie. "linear" activation: a(x) = x).</param>
/// <param name="input_shape">N-D tensor with shape: (batch_size, ..., input_dim). The most common situation would be a 2D input with shape (batch_size, input_dim).</param>
/// <returns>N-D tensor with shape: (batch_size, ..., units). For instance, for a 2D input with shape (batch_size, input_dim), the output would have shape (batch_size, units).</returns>
public ILayer Dense(int units,
string activation = null,
Shape input_shape = null)
=> new Dense(new DenseArgs
{
Units = units,
Activation = keras.activations.GetActivationFromName(activation),
InputShape = input_shape
});
/// <summary>
/// Densely-connected layer class. aka fully-connected<br></br>
/// `outputs = activation(inputs * kernel + bias)`
/// </summary>
/// <param name="inputs"></param>
/// <param name="units">Python integer, dimensionality of the output space.</param>
/// <param name="activation"></param>
/// <param name="use_bias">Boolean, whether the layer uses a bias.</param>
/// <param name="kernel_initializer"></param>
/// <param name="bias_initializer"></param>
/// <param name="trainable"></param>
/// <param name="name"></param>
/// <param name="reuse"></param>
/// <returns></returns>
public Tensor dense(Tensor inputs,
int units,
Activation activation = null,
bool use_bias = true,
IInitializer kernel_initializer = null,
IInitializer bias_initializer = null,
bool trainable = true,
string name = null,
bool? reuse = null)
{
if (bias_initializer == null)
bias_initializer = tf.zeros_initializer;
var layer = new Dense(new DenseArgs
{
Units = units,
Activation = activation,
UseBias = use_bias,
BiasInitializer = bias_initializer,
KernelInitializer = kernel_initializer,
Trainable = trainable,
Name = name
});
return layer.Apply(inputs);
}
public ILayer EinsumDense(string equation,
Shape output_shape,
string bias_axes,
Activation activation = null,
IInitializer kernel_initializer= null,
IInitializer bias_initializer= null,
IRegularizer kernel_regularizer= null,
IRegularizer bias_regularizer= null,
IRegularizer activity_regularizer= null,
Action kernel_constraint= null,
Action bias_constraint= null) =>
new EinsumDense(new EinsumDenseArgs()
{
Equation = equation,
OutputShape = output_shape,
BiasAxes = bias_axes,
Activation = activation,
KernelInitializer = kernel_initializer ?? tf.glorot_uniform_initializer,
BiasInitializer = bias_initializer ?? tf.zeros_initializer,
KernelRegularizer = kernel_regularizer,
BiasRegularizer = bias_regularizer,
ActivityRegularizer = activity_regularizer,
KernelConstraint = kernel_constraint,
BiasConstraint = bias_constraint
});
/// <summary>
/// Applies Dropout to the input.
/// The Dropout layer randomly sets input units to 0 with a frequency of rate at each step during training time,
/// which helps prevent overfitting.Inputs not set to 0 are scaled up by 1/(1 - rate) such that the sum over all inputs is unchanged.
/// </summary>
/// <param name="rate">Float between 0 and 1. Fraction of the input units to drop.</param>
/// <param name="noise_shape">1D integer tensor representing the shape of the binary dropout mask that will be multiplied with the input. For instance,
/// if your inputs have shape (batch_size, timesteps, features) and you want the dropout mask to be the same for all timesteps,
/// you can use noise_shape=(batch_size, 1, features).
/// </param>
/// <param name="seed">An integer to use as random seed.</param>
/// <returns></returns>
public ILayer Dropout(float rate, Shape noise_shape = null, int? seed = null)
=> new Dropout(new DropoutArgs
{
Rate = rate,
NoiseShape = noise_shape,
Seed = seed
});
/// <summary>
/// Turns positive integers (indexes) into dense vectors of fixed size.
/// This layer can only be used as the first layer in a model.
/// e.g. [[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]
/// https://www.tensorflow.org/api_docs/python/tf/keras/layers/Embedding
/// </summary>
/// <param name="input_dim">Size of the vocabulary, i.e. maximum integer index + 1.</param>
/// <param name="output_dim">Dimension of the dense embedding.</param>
/// <param name="embeddings_initializer">Initializer for the embeddings matrix (see keras.initializers).</param>
/// <param name="mask_zero"></param>
/// <returns></returns>
public ILayer Embedding(int input_dim,
int output_dim,
IInitializer embeddings_initializer = null,
bool mask_zero = false,
Shape input_shape = null,
int input_length = -1)
=> new Embedding(new EmbeddingArgs
{
InputDim = input_dim,
OutputDim = output_dim,
MaskZero = mask_zero,
InputShape = input_shape ?? input_length,
InputLength = input_length,
EmbeddingsInitializer = embeddings_initializer
});
/// <summary>
/// Flattens the input. Does not affect the batch size.
/// </summary>
/// <param name="data_format">A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.
/// channels_last corresponds to inputs with shape (batch, ..., channels) while channels_first corresponds to inputs with shape (batch, channels, ...).
/// It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json.
/// If you never set it, then it will be "channels_last".
/// </param>
/// <returns></returns>
public ILayer Flatten(string data_format = null)
=> new Flatten(new FlattenArgs
{
DataFormat = data_format
});
/// <summary>
/// `Input()` is used to instantiate a Keras tensor.
/// Keras tensor is a TensorFlow symbolic tensor object, which we augment with certain attributes that allow us
/// to build a Keras model just by knowing the inputs and outputs of the model.
/// </summary>
/// <param name="shape">A shape tuple not including the batch size.</param>
/// <param name="name">An optional name string for the layer. Should be unique in a model (do not reuse the same name twice). It will be autogenerated if it isn't provided.</param>
/// <param name="sparse">A boolean specifying whether the placeholder to be created is sparse. Only one of 'ragged' and 'sparse' can be True.
/// Note that, if sparse is False, sparse tensors can still be passed into the input - they will be densified with a default value of 0.
/// </param>
/// <param name="ragged">A boolean specifying whether the placeholder to be created is ragged. Only one of 'ragged' and 'sparse' can be True.
/// In this case, values of 'None' in the 'shape' argument represent ragged dimensions. For more information about RaggedTensors, see this guide.
/// </param>
/// <returns>A tensor.</returns>
public KerasTensor Input(Shape shape = null,
int batch_size = -1,
string name = null,
TF_DataType dtype = TF_DataType.DtInvalid,
bool sparse = false,
Tensor tensor = null,
bool ragged = false,
TypeSpec type_spec = null,
Shape batch_input_shape = null,
Shape batch_shape = null)
{
if(sparse && ragged)
{
throw new ValueError("Cannot set both `sparse` and `ragged` to `true` in a Keras `Input`.");
}
InputLayerArgs input_layer_config = new()
{
Name = name,
DType = dtype,
Sparse = sparse,
Ragged = ragged,
InputTensor = tensor,
// skip the `type_spec`
};
if(shape is not null && batch_input_shape is not null)
{
throw new ValueError("Only provide the `shape` OR `batch_input_shape` argument "
+ "to Input, not both at the same time.");
}
if(batch_input_shape is null && shape is null && tensor is null && type_spec is null)
{
throw new ValueError("Please provide to Input a `shape` or a `tensor` or a `type_spec` argument. Note that " +
"`shape` does not include the batch dimension.");
}
if(batch_input_shape is not null)
{
shape = batch_input_shape["1:"];
input_layer_config.BatchInputShape = batch_input_shape;
}
else
{
input_layer_config.BatchSize = batch_size;
input_layer_config.InputShape = shape;
}
var input_layer = new InputLayer(input_layer_config);
return input_layer.InboundNodes[0].Outputs;
}
public ILayer InputLayer(Shape input_shape,
string name = null,
bool sparse = false,
bool ragged = false)
=> new InputLayer(new InputLayerArgs
{
InputShape = input_shape,
Name = name,
Sparse = sparse,
Ragged = ragged
});
/// <summary>
/// Average pooling operation for spatial data.
/// </summary>
/// <param name="pool_size"></param>
/// <param name="strides"></param>
/// <param name="padding"></param>
/// <param name="data_format"></param>
/// <returns></returns>
public ILayer AveragePooling2D(Shape pool_size = null,
Shape strides = null,
string padding = "valid",
string data_format = null)
=> new AveragePooling2D(new AveragePooling2DArgs
{
PoolSize = pool_size ?? (2, 2),
Strides = strides,
Padding = padding,
DataFormat = data_format
});
/// <summary>
/// Max pooling operation for 1D temporal data.
/// </summary>
/// <param name="pool_size">Integer, size of the max pooling window.</param>
/// <param name="strides">Integer, or null. Specifies how much the pooling window moves for each pooling step. If null, it will default to pool_size.</param>
/// <param name="padding">One of "valid" or "same" (case-insensitive). "valid" means no padding.
/// "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.
/// </param>
/// <param name="data_format">
/// A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.
/// channels_last corresponds to inputs with shape (batch, steps, features) while channels_first corresponds to inputs with shape (batch, features, steps).
/// </param>
/// <returns></returns>
public ILayer MaxPooling1D(int? pool_size = null,
int? strides = null,
string padding = "valid",
string data_format = null)
=> new MaxPooling1D(new MaxPooling1DArgs
{
PoolSize = pool_size ?? 2,
Strides = strides ?? (pool_size ?? 2),
Padding = padding,
DataFormat = data_format
});
/// <summary>
/// Max pooling operation for 2D spatial data.
/// Downsamples the input representation by taking the maximum value over the window defined by pool_size for each dimension along the features axis.
/// The window is shifted by strides in each dimension. The resulting output when using "valid" padding option has a shape(number of rows or columns)
/// of: output_shape = (input_shape - pool_size + 1) / strides)
/// The resulting output shape when using the "same" padding option is: output_shape = input_shape / strides
/// </summary>
/// <param name="pool_size">
/// Integer or tuple of 2 integers, window size over which to take the maximum.
/// (2, 2) will take the max value over a 2x2 pooling window. If only one integer is specified, the same window length will be used for both dimensions.
/// </param>
/// <param name="strides">
/// Integer, tuple of 2 integers, or null. Strides values. Specifies how far the pooling window moves for each pooling step.
/// If null, it will default to pool_size.
/// </param>
/// <param name="padding">One of "valid" or "same" (case-insensitive). "valid" means no padding.
/// "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.
/// </param>
/// <param name="data_format">
/// A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.
/// channels_last corresponds to inputs with shape (batch, height, width, channels) while channels_first corresponds to
/// inputs with shape (batch, channels, height, width).
/// It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json.
/// If you never set it, then it will be "channels_last"</param>
/// <returns></returns>
public ILayer MaxPooling2D(Shape pool_size = null,
Shape strides = null,
string padding = "valid",
string data_format = null)
=> new MaxPooling2D(new MaxPooling2DArgs
{
PoolSize = pool_size ?? (2, 2),
Strides = strides,
Padding = padding,
DataFormat = data_format
});
/// <summary>
/// Max pooling layer for 2D inputs (e.g. images).
/// </summary>
/// <param name="inputs">The tensor over which to pool. Must have rank 4.</param>
/// <param name="pool_size">
/// Integer or tuple of 2 integers, window size over which to take the maximum.
/// (2, 2) will take the max value over a 2x2 pooling window. If only one integer is specified, the same window length will be used for both dimensions.
/// </param>
/// <param name="strides">
/// Integer, tuple of 2 integers, or null. Strides values. Specifies how far the pooling window moves for each pooling step.
/// If null, it will default to pool_size.
/// </param>
/// <param name="padding">One of "valid" or "same" (case-insensitive). "valid" means no padding.
/// "same" results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input.
/// </param>
/// <param name="data_format">
/// A string, one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs.
/// channels_last corresponds to inputs with shape (batch, height, width, channels) while channels_first corresponds to
/// inputs with shape (batch, channels, height, width).
/// It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json.
/// If you never set it, then it will be "channels_last"</param>
/// <param name="name">A name for the layer</param>
/// <returns></returns>
public Tensor max_pooling2d(Tensor inputs,
int[] pool_size,
int[] strides,
string padding = "valid",
string data_format = "channels_last",
string name = null)
{
var layer = new MaxPooling2D(new MaxPooling2DArgs
{
PoolSize = pool_size,
Strides = strides,
Padding = padding,
DataFormat = data_format,
Name = name
});
return layer.Apply(inputs);
}
public ILayer LayerNormalization(Axis? axis,
float epsilon = 1e-3f,
bool center = true,
bool scale = true,
IInitializer beta_initializer = null,
IInitializer gamma_initializer = null)
=> new LayerNormalization(new LayerNormalizationArgs
{
Axis = axis ?? -1,
Epsilon = epsilon,
Center = center,
Scale = scale,
BetaInitializer = beta_initializer ?? tf.zeros_initializer
});
/// <summary>
/// Leaky version of a Rectified Linear Unit.
/// </summary>
/// <param name="alpha">Negative slope coefficient.</param>
/// <returns></returns>
public ILayer LeakyReLU(float alpha = 0.3f)
=> new LeakyReLu(new LeakyReLuArgs
{
Alpha = alpha
});
/// <summary>
/// Leaky version of a Rectified Linear Unit.
/// </summary>
/// <param name="alpha">Negative slope coefficient.</param>
/// <returns></returns>
public ILayer ReLU6()
=> new ReLu6();
public IRnnCell SimpleRNNCell(
int units,
string activation = "tanh",
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string recurrent_initializer = "orthogonal",
string bias_initializer = "zeros",
float dropout = 0f,
float recurrent_dropout = 0f)
=> new SimpleRNNCell(new SimpleRNNCellArgs
{
Units = units,
Activation = keras.activations.GetActivationFromName(activation),
UseBias = use_bias,
KernelInitializer = GetInitializerByName(kernel_initializer),
RecurrentInitializer = GetInitializerByName(recurrent_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
Dropout = dropout,
RecurrentDropout = recurrent_dropout
});
public IRnnCell StackedRNNCells(
IEnumerable<IRnnCell> cells)
=> new StackedRNNCells(cells.ToList(), new StackedRNNCellsArgs());
/// <summary>
///
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <param name="activation">The name of the activation function to use. Default: hyperbolic tangent (tanh)..</param>
/// <returns></returns>
public ILayer SimpleRNN(int units,
string activation = "tanh",
string kernel_initializer = "glorot_uniform",
string recurrent_initializer = "orthogonal",
string bias_initializer = "zeros",
bool return_sequences = false,
bool return_state = false)
=> new SimpleRNN(new SimpleRNNArgs
{
Units = units,
Activation = keras.activations.GetActivationFromName(activation),
KernelInitializer = GetInitializerByName(kernel_initializer),
RecurrentInitializer = GetInitializerByName(recurrent_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
ReturnSequences = return_sequences,
ReturnState = return_state
});
/// <summary>
///
/// </summary>
/// <param name="cell"></param>
/// <param name="return_sequences"></param>
/// <param name="return_state"></param>
/// <param name="go_backwards"></param>
/// <param name="stateful"></param>
/// <param name="unroll"></param>
/// <param name="time_major"></param>
/// <returns></returns>
public ILayer RNN(
IRnnCell cell,
bool return_sequences = false,
bool return_state = false,
bool go_backwards = false,
bool stateful = false,
bool unroll = false,
bool time_major = false)
=> new RNN(cell, new RNNArgs
{
ReturnSequences = return_sequences,
ReturnState = return_state,
GoBackwards = go_backwards,
Stateful = stateful,
Unroll = unroll,
TimeMajor = time_major
});
public ILayer RNN(
IEnumerable<IRnnCell> cell,
bool return_sequences = false,
bool return_state = false,
bool go_backwards = false,
bool stateful = false,
bool unroll = false,
bool time_major = false)
=> new RNN(cell, new RNNArgs
{
ReturnSequences = return_sequences,
ReturnState = return_state,
GoBackwards = go_backwards,
Stateful = stateful,
Unroll = unroll,
TimeMajor = time_major
});
public IRnnCell LSTMCell(int uints,
string activation = "tanh",
string recurrent_activation = "sigmoid",
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string recurrent_initializer = "orthogonal",
string bias_initializer = "zeros",
bool unit_forget_bias = true,
float dropout = 0f,
float recurrent_dropout = 0f,
int implementation = 2)
=> new LSTMCell(new LSTMCellArgs
{
Units = uints,
Activation = keras.activations.GetActivationFromName(activation),
RecurrentActivation = keras.activations.GetActivationFromName(recurrent_activation),
UseBias = use_bias,
KernelInitializer = GetInitializerByName(kernel_initializer),
RecurrentInitializer = GetInitializerByName(recurrent_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
UnitForgetBias = unit_forget_bias,
Dropout = dropout,
RecurrentDropout = recurrent_dropout,
Implementation = implementation
});
/// <summary>
/// Long Short-Term Memory layer - Hochreiter 1997.
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <param name="activation">Activation function to use. If you pass null, no activation is applied (ie. "linear" activation: a(x) = x).</param>
/// <param name="recurrent_activation">Activation function to use for the recurrent step. If you pass null, no activation is applied (ie. "linear" activation: a(x) = x).</param>
/// <param name="use_bias">Boolean (default True), whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">Initializer for the kernel weights matrix, used for the linear transformation of the inputs. Default: glorot_uniform.</param>
/// <param name="recurrent_initializer">Initializer for the recurrent_kernel weights matrix, used for the linear transformation of the recurrent state. Default: orthogonal.</param>
/// <param name="bias_initializer">Initializer for the bias vector. Default: zeros.</param>
/// <param name="unit_forget_bias">Boolean (default True). If True, add 1 to the bias of the forget gate at initialization. Setting it to true will also force bias_initializer="zeros". This is recommended in Jozefowicz et al..</param>
/// <param name="dropout">Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. Default: 0.</param>
/// <param name="recurrent_dropout">Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state. Default: 0.</param>
/// <param name="implementation"></param>
/// <param name="return_sequences">Boolean. Whether to return the last output. in the output sequence, or the full sequence. Default: False.</param>
/// <param name="return_state">Whether to return the last state in addition to the output. Default: False.</param>
/// <param name="go_backwards">Boolean (default false). If True, process the input sequence backwards and return the reversed sequence.</param>
/// <param name="stateful">Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.</param>
/// <param name="time_major">
/// The shape format of the inputs and outputs tensors. If True, the inputs and outputs will be in shape [timesteps, batch, feature],
/// whereas in the False case, it will be [batch, timesteps, feature]. Using time_major = True is a bit more efficient because it avoids transposes at the
/// beginning and end of the RNN calculation. However, most TensorFlow data is batch-major, so by default this function accepts input and emits output in batch-major form.</param>
/// <param name="unroll">
/// Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speed-up a RNN,
/// although it tends to be more memory-intensive. Unrolling is only suitable for short sequences.
/// </param>
/// <returns></returns>
public ILayer LSTM(int units,
Activation activation = null,
Activation recurrent_activation = null,
bool use_bias = true,
IInitializer kernel_initializer = null,
IInitializer recurrent_initializer = null,
IInitializer bias_initializer = null,
bool unit_forget_bias = true,
float dropout = 0f,
float recurrent_dropout = 0f,
int implementation = 2,
bool return_sequences = false,
bool return_state = false,
bool go_backwards = false,
bool stateful = false,
bool time_major = false,
bool unroll = false)
=> new LSTM(new LSTMArgs
{
Units = units,
Activation = activation ?? keras.activations.Tanh,
RecurrentActivation = recurrent_activation ?? keras.activations.Sigmoid,
KernelInitializer = kernel_initializer ?? tf.glorot_uniform_initializer,
RecurrentInitializer = recurrent_initializer ?? tf.orthogonal_initializer,
BiasInitializer = bias_initializer ?? tf.zeros_initializer,
Dropout = dropout,
RecurrentDropout = recurrent_dropout,
Implementation = implementation,
ReturnSequences = return_sequences,
ReturnState = return_state,
GoBackwards = go_backwards,
Stateful = stateful,
TimeMajor = time_major,
Unroll = unroll,
UnitForgetBias = unit_forget_bias
});
/// <summary>
/// Cell class for the GRU layer.
/// </summary>
/// <param name="units"></param>
/// <param name="activation"></param>
/// <param name="recurrent_activation"></param>
/// <param name="use_bias"></param>
/// <param name="kernel_initializer"></param>
/// <param name="recurrent_initializer"></param>
/// <param name="bias_initializer"></param>
/// <param name="dropout"></param>
/// <param name="recurrent_dropout"></param>
/// <param name="reset_after"></param>
/// <returns></returns>
public IRnnCell GRUCell(
int units,
string activation = "tanh",
string recurrent_activation = "sigmoid",
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string recurrent_initializer = "orthogonal",
string bias_initializer = "zeros",
float dropout = 0f,
float recurrent_dropout = 0f,
bool reset_after = true)
=> new GRUCell(new GRUCellArgs
{
Units = units,
Activation = keras.activations.GetActivationFromName(activation),
RecurrentActivation = keras.activations.GetActivationFromName(recurrent_activation),
KernelInitializer = GetInitializerByName(kernel_initializer),
RecurrentInitializer = GetInitializerByName(recurrent_initializer),
BiasInitializer = GetInitializerByName(bias_initializer),
UseBias = use_bias,
Dropout = dropout,
RecurrentDropout = recurrent_dropout,
ResetAfter = reset_after
});
/// <summary>
/// Gated Recurrent Unit - Cho et al. 2014.
/// </summary>
/// <param name="units">Positive integer, dimensionality of the output space.</param>
/// <param name="activation">Activation function to use. If you pass `None`, no activation is applied.(ie. "linear" activation: `a(x) = x`).</param>
/// <param name="recurrent_activation">Activation function to use for the recurrent step. If you pass `None`, no activation is applied. (ie. "linear" activation: `a(x) = x`).</param>
/// <param name="use_bias">Boolean, (default `True`), whether the layer uses a bias vector.</param>
/// <param name="kernel_initializer">Initializer for the `kernel` weights matrix, used for the linear transformation of the inputs. Default: `glorot_uniform`.</param>
/// <param name="recurrent_initializer">Initializer for the `recurrent_kernel` weights matrix, used for the linear transformation of the recurrent state. Default: `orthogonal`.</param>
/// <param name="bias_initializer">Initializer for the bias vector. Default: `zeros`.</param>
/// <param name="dropout">Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs. Default: 0.</param>
/// <param name="recurrent_dropout">Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state. Default: 0.</param>
/// <param name="implementation"></param>
/// <param name="return_sequences">Boolean. Whether to return the last output in the output sequence, or the full sequence. Default: `False`.</param>
/// <param name="return_state">Boolean. Whether to return the last state in addition to the output. Default: `False`.</param>
/// <param name="go_backwards">Boolean (default `False`). If True, process the input sequence backwards and return the reversed sequence.</param>
/// <param name="stateful">Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.</param>
/// <param name="unroll">Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speed-up a RNN,</param>
/// <param name="time_major">The shape format of the `inputs` and `outputs` tensors.</param>
/// <param name="reset_after">GRU convention (whether to apply reset gate after or before matrix multiplication). False = "before", True = "after" (default and cuDNN compatible).</param>
/// <returns></returns>
public ILayer GRU(
int units,
string activation = "tanh",
string recurrent_activation = "sigmoid",
bool use_bias = true,
string kernel_initializer = "glorot_uniform",
string recurrent_initializer = "orthogonal",