public void TestAlexNetCiFar()
        {
            CancelEvent   evtCancel = new CancelEvent();
            SettingsCaffe settings  = new SettingsCaffe();

            settings.ImageDbLoadMethod          = IMAGEDB_LOAD_METHOD.LOAD_ON_DEMAND;
            settings.EnableRandomInputSelection = true;
            settings.GpuIds = getGpuIds();

            Trace.WriteLine("Running TestAlexNetCiFar on GPU " + settings.GpuIds);

            ProjectEx          p    = getProject();
            MyCaffeControl <T> ctrl = new MyCaffeControl <T>(settings, m_log, evtCancel);

            try
            {
                ctrl.Load(Phase.TRAIN, p);
                ctrl.OnTrainingIteration += ctrl_OnTrainingIteration;
                ctrl.Train();
            }
            catch (Exception excpt)
            {
                throw excpt;
            }
            finally
            {
                ctrl.Dispose();
            }
        }
Example #2
0
        //-----------------------------------------------------------------------------------------
        //  Simplest Classification (using MyCaffeControl and MyCaffeImageDatabase)
        //-----------------------------------------------------------------------------------------

        /// <summary>
        /// The SimplestClassification shows how to the MyCaffeControl (and internal MyCaffeImageDatabase) to train and test on the MNIST dataset.
        /// </summary>
        /// <param name="sender">Specifies the event sender.</param>
        /// <param name="e">Specifies the event args.</param>
        private void btnSimplestClassification_Click(object sender, EventArgs e)
        {
            DatasetFactory factory  = new DatasetFactory();
            Stopwatch      sw       = new Stopwatch();
            SettingsCaffe  settings = new SettingsCaffe();

            // Load all images into memory before training.
            settings.ImageDbLoadMethod = IMAGEDB_LOAD_METHOD.LOAD_ALL;
            // Use GPU ID = 0.
            settings.GpuIds = "0";

            string strSolver;
            string strModel;

            // Load the descriptors from their respective files (installed by MyCaffe Test Application install)
            load_descriptors("mnist", out strSolver, out strModel);

            // NOTE: model fixup not needed for we will use the DATA layer which pulls data from SQL or SQLEXPRESS via the MyCaffeImageDatabase.
            // Set the interval beyond the iterations to skip testing during solving.
            strSolver = fixup_solver(strSolver, 10000);

            // Load the MNIST dataset descriptor.
            DatasetDescriptor ds = factory.LoadDataset("MNIST");

            // Create a test project with the dataset and descriptors.
            ProjectEx project = new ProjectEx("Test");

            project.SetDataset(ds);
            project.ModelDescription  = strModel;
            project.SolverDescription = strSolver;
            project.WeightsState      = null;

            // Create the MyCaffeControl
            MyCaffeControl <float> mycaffe = new MyCaffeControl <float>(settings, m_log, m_evtCancel);

            // Load the project, using the TRAIN phase.
            mycaffe.Load(Phase.TRAIN, project);

            // Trian the model for 5000 interations (which uses the internal solver and internal training net)
            int nIterations = 5000;

            mycaffe.Train(nIterations);

            // Test the model for 100 iterations (which uses the internal solver and internal testing net)
            nIterations = 100;
            double dfAccuracy = mycaffe.Test(nIterations);

            // Report the testing accuracy.
            m_log.WriteLine("Accuracy = " + dfAccuracy.ToString("P"));

            MessageBox.Show("Average Accuracy = " + dfAccuracy.ToString("P"), "Traing/Test on MNIST Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private ProjectEx getProject()
        {
            ProjectEx p = new ProjectEx("AlexNet Project");

            DatasetFactory    factory = new DatasetFactory();
            DatasetDescriptor ds      = factory.LoadDataset("CIFAR-10");

            p.SetDataset(ds);

            string strModelFile  = getTestPath("\\MyCaffe\\test_data\\models\\alexnet\\cifar\\alexnet_cifar_train_val.prototxt");
            string strSolverFile = getTestPath("\\MyCaffe\\test_data\\models\\alexnet\\cifar\\alexnet_cifar_solver.prototxt");

            p.LoadModelFile(strModelFile);
            RawProto proto = RawProtoFile.LoadFromFile(strSolverFile);

            RawProto iter = proto.FindChild("max_iter");

            iter.Value = m_nMaxIteration.ToString();

            p.SolverDescription = proto.ToString();

            return(p);
        }
Example #4
0
        static void Main(string[] args)
        {
            if (!sqlCheck())
            {
                return;
            }

            Log log = new Log("test");

            log.OnWriteLine += Log_OnWriteLine;
            CancelEvent   cancel   = new CancelEvent();
            SettingsCaffe settings = new SettingsCaffe();

            // Load all images into memory before training.
            settings.ImageDbLoadMethod = IMAGEDB_LOAD_METHOD.LOAD_ALL;
            // Use GPU ID = 0
            settings.GpuIds = "0";

            // Load the descriptors from their respective files
            string strSolver = load_file("C:\\ProgramData\\MyCaffe\\test_data\\models\\siamese\\mnist\\solver.prototxt");
            string strModel  = load_file("C:\\ProgramData\\MyCaffe\\test_data\\models\\siamese\\mnist\\train_val.prototxt");

            RawProto       proto     = RawProto.Parse(strModel);
            NetParameter   net_param = NetParameter.FromProto(proto);
            LayerParameter layer     = net_param.FindLayer(LayerParameter.LayerType.DECODE);

            layer.decode_param.target = DecodeParameter.TARGET.CENTROID;
            proto    = net_param.ToProto("root");
            strModel = proto.ToString();

            // Load the MNIST data descriptor.
            DatasetFactory    factory = new DatasetFactory();
            DatasetDescriptor ds      = factory.LoadDataset("MNIST");

            // Create a test project with the dataset and descriptors
            ProjectEx project = new ProjectEx("Test");

            project.SetDataset(ds);
            project.ModelDescription  = strModel;
            project.SolverDescription = strSolver;

            // Crate the MyCaffeControl (with the 'float' base type)
            string strCudaPath             = "C:\\Program Files\\SignalPop\\MyCaffe\\cuda_11.3\\CudaDnnDll.11.3.dll";
            MyCaffeControl <float> mycaffe = new MyCaffeControl <float>(settings, log, cancel, null, null, null, null, strCudaPath);

            // Load the project, using the TRAIN phase.
            mycaffe.Load(Phase.TRAIN, project);

            // Train the model for 4000 iterations
            // (which uses the internal solver and internal training net)
            int nIterations = 4000;

            mycaffe.Train(nIterations);

            // Test the model for 100 iterations
            // (which uses the internal testing net)
            nIterations = 100;
            double dfAccuracy = mycaffe.Test(nIterations);

            // Report the testing accuracy.
            log.WriteLine("Accuracy = " + dfAccuracy.ToString("P"));

            mycaffe.Dispose();

            Console.Write("Press any key...");
            Console.ReadKey();
        }