示例#1
0
        public override List <int?[]> compute_output_shape(List <int?[]> input_shapes)
        {
            if (input_shapes.Count != 1)
            {
                throw new Exception("Expected a single input.");
            }
            int?[] input_shape = input_shapes[0];

            // https://github.com/fchollet/keras/blob/f65a56fb65062c8d14d215c9f4b1015b97cc5bf3/keras/layers/convolutional.py#L185

            if (this.data_format == DataFormatType.ChannelsLast)
            {
                var space     = input_shape.Get(1, -1);
                var new_space = new List <int?>();
                for (int i = 0; i < space.Length; i++)
                {
                    int?new_dim = ConvUtils.ConvOutputLength(
                        space[i],
                        this.kernel_size[i],
                        padding: this.padding,
                        stride: this.strides[i],
                        dilation: this.dilation_rate[i]);
                    new_space.Add(new_dim);
                }

                return(new[] { new[] { input_shape[0] }.Concat(new_space).Concat(new int?[] { this.filters }).ToList().ToArray() }.ToList());
            }
            else if (this.data_format == DataFormatType.ChannelsFirst)
            {
                var space     = input_shape.Get(2, 0);
                var new_space = new List <int?>();
                for (int i = 0; i < space.Length; i++)
                {
                    int?new_dim = ConvUtils.ConvOutputLength(
                        space[i],
                        this.kernel_size[i],
                        padding: this.padding,
                        stride: this.strides[i],
                        dilation: this.dilation_rate[i]);
                    new_space.Add(new_dim);
                }

                return(new[] { new[] { input_shape[0] }.Concat(new int?[] { this.filters }).Concat(new_space).ToList().ToArray() }.ToList());
            }
            else
            {
                throw new Exception();
            }
        }