Esempio n. 1
0
        public void should_output_tensor_of_expected_size(int inputSize, int weightLength, int expectedOutputSize)
        {
            // Arrange
            _sut = (ConvolutionalLayer) new Net(inputSize)
                   .Convolution(new [] { weightLength, 1 }, kernelCount: 1, strideArray: new [] { 1 })
                   .Layers[0];

            var input = new float[inputSize];

            // Act
            var output = _sut.FeedForwards(new Tensor(input));

            // Assert
            Assert.That(output.Size.Dimensions.Length, Is.EqualTo(1));
            Assert.That(output.Size.Dimensions[0], Is.EqualTo(expectedOutputSize));
        }
        public void should_output_tensor_of_correct_size(int inputSize, int weightLength, int expectedOutputSize)
        {
            // Arrange
            _sut = (ConvolutionalLayer) new Net(inputSize, inputSize)
                   .ConvolutionTranspose(new[] { weightLength, weightLength })
                   .Layers[0];

            var input = new float[inputSize, inputSize].ToMatrix();

            // Act
            var output = _sut.FeedForwards(new Tensor(input));

            // Assert
            Assert.That(output.Size.Dimensions.Length, Is.EqualTo(2));
            Assert.That(output.Size.Dimensions[0], Is.EqualTo(expectedOutputSize));
            Assert.That(output.Size.Dimensions[1], Is.EqualTo(expectedOutputSize));
        }
        public void should_backpropagate_tensor_of_correct_size(int inputSize, int weightLength, int outputSize)
        {
            // Arrange
            _sut = (ConvolutionalLayer) new Net(inputSize, inputSize)
                   .ConvolutionTranspose(new[] { weightLength, weightLength })
                   .Layers[0];

            var trainingRun = new TrainingRun(1)
            {
                Input       = new float[inputSize, inputSize].ToMatrix(),
                Output      = _sut.FeedForwards(new float[inputSize, inputSize].ToMatrix()),
                OutputError = new float[outputSize, outputSize].ToMatrix()
            };

            // Act
            _sut.BackPropagate(trainingRun);

            // Assert
            Assert.That(trainingRun.InputError.Size, Is.EqualTo(trainingRun.Input.Size));
        }
        public void should_backpropagate_tensor_of_correct_kernel_size(int kernelSize)
        {
            // Arrange
            _sut = (ConvolutionalLayer) new Net(1, 1)
                   .ConvolutionTranspose(new[] { 5, 5 }, kernelSize)
                   .Layers[0];
            var input = new float[, ] {
                { 0 }
            }.ToMatrix();

            var trainingRun = new TrainingRun(1)
            {
                Input       = input,
                Output      = _sut.FeedForwards(input),
                OutputError = new Tensor(new Size(5, 5, kernelSize), new float[5 * 5 * kernelSize])
            };

            // Act
            _sut.BackPropagate(trainingRun);

            // Assert
            Assert.That(trainingRun.InputError.Size, Is.EqualTo(trainingRun.Input.Size));
        }