public void ForwardBackwardTest() { var input = new TensorOld(new double[] { 4, 6, 1, 4, 8, 4, 5, 1, 5, 3, 5, 7, 1, 7, 2, 8, }, 1, 1, 4, 4); var conv = new ConvLayer(4, 2, 1, 1); conv.SetFilters(new TensorOld(new double[] { 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, }, 4, 1, 2, 2)); var expected = new TensorOld(new double[] { 0, 0, 0, 0, 0, 4, 10, 7, 5, 4, 8, 12, 9, 6, 1, 5, 8, 8, 12, 7, 1, 8, 9, 10, 8, 4, 10, 7, 5, 4, 8, 12, 9, 6, 1, 5, 8, 8, 12, 7, 1, 8, 9, 10, 8, 0, 0, 0, 0, 0, 0, 4, 6, 1, 4, 0, 12, 10, 6, 5, 0, 13, 7, 10, 8, 0, 6, 10, 7, 15, 0, 1, 7, 2, 8, 4, 6, 1, 4, 0, 12, 10, 6, 5, 0, 13, 7, 10, 8, 0, 6, 10, 7, 15, 0, 1, 7, 2, 8, 0, }, 1, 4, 5, 5); conv.PrepareTrain(input); var acutal = conv.Forward(input); Assert.Equal(acutal, expected); var error = expected / 10; var back = conv.Backward(error); }
public void ConvLayerStorageTest() { var doc = new XmlDocument(); var layer = new ConvLayer(3, 2, 1, 1); layer.SetFilters(new TensorOld( new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, 3, 1, 2, 2)); layer.SetBias(new TensorOld(new double[] { 1, 2, 3 })); var el = XmlStorage.SaveToEl(doc, layer); var test = XmlStorage.LoadFromNode <ConvLayer>(el); Assert.True(test is ConvLayer); Assert.Equal(layer.PaddingValue, test.PaddingValue); Assert.Equal(layer.FilterRows, test.FilterRows); Assert.Equal(layer.FilterColumns, test.FilterColumns); Assert.Equal(layer.RowStride, test.RowStride); Assert.Equal(layer.ColumnStride, test.ColumnStride); Assert.Equal(layer.Filters, test.Filters); Assert.Equal(layer.Bias, test.Bias); }