Exemplo n.º 1
0
        private static INeuralNetwork <double> InitializeNeuralNetworkStartingValues(INeuralNetworkBuilder <double> builder)
        {
            double[][] hiddenLayerValues = new double[2][];
            hiddenLayerValues[0] = new double[10];
            hiddenLayerValues[1] = new double[20];
            for (int i = 0; i < 10; ++i)
            {
                hiddenLayerValues[0][i] = i;
            }
            for (int i = 0; i < 20; ++i)
            {
                hiddenLayerValues[1][i] = i;
            }

            INeuralNetwork <double> network = builder.InitializeNeuralNetworkWithData(null, hiddenLayerValues, null);

            network.LearningRate = 1;

            return(network);
        }
Exemplo n.º 2
0
        public static void TrainModel(INeuralNetworkBuilder networkBuilder, string preparedDataPath, string modelPath,
                                      int imageWidth, int numClasses)
        {
            //var device = DeviceDescriptor.GPUDevice(0);
            var device      = DeviceDescriptor.CPUDevice;
            var imageDim    = GetImageDim(imageWidth);
            var buildOutput = networkBuilder.Build(device, FeatureStreamName, LabelsStreamName, ClassifierName,
                                                   numClasses, imageDim);
            var imageSize    = GetImageSize(imageWidth);
            var preparedData = new PreparedDataInfo(preparedDataPath, FeatureStreamName, LabelsStreamName, imageSize,
                                                    numClasses, MinibatchSource.InfinitelyRepeat);
            var trainer = CreateTrainer(buildOutput);

            TrainModel(device, preparedData, buildOutput, trainer);
            SaveModel(buildOutput, modelPath);

            // validate the model
            var preparedNewData = new PreparedDataInfo(preparedDataPath, FeatureStreamName, LabelsStreamName, imageSize,
                                                       numClasses, MinibatchSource.FullDataSweep);

            ValidateModelWithMinibatchSource(modelPath, imageDim, numClasses, preparedNewData, FeatureStreamName, device);
        }