Beispiel #1
0
        public void FullyConnLayerSerialization()
        {
            var layer = new FullyConnLayer(10)
            {
                BiasPref = 0.5
            };

            layer.Init(28, 24, 1);

            var data = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as FullyConnLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);

            Assert.AreEqual(layer.NeuronCount, deserialized.NeuronCount);

            Assert.AreEqual(layer.Filters.Shape, deserialized.Filters.Shape);
            Assert.IsTrue(layer.Filters.ToArray().SequenceEqual(deserialized.Filters.ToArray()));

            Assert.AreEqual(layer.Bias.Shape, deserialized.Bias.Shape);
            Assert.IsTrue(layer.Bias.ToArray().SequenceEqual(deserialized.Bias.ToArray()));

            Assert.AreEqual(layer.BiasPref, deserialized.BiasPref);
        }
Beispiel #2
0
        public void PoolLayerSerialization()
        {
            var layer = new PoolLayer(3, 3)
            {
                Pad = 1, Stride = 2
            };

            layer.Init(28, 24, 1);
            var data = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as PoolLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);
            Assert.AreEqual(layer.OutputWidth, deserialized.OutputWidth);
            Assert.AreEqual(layer.OutputHeight, deserialized.OutputHeight);
            Assert.AreEqual(layer.OutputDepth, deserialized.OutputDepth);

            Assert.AreEqual(layer.Width, deserialized.Width);
            Assert.AreEqual(layer.Height, deserialized.Height);
            Assert.AreEqual(layer.Pad, deserialized.Pad);
            Assert.AreEqual(layer.Stride, deserialized.Stride);
        }
        public void DropoutSerialization()
        {
            var layer = new DropoutLayer {
                DropProbability = 0.1
            };

            layer.Init(28, 24, 1);
            var data = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as DropoutLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);
            Assert.AreEqual(layer.OutputWidth, deserialized.OutputWidth);
            Assert.AreEqual(layer.OutputHeight, deserialized.OutputHeight);
            Assert.AreEqual(layer.OutputDepth, deserialized.OutputDepth);

            Assert.AreEqual(layer.DropProbability, deserialized.DropProbability);
        }
Beispiel #4
0
        public static Net <T> FromData(IDictionary <string, object> dico)
        {
            var net = new Net <T>();

            var layers = dico["Layers"] as IEnumerable <IDictionary <string, object> >;

            foreach (var layerData in layers)
            {
                var layer = LayerBase <T> .FromData(layerData);

                net.Layers.Add(layer);
            }

            return(net);
        }
Beispiel #5
0
        public void InputLayerSerialization()
        {
            var layer = new InputLayer(28, 24, 1);
            var data  = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as InputLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);
            Assert.AreEqual(layer.OutputWidth, deserialized.OutputWidth);
            Assert.AreEqual(layer.OutputHeight, deserialized.OutputHeight);
            Assert.AreEqual(layer.OutputDepth, deserialized.OutputDepth);
        }
Beispiel #6
0
        public void LeakyReluLayerSerialization()
        {
            var layer = new LeakyReluLayer(0.01);

            layer.Init(28, 24, 1);
            var data = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as LeakyReluLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);
            Assert.AreEqual(layer.OutputWidth, deserialized.OutputWidth);
            Assert.AreEqual(layer.OutputHeight, deserialized.OutputHeight);
            Assert.AreEqual(layer.OutputDepth, deserialized.OutputDepth);
            Assert.AreEqual(0.01, layer.Alpha);
        }
Beispiel #7
0
        public void ConvLayerSerialization()
        {
            var layer = new ConvLayer(5, 5, 8)
            {
                Stride = 1, Pad = 2, BiasPref = 0.5
            };

            layer.Init(28, 24, 1);

            var data = layer.GetData();

            Assert.AreEqual(28, data["InputWidth"]);
            Assert.AreEqual(24, data["InputHeight"]);
            Assert.AreEqual(1, data["InputDepth"]);

            var deserialized = LayerBase <double> .FromData(data) as ConvLayer;

            Assert.IsNotNull(deserialized);
            Assert.AreEqual(28, deserialized.InputWidth);
            Assert.AreEqual(24, deserialized.InputHeight);
            Assert.AreEqual(1, deserialized.InputDepth);

            Assert.AreEqual(layer.Width, deserialized.Width);
            Assert.AreEqual(layer.Height, deserialized.Height);
            Assert.AreEqual(layer.Pad, deserialized.Pad);
            Assert.AreEqual(layer.Stride, deserialized.Stride);
            Assert.AreEqual(layer.FilterCount, deserialized.FilterCount);

            Assert.AreEqual(layer.Filters.Shape, deserialized.Filters.Shape);
            Assert.IsTrue(layer.Filters.ToArray().SequenceEqual(deserialized.Filters.ToArray()));

            Assert.AreEqual(layer.Bias.Shape, deserialized.Bias.Shape);
            Assert.IsTrue(layer.Bias.ToArray().SequenceEqual(deserialized.Bias.ToArray()));

            Assert.AreEqual(layer.BiasPref, deserialized.BiasPref);
        }