|
2 | 2 | using Tensorflow.Keras.Engine;
|
3 | 3 |
|
4 | 4 | namespace Tensorflow.Keras.Layers {
|
5 |
| - public class Cropping1D : Layer { |
6 |
| - CroppingArgs args; |
7 |
| - public Cropping1D ( CroppingArgs args ) : base(args) { |
8 |
| - this.args = args; |
9 |
| - } |
| 5 | + public class Cropping1D : Layer |
| 6 | + { |
| 7 | + CroppingArgs args; |
| 8 | + public Cropping1D(CroppingArgs args) : base(args) |
| 9 | + { |
| 10 | + this.args = args; |
| 11 | + } |
10 | 12 |
|
11 |
| - protected override void build ( Tensors inputs ) { |
12 |
| - if ( args.cropping.rank != 1 ) { |
13 |
| - // throw an ValueError exception |
14 |
| - throw new ValueError(""); |
15 |
| - } |
16 |
| - else if ( args.cropping.shape[0] > 2 || args.cropping.shape[0] < 1 ) { |
17 |
| - throw new ValueError("The `cropping` argument must be a tuple of 2 integers."); |
18 |
| - } |
19 |
| - built = true; |
| 13 | + public override void build(Shape input_shape) |
| 14 | + { |
| 15 | + if (args.cropping.rank != 1) |
| 16 | + { |
| 17 | + // throw an ValueError exception |
| 18 | + throw new ValueError(""); |
| 19 | + } |
| 20 | + else if (args.cropping.shape[0] > 2 || args.cropping.shape[0] < 1) |
| 21 | + { |
| 22 | + throw new ValueError("The `cropping` argument must be a tuple of 2 integers."); |
20 | 23 | }
|
| 24 | + built = true; |
| 25 | + } |
21 | 26 |
|
22 |
| - protected override Tensors Call ( Tensors inputs, Tensor state = null, bool? training = null ) { |
23 |
| - Tensor output = inputs; |
24 |
| - if ( output.rank != 3 ) { |
25 |
| - // throw an ValueError exception |
26 |
| - throw new ValueError("Expected dim=3, found dim=" + output.rank); |
27 |
| - } |
28 |
| - if ( args.cropping.shape[0] == 1 ) { |
29 |
| - int crop_start = args.cropping[0]; |
30 |
| - output = output[new Slice(), new Slice(crop_start, ( int ) output.shape[1] - crop_start), new Slice()]; |
31 |
| - } |
32 |
| - else { |
33 |
| - int crop_start = args.cropping[0], crop_end = args.cropping[1]; |
34 |
| - output = output[new Slice(), new Slice(crop_start, ( int ) (output.shape[1]) - crop_end), new Slice()]; |
35 |
| - } |
36 |
| - return output; |
| 27 | + protected override Tensors Call(Tensors inputs, Tensor state = null, bool? training = null) |
| 28 | + { |
| 29 | + Tensor output = inputs; |
| 30 | + if (output.rank != 3) |
| 31 | + { |
| 32 | + // throw an ValueError exception |
| 33 | + throw new ValueError("Expected dim=3, found dim=" + output.rank); |
| 34 | + } |
| 35 | + if (args.cropping.shape[0] == 1) |
| 36 | + { |
| 37 | + int crop_start = args.cropping[0]; |
| 38 | + output = output[new Slice(), new Slice(crop_start, (int)output.shape[1] - crop_start), new Slice()]; |
37 | 39 | }
|
| 40 | + else |
| 41 | + { |
| 42 | + int crop_start = args.cropping[0], crop_end = args.cropping[1]; |
| 43 | + output = output[new Slice(), new Slice(crop_start, (int)(output.shape[1]) - crop_end), new Slice()]; |
| 44 | + } |
| 45 | + return output; |
| 46 | + } |
38 | 47 |
|
39 |
| - public override Shape ComputeOutputShape ( Shape input_shape ) { |
40 |
| - if ( args.cropping.shape[0] == 1 ) { |
41 |
| - int crop = args.cropping[0]; |
42 |
| - return new Shape(( int ) (input_shape[0]), ( int ) (input_shape[1] - crop * 2), ( int ) (input_shape[2])); |
43 |
| - } |
44 |
| - else { |
45 |
| - int crop_start = args.cropping[0], crop_end = args.cropping[1]; |
46 |
| - return new Shape(( int ) (input_shape[0]), ( int ) (input_shape[1] - crop_start - crop_end), ( int ) (input_shape[2])); |
47 |
| - } |
| 48 | + public override Shape ComputeOutputShape(Shape input_shape) |
| 49 | + { |
| 50 | + if (args.cropping.shape[0] == 1) |
| 51 | + { |
| 52 | + int crop = args.cropping[0]; |
| 53 | + return new Shape((int)(input_shape[0]), (int)(input_shape[1] - crop * 2), (int)(input_shape[2])); |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + int crop_start = args.cropping[0], crop_end = args.cropping[1]; |
| 58 | + return new Shape((int)(input_shape[0]), (int)(input_shape[1] - crop_start - crop_end), (int)(input_shape[2])); |
48 | 59 | }
|
49 |
| - } |
| 60 | + } |
| 61 | + } |
50 | 62 | }
|
0 commit comments