コード例 #1
0
        public void ForwardBackwardTest1()
        {
            Shape      shape = new Shape(Shape.BWHC, -1, 2, 2, 2);
            SplitLayer layer = new SplitLayer(shape, 3);

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

                Tensor x = new Tensor(null, shape.Reshape(Axis.B, mb));
                x.Randomize();

                IList <Tensor> ys = layer.Forward(session, new[] { x });

                Assert.AreEqual(layer.NumberOfOutputs, ys.Count);
                foreach (Tensor y in ys)
                {
                    Helpers.AreTensorsEqual(x, y);
                }

                // unroll the graph
                // during backward pass we should average all gradients into a single tensor
                for (int i = 0; i < layer.NumberOfOutputs; i++)
                {
                    ys[i].SetGradient(i + 2);
                }

                session.Unroll();

                Helpers.IsArrayEqual(x.Length, 3.0f, x.Gradient, 0);
            }
        }
コード例 #2
0
        public void CloneTest()
        {
            Shape      shape  = new Shape(Shape.BWHC, -1, 2, 2, 2);
            SplitLayer layer1 = new SplitLayer(shape, 3);
            SplitLayer layer2 = layer1.Clone() as SplitLayer;

            Assert.AreEqual(JsonConvert.SerializeObject(layer1), JsonConvert.SerializeObject(layer2));
        }
コード例 #3
0
        public void CopyConstructorTest1()
        {
            Shape      shape  = new Shape(Shape.BWHC, -1, 2, 2, 2);
            SplitLayer layer1 = new SplitLayer(shape, 3);
            SplitLayer layer2 = new SplitLayer(layer1);

            Assert.AreEqual(JsonConvert.SerializeObject(layer1), JsonConvert.SerializeObject(layer2));
        }
コード例 #4
0
        public void ArchitectureConstructorTest1()
        {
            Shape      shape = new Shape(Shape.BWHC, -1, 2, 2, 2);
            SplitLayer layer = new SplitLayer(shape, "SP3", null);

            Assert.AreEqual(3, layer.NumberOfOutputs);
            CollectionAssert.AreEqual(shape.Axes, layer.OutputShape.Axes);
            Assert.AreEqual("SP3", layer.Architecture);
        }
コード例 #5
0
        public void SerializeTest()
        {
            Shape      shape  = new Shape(Shape.BWHC, -1, 2, 2, 2);
            SplitLayer layer1 = new SplitLayer(shape, 3);
            string     s1     = JsonConvert.SerializeObject(layer1);
            SplitLayer layer2 = JsonConvert.DeserializeObject <SplitLayer>(s1);
            string     s2     = JsonConvert.SerializeObject(layer2);

            Assert.AreEqual(s1, s2);
        }
コード例 #6
0
        public void ArchitectureConstructorTest2()
        {
            string architecture = "SP";

            try
            {
                SplitLayer layer = new SplitLayer(new Shape(Shape.BWHC, -1, 2, 2, 2), architecture, null);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(
                    new ArgumentException(string.Format(CultureInfo.InvariantCulture, Properties.Resources.E_InvalidLayerArchitecture, architecture), nameof(architecture)).Message,
                    e.Message);
                throw;
            }
        }
コード例 #7
0
        internal void SplitRoute(int splitDistance)
        {
            _splitDistance         = splitDistance;
            SplitLayer.DisplayName = $"{splitDistance} km";
            SplitLayer.Graphics.Clear();
            SplitLayer.Opacity = Opacity;
            _routeSplitter.SplitRoute(_splitDistance, _routeOrTrack.Points);
            var splitPoints = _routeSplitter.GetSplitPoints();
            var splitRoutes = _routeSplitter.GetSplittedRoutes();

            SplitLayer.Graphics.Add(_routeOrTrack.StartLocation);
            SplitLayer.Graphics.Add(_routeOrTrack.EndLocation);
            SplitLayer.Graphics.AddRange(splitPoints);
            SplitLayer.Graphics.AddRange(splitRoutes);
            SetSymbols(SplitLayer.Graphics);
            SplitLayer.IsVisible = true;
            IsVisible            = false;
            IsSplitted           = true;
            SplitLayer.SetSelectionColorOfGraphics();
        }