Ejemplo n.º 1
0
        public void NetworkSerialization()
        {
            INeuralNetwork network = NetworkManager.NewSequential(TensorInfo.Image <Rgb24>(120, 120),
                                                                  CuDnnNetworkLayers.Convolutional(ConvolutionInfo.New(ConvolutionMode.CrossCorrelation), (10, 10), 20, ActivationType.AbsoluteReLU),
                                                                  CuDnnNetworkLayers.Convolutional(ConvolutionInfo.New(ConvolutionMode.Convolution, 2, 2), (5, 5), 20, ActivationType.ELU),
                                                                  CuDnnNetworkLayers.Convolutional(ConvolutionInfo.Default, (10, 10), 20, ActivationType.Identity),
                                                                  CuDnnNetworkLayers.Pooling(PoolingInfo.New(PoolingMode.AverageIncludingPadding, 2, 2, 1, 1), ActivationType.ReLU),
                                                                  CuDnnNetworkLayers.Convolutional(ConvolutionInfo.Default, (10, 10), 20, ActivationType.Identity),
                                                                  CuDnnNetworkLayers.Pooling(PoolingInfo.Default, ActivationType.ReLU),
                                                                  CuDnnNetworkLayers.FullyConnected(125, ActivationType.Tanh),
                                                                  CuDnnNetworkLayers.FullyConnected(27, ActivationType.Tanh),
                                                                  CuDnnNetworkLayers.Softmax(133));

            using (MemoryStream stream = new MemoryStream())
            {
                network.Save(stream);
                stream.Seek(0, SeekOrigin.Begin);
                INeuralNetwork copy = NetworkLoader.TryLoad(stream, ExecutionModePreference.Cuda);
                Assert.IsTrue(network.Equals(copy));
            }
        }
Ejemplo n.º 2
0
        public bool CreateLayer(int nCount, ELayerType type, ActivationSettings activationSettings)
        {
            Layer.Utility.Layer layer;
            switch (type)
            {
            case ELayerType.Invalid:
                throw new ArgumentException("Invalid \"type\" argument.");

            case ELayerType.AveragePooling:
                layer = new AveragePooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.AverageUnpooling:
                layer = new AverageUnpooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Convolutional:
                layer = new Convolutional(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Deconvolutional:
                layer = new Deconvolutional(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Dropout:
                layer = new Dropout(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.FullyConnected:
                layer = new FullyConnected(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.GatedRecurrent:
                layer = new GatedRecurrent(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.LSTM:
                layer = new LSTM(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.MaxPooling:
                layer = new MaxPooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.MaxUnpooling:
                layer = new MaxUnpooling(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            case ELayerType.Recurrent:
                layer = new Recurrent(nCount, Layers.Count, activationSettings);
                Layers.Add(layer);
                return(true);

            default:
                throw new ArgumentException("Invalid \"type\" argument.");
            }
        }