public void Shape() { var cns = new ConvNetSharp <double>(); var x = cns.Const(1.0, "x"); var op = cns.Shape(x); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Shape <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Parents.Count); Assert.AreEqual("x", (deserialized.Parents[0] as Const <double>).Name); }
public void Dropout() { var cns = new ConvNetSharp <double>(); var x = cns.Const(1.0, "x"); var dropoutProbability = 0.5; var op = cns.Dropout(x, dropoutProbability); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Dropout <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(dropoutProbability, ((Const <double>)deserialized.DropoutProbability).Value); }
public void Sqrt() { var cns = new ConvNetSharp <double>(); var a = cns.Const(9.0, "input"); var op = cns.Sqrt(a); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Sqrt <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Parents.Count); Assert.AreEqual("input", (deserialized.Parents[0] as Const <double>).Name); }
public void LeakyRelu() { var cns = new ConvNetSharp <double>(); var a = cns.Const(1.0, "one"); var op = cns.LeakyRelu(a, 0.01); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as LeakyRelu <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Parents.Count); Assert.AreEqual("one", (deserialized.Parents[0] as Const <double>).Name); }
public void ConcatGradientCheck() { var leftShape = new Shape(2, 2, 1, 1); var rightShape = new Shape(3, 1, 1, 1); var cns = new ConvNetSharp <T>(); var location = this.NewVolume(RandomUtilities.RandomDoubleArray(leftShape.TotalLength), new Shape(2, 2, 1, 1)); var x = cns.PlaceHolder("x"); var z = cns.Const(this.NewVolume(new double[rightShape.TotalLength].Populate(1.0), rightShape), "z"); var fun = cns.Concat(x, z); this.GradientCheck(cns, fun, location, 1e-5); }
public void Activation() { var cns = new ConvNetSharp <double>(); var x = cns.Const(1.0, "x"); var op = new Activation <double>(cns, x, ActivationType.Relu); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Activation <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Parents.Count); Assert.AreEqual("x", (deserialized.Parents[0] as Const <double>).Name); Assert.AreEqual(ActivationType.Relu, deserialized.Type); }
public void AddOpBackward() { var cns = new ConvNetSharp <double>(); var volA = cns.Const(BuilderInstance <double> .Volume.SameAs(new Shape(1, 1, 3, 5)), "A"); var volB = cns.Const(BuilderInstance <double> .Volume.From(new[] { 1.0, 2.0, 3.0 }, new Shape(1, 1, 3, 1)), "bias"); var op = volA + volB; using var session = new Session <double>(); var eval = op.Evaluate(session); Assert.IsNotNull(eval); op.Derivate = cns.Const(BuilderInstance <double> .Volume.From(new double[15].Populate(1.0), new Shape(1, 1, 3, 5)), "error"); op.Differentiate(); var volADiff = volA.Derivate.Evaluate(session); Assert.AreEqual(volA.Result.Shape, volADiff.Shape); var volBDiff = volB.Derivate.Evaluate(session); Assert.AreEqual(volB.Result.Shape, volBDiff.Shape); }
public void SumOpBatch() { var cns = new ConvNetSharp <T>(); var x = cns.Const(NewVolume(new[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }, new Shape(3, 1, 1, 2)), "x"); var op = cns.Sum(x, new Shape(1, 1, 1, 2)); using (var session = new Session <T>()) { var result = op.Evaluate(session); AssertNumber.AreEqual(6.0, result.Get(0)); AssertNumber.AreEqual(15.0, result.Get(1)); } }
public void Dense() { var cns = new ConvNetSharp <double>(); var x = cns.Const(1.0, "x"); var op = new Dense <double>(cns, x, 16); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Dense <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Parents.Count); // input and filters Assert.AreEqual("x", (deserialized.Parents[0] as Const <double>).Name); Assert.AreEqual(1, deserialized.Width); Assert.AreEqual(1, deserialized.Height); Assert.AreEqual(16, deserialized.FilterCount); Assert.AreEqual(1, deserialized.Stride); Assert.AreEqual(0, deserialized.Pad); }
public void Pool() { var cns = new ConvNetSharp <double>(); var x = cns.Const(1.0, "x"); var op = cns.Pool(x, 3, 4, 1, 2, 1, 2); var xml = op.ToXml(); var deserialized = SerializationExtensions.FromXml <double>(xml) as Pool <double>; Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Parents.Count); Assert.AreEqual("x", (deserialized.Parents[0] as Const <double>).Name); Assert.AreEqual(3, deserialized.Width); Assert.AreEqual(4, deserialized.Height); Assert.AreEqual(1, deserialized.HorizontalPad); Assert.AreEqual(2, deserialized.VerticalPad); Assert.AreEqual(1, deserialized.HorizontalStride); Assert.AreEqual(2, deserialized.VerticalStride); }