Exemple #1
0
        public IMatrix ExecuteToMatrix(I3DTensor tensor)
        {
            IMatrix input;

            if (_padding > 0)
            {
                using (var padded = tensor.AddPadding(_padding))
                    input = padded.Im2Col(_filterWidth, _filterHeight, _stride);
            }
            else
            {
                input = tensor.Im2Col(_filterWidth, _filterHeight, _stride);
            }

            // execute the layer
            var ret = _layer.Activate(input);

            input.Dispose();
            return(ret);
        }
Exemple #2
0
        IMatrix _Execute(I3DTensor tensor, Stack <IConvolutionalLayerBackpropagation> backpropagation)
        {
            var     layer = _trainer.LayerUpdater.Layer;
            IMatrix input;

            if (_descriptor.Padding > 0)
            {
                using (var padded = tensor.AddPadding(_descriptor.Padding))
                    input = padded.Im2Col(_descriptor.FilterWidth, _descriptor.FilterHeight, _descriptor.Stride);
            }
            else
            {
                input = tensor.Im2Col(_descriptor.FilterWidth, _descriptor.FilterHeight, _descriptor.Stride);
            }

            var output = layer.Execute(input);

            if (backpropagation != null)
            {
                backpropagation?.Push(new Backpropagation(this, _trainer, input, output));
                return(layer.Activation?.Calculate(output) ?? output);
            }
            else
            {
                input.Dispose();
                if (layer.Activation == null)
                {
                    return(output);
                }
                else
                {
                    var ret = layer.Activation.Calculate(output);
                    output.Dispose();
                    return(ret);
                }
            }
        }