Пример #1
0
        public void ConstructorTest1()
        {
            ConcatLayer layer = new ConcatLayer(
                new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 });

            CollectionAssert.AreEqual(ConcatLayerTest.outputShape.Axes, layer.OutputShape.Axes);
            Assert.AreEqual("CONCAT", layer.Architecture);
        }
Пример #2
0
        public void CloneTest()
        {
            ConcatLayer layer1 = new ConcatLayer(
                new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 });
            ConcatLayer layer2 = layer1.Clone() as ConcatLayer;

            Assert.AreEqual(JsonConvert.SerializeObject(layer1), JsonConvert.SerializeObject(layer2));
        }
Пример #3
0
        public void CopyConstructorTest1()
        {
            ConcatLayer layer1 = new ConcatLayer(
                new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 });
            ConcatLayer layer2 = new ConcatLayer(layer1);

            Assert.AreEqual(JsonConvert.SerializeObject(layer1), JsonConvert.SerializeObject(layer2));
        }
Пример #4
0
        public void SerializeTest()
        {
            ConcatLayer layer1 = new ConcatLayer(
                new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 });
            string      s1     = JsonConvert.SerializeObject(layer1);
            ConcatLayer layer2 = JsonConvert.DeserializeObject <ConcatLayer>(s1);
            string      s2     = JsonConvert.SerializeObject(layer2);

            Assert.AreEqual(s1, s2);
        }
Пример #5
0
        public void ArchitectureConstructorTest2()
        {
            string architecture = "CON";

            try
            {
                ConcatLayer layer = new ConcatLayer(
                    new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 },
                    architecture,
                    null);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(
                    new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.E_InvalidLayerArchitecture, architecture), nameof(architecture)).Message,
                    e.Message);
                throw;
            }
        }
Пример #6
0
        public void ForwardBackwardTest()
        {
            ConcatLayer layer = new ConcatLayer(
                new Shape[] { ConcatLayerTest.inputShape1, ConcatLayerTest.inputShape2 });

            Tensor xTemp1 = new Tensor(null, ConcatLayerTest.inputShape1.Reshape(Axis.B, 1));

            xTemp1.Set(ConcatLayerTest.weights1);
            Tensor xTemp2 = new Tensor(null, ConcatLayerTest.inputShape2.Reshape(Axis.B, 1));

            xTemp2.Set(ConcatLayerTest.weights2);

            Tensor expectedTemp = new Tensor(null, new[] { 1, 2, 3, 5 });

            expectedTemp.Set(new float[]
            {
                1, 11, 21, 31, 41, 2, 12, 22, 32, 42, 3, 13, 23, 33, 43,
                4, 14, 24, 34, 44, 5, 15, 25, 35, 45, 6, 16, 26, 36, 46
            });

            for (int i = 1; i <= 3; i++)
            {
                Session session = new Session();

                Tensor x1 = session.Tile(xTemp1, (int)Axis.B, i);
                Tensor x2 = session.Tile(xTemp2, (int)Axis.B, i);
                Tensor y  = layer.Forward(session, new[] { x1, x2 })[0];

                Tensor expected = session.Tile(expectedTemp, (int)Axis.B, i);
                Helpers.AreTensorsEqual(expected, y);

                // unroll the graph
                Array.Copy(y.Weights, y.Gradient, y.Length);
                session.Unroll();

                Helpers.AreArraysEqual(x1.Length, x1.Weights, x1.Gradient);
                Helpers.AreArraysEqual(x2.Length, x2.Weights, x2.Gradient);
            }
        }