示例#1
0
        static bool SaveLoad()
        {
            BitmapCatEnumerator enums = new BitmapCatEnumerator("Sorted", new System.Drawing.Size(50, 25));

            Network network = new Network();

            network.AddLayer(new Conv2D(new Relu(), 7, 7, 32));
            network.AddLayer(new MaxPool2D(new Relu(), 2, 2));

            network.AddLayer(new Conv2D(new Relu(), 5, 5, 64));
            network.AddLayer(new MaxPool2D(new Relu(), 2, 2));

            network.AddLayer(new FullyConnLayar(new Relu(), new Size(1, 1, 256)));
            network.AddLayer(new FullyConnLayar(new Sigmoid(), new Size(1, 1, 2)));

            network.Compile(new Size(3, 25, 50), true);

            network.Normalization();
            network.Normalization();

            string data = network.SaveJSON();

            Network network2 = new Network();

            network2.LoadJSON(data);

            var pair = enums.GetRandom(ref network);

            var out1 = network.GetOutput(pair.Key);
            var out2 = network.GetOutput(pair.Key);

            return(out1[0, 0, 0] == out2[0, 0, 0]);
        }
示例#2
0
        static bool CatTrain()
        {
            BitmapCatEnumerator enums   = new BitmapCatEnumerator("Sorted", new System.Drawing.Size(50, 25));
            Network             network = new Network();

            network.AddLayer(new Conv2D(new Relu(), 7, 7, 32));
            network.AddLayer(new MaxPool2D(new Relu(), 2, 2));

            network.AddLayer(new Conv2D(new Relu(), 5, 5, 64));
            network.AddLayer(new MaxPool2D(new Relu(), 2, 2));


            network.AddLayer(new FullyConnLayar(new Relu(), new Size(1, 1, 256)));
            network.AddLayer(new FullyConnLayar(new Sigmoid(), new Size(1, 1, 2)));

            network.Compile(new Size(3, 25, 50), true);

            network.Normalization();

            var pair = enums.GetRandom(ref network);

            OneEnumerator one = new OneEnumerator();

            one.input  = pair.Key;
            one.output = pair.Value;

            MomentumParallel sgd = new MomentumParallel(network, 0.9, 1e-6);

            double[] errors = sgd.TrainBatch(enums, 32, 1000);

            return(errors[0] > errors.Last());
        }