Пример #1
0
        static void Main(string[] args)
        {
            String positiveSamplesPath = "D:\\StromaSet\\S-114-HE_64\\training\\stroma";
            String negativeSamplesPath = "D:\\StromaSet\\S-114-HE_64\\training\\not-stroma";
            String rbmSavePath = "D:\\StromaSet\\weights";

            String rbm0WeightsPath = "D:\\StromaSet\\weights\\RBM0_T1_769_500_139_0,04191353.weights";
            String rbm1WeightsPath = "D:\\StromaSet\\weights\\RBM1_T1_500_75_375_0,07180008.weights";
            String rbm2WeightsPath = "D:\\StromaSet\\weights\\RBM2_TOP_T3_76_40_16_0,1688143.weights";

            int batchSize = 100;
            int patchWidth = 16;
            int patchHeight = 16;

            Random random = new Random();

            int rbm0Visible = patchWidth * patchHeight * 3 + 1;
            int rbm0Hidden = 500;

            int rbm1Visible = rbm0Hidden;
            int rbm1Hidden = 75;

            int rbm2Visible = rbm1Hidden + 1;
            int rbm2Hidden = 40;

            IBatchGenerator generator = new ScaleBatchGenerator(positiveSamplesPath, negativeSamplesPath);

            //Matrix<float> rbm0Weights = WeightsHelper.generateWeights(rbm0Visible, rbm0Hidden, random);
            Matrix<float> rbm0Weights = WeightsHelper.loadWeights(rbm0WeightsPath);
            //Matrix<float> rbm1Weights = WeightsHelper.generateWeights(rbm1Visible, rbm1Hidden, random);
            Matrix<float> rbm1Weights = WeightsHelper.loadWeights(rbm1WeightsPath);
            //Matrix<float> rbm2Weights = WeightsHelper.generateWeights(rbm2Visible, rbm2Hidden, random);
            Matrix<float> rbm2Weights = WeightsHelper.loadWeights(rbm2WeightsPath);

            RBM rbm0 = new RBM(rbm0Weights, false);
            RBM rbm1 = new RBM(rbm1Weights, false);
            RBM rbm2 = new RBM(rbm2Weights, false);

            //RBMTrainer.IRBMInput rbm0Input = new RBM0Input(generator, batchSize, patchWidth, patchHeight);
            //RBMTrainer.trainRBM(rbm0, rbm0Input, 0.01f, 100000, 100, rbmSavePath, "RBM0_LABEL_T1", rbm0Visible, rbm0Hidden);

            //RBMTrainer.IRBMInput rbm1Input = new RBM1Input(generator, batchSize, patchWidth, patchHeight, rbm0);
            //RBMTrainer.trainRBM(rbm1, rbm1Input, 0.01f, 2000000, 1000, rbmSavePath, "RBM1_LABELS_T2", rbm1Visible, rbm1Hidden);

            RBMTrainer.IRBMInput rbm2Input = new RBM2Input(generator, batchSize, patchWidth, patchHeight, rbm0, rbm1);
            RBMTrainer.trainRBM(rbm2, rbm2Input, 0.03f, 1000000, 1000, rbmSavePath, "RBM2_TOP_T3", rbm2Visible, rbm2Hidden);
        }
        static void Main(string[] args)
        {
            String positiveSamplesPath = "D:\\StromaSet\\S-114-HE_64\\crossvalidation\\stroma";
            String negativeSamplesPath = "D:\\StromaSet\\S-114-HE_64\\crossvalidation\\not-stroma";
            String outputPath = "D:\\StromaSet\\reconstructions";

            String rbm0WeightsPath = "D:\\StromaSet\\weights\\RBM0_T1_769_500_139_0,04191353.weights";
            String rbm1WeightsPath = "D:\\StromaSet\\weights\\RBM1_T1_500_75_375_0,07180008.weights";
            String rbm2WeightsPath = "D:\\StromaSet\\weights\\RBM2_TOP_T3_76_40_16_0,1688143.weights";

            int batchSize = 100;
            int patchWidth = 16;
            int patchHeight = 16;

            IBatchGenerator generator = new ScaleBatchGenerator(positiveSamplesPath, negativeSamplesPath);

            Matrix<float> rbm0Weights = WeightsHelper.loadWeights(rbm0WeightsPath);
            Matrix<float> rbm1Weights = WeightsHelper.loadWeights(rbm1WeightsPath);
            Matrix<float> rbm2Weights = WeightsHelper.loadWeights(rbm2WeightsPath);

            RBM rbm0 = new RBM(rbm0Weights, false);
            RBM rbm1 = new RBM(rbm1Weights, false);
            RBM rbm2 = new RBM(rbm2Weights, false);

            Matrix<float> batch = generator.nextBatch(batchSize, patchWidth, patchHeight);

            Matrix<float> rbm0Hidden = rbm0.getHidden(batch);
            Matrix<float> rbm1Hidden = rbm1.getHidden(rbm0Hidden);
            Matrix<float> rbm1HiddenWithEmptyLabels = MatrixHelper.addEmptyLabels(rbm1Hidden);
            Matrix<float> rbm2Hidden = rbm2.getHidden(rbm1HiddenWithEmptyLabels);

            Matrix<float> rbm2Visible = rbm2.getVisible(rbm2Hidden);
            Matrix<float> rbm2VisibleWithoutLabels = MatrixHelper.removeLabels(rbm2Visible);
            Matrix<float> rbm1Visible = rbm1.getVisible(rbm2VisibleWithoutLabels);
            Matrix<float> rbm0Visible = rbm0.getVisible(rbm1Visible);

            ImageHelper.persistOriginalAndReconstruction(patchWidth, patchHeight, batch, rbm0Visible, outputPath);

            Console.WriteLine("Image Reconstruction: " + RBMTrainer.reconstructionError(batch, rbm0Visible));
            Console.WriteLine("Prediction Quality: " + RBMTrainer.predictionQuality(rbm2Visible));

            Console.WriteLine("press key to exit: ");
            Console.ReadKey();
        }