Exemple #1
0
        public void LoadDatabase()
        {
            int nIdx   = 0;
            int nTotal = 0;

            reportProgress(nIdx, nTotal, "Unpacking files...");
            string strTrainImagesBin = expandFile(m_param.TrainImagesFile);
            string strTrainLabelsBin = expandFile(m_param.TrainLabelsFile);
            string strTestImagesBin  = expandFile(m_param.TestImagesFile);
            string strTestLabelsBin  = expandFile(m_param.TestLabelsFile);

            reportProgress(nIdx, nTotal, "Loading database...");

            loadFile(strTrainImagesBin, strTrainLabelsBin, "MNIST.training");
            loadFile(strTestImagesBin, strTestLabelsBin, "MNIST.testing");

            DatasetFactory    factory  = new DatasetFactory();
            SourceDescriptor  srcTrain = factory.LoadSource("MNIST.training");
            SourceDescriptor  srcTest  = factory.LoadSource("MNIST.testing");
            DatasetDescriptor ds       = new DatasetDescriptor(0, "MNIST", null, null, srcTrain, srcTest, "MNIST", "MNIST Character Dataset");

            factory.AddDataset(ds);
            factory.UpdateDatasetCounts(ds.ID);

            if (OnCompleted != null)
            {
                OnCompleted(this, new EventArgs());
            }
        }
Exemple #2
0
 void updateLabels(DatasetFactory factory)
 {
     for (int i = 0; i < m_parser.Labels.Count; i++)
     {
         factory.UpdateLabelName(i, m_parser.Labels[i]);
     }
 }
        bool loadFile(Log log, string strName, string strFile, DatasetFactory factory, int nTotal, bool bCreateMeanImage, ref int nIdx)
        {
            Stopwatch sw = new Stopwatch();

            log.WriteLine("Loading '" + strName + "' into '" + factory.OpenSource.Name + "'...");

            sw.Start();

            FileStream fs = null;

            try
            {
                fs = new FileStream(strFile, FileMode.Open, FileAccess.Read);
                using (BinaryReader br = new BinaryReader(fs))
                {
                    fs = null;

                    for (int i = 0; i < 10000; i++)
                    {
                        int    nLabel     = (int)br.ReadByte();
                        byte[] rgImgBytes = br.ReadBytes(3072);
                        Bitmap img        = createImage(rgImgBytes);

                        if (m_bCancel)
                        {
                            return(false);
                        }

                        Datum d = ImageData.GetImageDataD(img, 3, false, nLabel);

                        factory.PutRawImageCache(nIdx, d);
                        nIdx++;

                        if (bCreateMeanImage)
                        {
                            m_rgImages.Add(new SimpleDatum(d));
                        }

                        if (sw.ElapsedMilliseconds > 1000)
                        {
                            sw.Stop();
                            log.Progress = (double)nIdx / (double)nTotal;
                            log.WriteLine("Processing " + nIdx.ToString() + " of " + nTotal.ToString());
                            sw.Restart();
                        }
                    }

                    factory.ClearImageCache(true);
                }
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }

            return(true);
        }
Exemple #4
0
        /// <summary>
        /// The constructor.
        /// </summary>
        /// <param name="random">Specifies the CryptoRandom to use for random selection.</param>
        /// <param name="log">Specifies the output log.</param>
        /// <param name="src">Specifies the data source that holds the data on the database.</param>
        /// <param name="factory">Specifies the data factory used to access the database data.</param>
        /// <param name="rgAbort">Specifies the cancel handles.</param>
        /// <param name="nMaxLoadCount">Optionally, specifies to automaticall start the image refresh which only applies when the number of images loaded into memory is less than the actual number of images (default = false).</param>
        public MasterList(CryptoRandom random, Log log, SourceDescriptor src, DatasetFactory factory, List <WaitHandle> rgAbort, int nMaxLoadCount = 0)
        {
            m_random  = random;
            m_log     = log;
            m_src     = src;
            m_factory = factory;

            m_rgAbort.Add(m_evtCancel);
            if (rgAbort.Count > 0)
            {
                m_rgAbort.AddRange(rgAbort);
            }

            m_imgMean = m_factory.LoadImageMean(m_src.ID);

            m_nLoadCount = nMaxLoadCount;
            if (m_nLoadCount == 0 || m_nLoadCount > m_src.ImageCount)
            {
                m_nLoadCount = m_src.ImageCount;
            }

            m_rgImages     = new SimpleDatum[m_nLoadCount];
            m_nLoadedCount = 0;

            if (m_nLoadCount < m_src.ImageCount)
            {
                m_refreshManager = new RefreshManager(random, m_src, m_factory);
            }
        }
Exemple #5
0
 /// <summary>
 /// Release all resources used.
 /// </summary>
 public void Dispose()
 {
     if (m_factory != null)
     {
         m_factory.Close();
         m_factory.Dispose();
         m_factory = null;
     }
 }
 /// <summary>
 /// Releases the resouces used.
 /// </summary>
 /// <param name="bDisposing">Set to <i>true</i> when called by Dispose()</param>
 protected virtual void Dispose(bool bDisposing)
 {
     if (m_factory != null)
     {
         m_factory.Close();
         m_factory.Dispose();
         m_factory = null;
     }
 }
Exemple #7
0
        /// <summary>
        /// The DatasetEx constructor.
        /// </summary>
        /// <param name="user">Specifies the unique ID of the dataset user.</param>
        /// <param name="factory">Specifies the DatasetFactory used to manage the database datasets.</param>
        public DatasetEx(Guid user, DatasetFactory factory)
        {
            if (user != Guid.Empty)
            {
                m_rgUsers.Add(user);
            }

            m_factory = new DatasetFactory(factory);
        }
        public MgrMnistData(DatasetFactory factory, Log log, string strTargetFileOverlay, MyCaffeImageDatabase imgDb = null)
        {
            m_factory = factory;
            m_log     = log;

            if (!string.IsNullOrEmpty(strTargetFileOverlay) && File.Exists(strTargetFileOverlay))
            {
                m_bmpTargetOverlay = new Bitmap(strTargetFileOverlay);
                m_random           = new Random();
            }
        }
Exemple #9
0
        /// <summary>
        /// The DatasetEx constructor.
        /// </summary>
        /// <param name="user">Specifies the unique ID of the dataset user.</param>
        /// <param name="factory">Specifies the DatasetFactory used to manage the database datasets.</param>
        /// <param name="random">Specifies the random number generator.</param>
        public DatasetEx2(Guid user, DatasetFactory factory, CryptoRandom random)
        {
            m_random = random;

            if (user != Guid.Empty)
            {
                m_rgUsers.Add(user);
            }

            m_factory = new DatasetFactory(factory);
        }
Exemple #10
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);
        }
        public void TestIndexQuery()
        {
            PreTest.Init();
            Log log = new Log("Test Dataset Factory");

            log.EnableTrace = true;

            string         strDs   = "MNIST";
            DatasetFactory factory = new DatasetFactory();
            Stopwatch      sw      = new Stopwatch();

            try
            {
                DatasetDescriptor ds = factory.LoadDataset(strDs);
                factory.Open(ds.TrainingSource.ID);

                sw.Start();
                List <DbItem> rgItems = factory.LoadImageIndexes(false);
                sw.Stop();

                log.CHECK_EQ(rgItems.Count, ds.TrainingSource.ImageCount, "The query count should match the image count!");
                factory.Close();

                log.WriteLine("Query time = " + sw.Elapsed.TotalMilliseconds.ToString("N5") + " ms.");

                sw.Restart();

                int nMin = int.MaxValue;
                int nMax = -int.MaxValue;
                for (int i = 0; i < rgItems.Count; i++)
                {
                    nMin = Math.Min(rgItems[i].Label, nMin);
                    nMax = Math.Max(rgItems[i].Label, nMax);
                }

                List <DbItem> rgBoosted = rgItems.Where(p => p.Boost > 0).ToList();

                for (int nLabel = nMin; nLabel <= nMax; nLabel++)
                {
                    List <DbItem> rgLabel = rgItems.Where(p => p.Label == nLabel).ToList();
                }

                sw.Stop();

                log.WriteLine("Query time (profile) = " + sw.Elapsed.TotalMilliseconds.ToString("N5") + " ms.");
            }
            finally
            {
                factory.Dispose();
            }
        }
Exemple #12
0
        /// <summary>
        /// The ImageSet2 constructor.
        /// </summary>
        /// <param name="type">Specifies the type of data source managed.</param>
        /// <param name="log">Specifies the output log.</param>
        /// <param name="factory">Specifies the data factory used to access the database data.</param>
        /// <param name="src">Specifies the data source descriptor.</param>
        /// <param name="loadMethod">Specifies the load method used to load the data.</param>
        /// <param name="random">Specifies the random number generator.</param>
        /// <param name="rgAbort">Specifies the cancellation handles.</param>
        public ImageSet2(TYPE type, Log log, DatasetFactory factory, SourceDescriptor src, IMAGEDB_LOAD_METHOD loadMethod, CryptoRandom random, WaitHandle[] rgAbort)
            : base(factory, src)
        {
            m_type       = type;
            m_log        = log;
            m_loadMethod = loadMethod;
            m_random     = random;

            m_rgAbort.Add(m_evtCancel);
            if (rgAbort.Length > 0)
            {
                m_rgAbort.AddRange(rgAbort);
            }
        }
Exemple #13
0
        /// <summary>
        /// The constructor used to copy another MasterIndexes and optionally specify a sorting for the indexes.
        /// </summary>
        /// <param name="idx">Specifies the MasterIndexes to copy.</param>
        /// <param name="sort">Optionally, specifies a sorting to use on the indexes.</param>
        public MasterIndexes(MasterIndexes idx, IMGDB_SORT sort)
        {
            m_sort       = sort;
            m_src        = idx.m_src;
            m_random     = idx.m_random;
            m_nLoadLimit = idx.m_nLoadLimit;
            m_factory    = new DatasetFactory(idx.m_factory);

            m_index    = idx.m_index.Clone(sort);
            m_rgLabels = new LabelIndex(idx.m_rgLabels);

            m_boosted         = idx.m_boosted.Clone(sort);
            m_rgLabelsBoosted = new LabelIndex(idx.m_rgLabelsBoosted);
        }
Exemple #14
0
        //public static void AddDatasetsIfWanted(bool addDatasets, Study study)
        //{
        //    if (addDatasets)
        //    {
        //        for (var counter = 0; counter <= 2; counter++)
        //        {
        //            var datasetName = $"ds-{counter}";
        //            var datasetClassification = (DatasetClassification)counter;

        //            study.StudyDatasets.Add(DatasetFactory.CreateStudySpecificRelation(study, datasetName, TestConstants.REGION, datasetClassification.ToString()));
        //        }
        //    }
        //}

        public static void AddDatasetsIfWanted(bool addDatasets, Study study)
        {
            if (addDatasets)
            {
                for (var counter = 0; counter <= 2; counter++)
                {
                    var datasetName           = $"ds-{counter}";
                    var datasetClassification = (DatasetClassification)counter;

                    var datasetRelation = DatasetFactory.CreateStudySpecificRelation(study, datasetName, TestConstants.REGION, datasetClassification.ToString());
                    study.StudyDatasets.Add(datasetRelation);
                }
            }
        }
Exemple #15
0
        public IDatasetProxy GetOrCreateDataSetProxy(IPool <GameObject> pool)
        {
            var updater = GetUpdaterByPool(pool);

            if (updater != null)
            {
                return(updater.DataSet as IDatasetProxy);
            }

            var dataset = DatasetFactory.Create();

            var proxy = DatasetProxyFactory.Create(((Component)pool).gameObject);

            proxy.Origin = dataset;

            return(proxy);
        }
        public void TestPutRawImage(bool bSaveImagesToFile)
        {
            DatasetFactory factory = new DatasetFactory();

            factory.DeleteSources("Test123");
            int nSrcId = factory.AddSource("Test123", 1, 10, 10, false, 0, bSaveImagesToFile);

            factory.Open(nSrcId, 10);

            byte[] rgBytes = new byte[10 * 10];

            for (int i = 0; i < 20; i++)
            {
                rgBytes[i] = (byte)i;
                SimpleDatum sd = new SimpleDatum(false, 1, 10, 10, i, DateTime.MinValue, rgBytes.ToList(), null, 0, false, i);

                factory.PutRawImageCache(i, sd);
            }

            factory.ClearImageCash(true);

            List <RawImage> rgImg = factory.GetRawImagesAt(0, 20);

            for (int i = 0; i < rgImg.Count; i++)
            {
                SimpleDatum sd       = factory.LoadDatum(rgImg[i]);
                bool        bEncoded = false;
                byte[]      rgData   = sd.GetByteData(out bEncoded);

                for (int j = 0; j < 100; j++)
                {
                    if (j <= i)
                    {
                        Assert.AreEqual(rgData[j], j);
                    }
                    else
                    {
                        Assert.AreEqual(rgData[j], 0);
                    }
                }
            }

            factory.DeleteSources("Test123");
            factory.Close();
        }
Exemple #17
0
        bool loadData(Log log, DatasetFactory factory, CsvParser parser, List <DataItem> rgData, List <int> rgDim, bool bTraining, bool bCreateImageMean)
        {
            Stopwatch sw = new Stopwatch();

            log.WriteLine("Loading data into '" + factory.OpenSource.Name + "'...");
            sw.Start();

            m_rgImages.Clear();

            int nSize = rgDim[1] / m_schema.CellSize;

            for (int i = 0; i < rgData.Count; i++)
            {
                int    nLabel = rgData[i].Label;
                Bitmap bmp    = createImage(rgData[i].Data, nSize, m_schema.CellSize, m_schema.BinaryValues);

                if (m_bCancel)
                {
                    return(false);
                }

                Datum d = ImageData.GetImageDataD(bmp, rgDim[0], false, nLabel);
                factory.PutRawImageCache(i, d);

                if (bCreateImageMean)
                {
                    m_rgImages.Add(new SimpleDatum(d));
                }

                if (sw.ElapsedMilliseconds > 1000)
                {
                    sw.Stop();
                    log.Progress = (double)i / (double)rgData.Count;
                    log.WriteLine("Processing " + i.ToString() + " of " + rgData.Count.ToString());
                    sw.Restart();
                    factory.ClearImageCache(true);
                }
            }

            factory.ClearImageCache(true);

            return(true);
        }
Exemple #18
0
        /// <summary>
        /// 创建结果影像数据
        /// </summary>
        /// <param name="imageBox">结果数组</param>
        /// <param name="imgInfo">影像图层信息</param>
        public static void createImageLayer(float[] imageBox, Image imgInfo)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title  = "请选择保存路径";
            sfd.Filter = "Raster Flie|*.tif";
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            int[]          bandMap = { 1 };
            IRasterDataset rs      = DatasetFactory.CreateRasterDataset(sfd.FileName, imgInfo.layerW, imgInfo.layerH, 1, PixelDataType.Float32, "GTiff", null);

            rs.SpatialReference = imgInfo.sr;
            rs.Write(0, 0, imgInfo.layerW, imgInfo.layerH, imageBox, imgInfo.layerW, imgInfo.layerH, PixelDataType.Float32, 1, bandMap);
            rs.SetGeoTransform(imgInfo.geoTrans);   //处理影像数据空间位置偏移
            MessageBox.Show("分析完成");
        }
Exemple #19
0
        /// <summary>
        /// The ImageSet constructor.
        /// </summary>
        /// <param name="factory">Specifies the DatasetFactory.</param>
        /// <param name="src">Specifies the data source.</param>
        /// <param name="loadMethod">Specifies the method to use when loading the images.</param>
        /// <param name="nLoadLimit">Specifies the image load limit.</param>
        public ImageSet(DatasetFactory factory, SourceDescriptor src, IMAGEDB_LOAD_METHOD loadMethod, int nLoadLimit)
        {
            m_factory = new DatasetFactory(factory);
            m_factory.Open(src.ID);
            m_loadMethod = loadMethod;
            m_nLoadLimit = nLoadLimit;
            m_src        = new SourceDescriptor(src);
            m_imgMean    = null;

            m_rgImages = new SimpleDatum[m_src.ImageCount];

            foreach (LabelDescriptor label in src.Labels)
            {
                if (label.ImageCount > 0)
                {
                    m_rgLabelSet.Add(new LabelSet(label));
                }
            }
        }
        void updateLabels(DatasetFactory factory)
        {
            Dictionary <int, string> rgLabels = new Dictionary <int, string>();

            rgLabels.Add(0, "airplane");
            rgLabels.Add(1, "automobile");
            rgLabels.Add(2, "bird");
            rgLabels.Add(3, "cat");
            rgLabels.Add(4, "deer");
            rgLabels.Add(5, "dog");
            rgLabels.Add(6, "frog");
            rgLabels.Add(7, "horse");
            rgLabels.Add(8, "ship");
            rgLabels.Add(9, "truck");

            for (int i = 0; i < rgLabels.Count; i++)
            {
                factory.UpdateLabelName(i, rgLabels[i]);
            }
        }
Exemple #21
0
        private void Bn_InputFile1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "请选择要打开的数据:";
            openFileDialog.Filter = "Raster Files|*.tif;*.tiff;*.img";
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Tb_InputFile1.Text          = openFileDialog.FileName;
            PCAfusionParams.PanFilePath = openFileDialog.FileName;
            IRasterDataset rasterDataset = DatasetFactory.OpenRasterDataset(openFileDialog.FileName, OpenMode.Update) as IRasterDataset;

            Cb_BandSelect.Items.Clear();
            for (int i = 1; i <= rasterDataset.GetBandCount(); i++)
            {
                Cb_BandSelect.Items.Add("波段" + i.ToString());
            }
        }
        /// <summary>
        /// 点击获取数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "请选择要打开的数据";
            openFileDialog.Filter = "Raster Files|*.tif;*.tiff;*.img";
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            textBox1.Text          = openFileDialog.FileName;
            neuralEx.InputFilePath = openFileDialog.FileName;
            IRasterDataset rasterDataset = DatasetFactory.OpenRasterDataset(openFileDialog.FileName, OpenMode.Update) as IRasterDataset;

            listBox1.Items.Clear();
            for (int i = 1; i <= rasterDataset.GetBandCount(); i++)
            {
                listBox1.Items.Add("波段" + i.ToString());
            }
            BandCount = rasterDataset.GetBandCount();
        }
        public void LoadDatabase()
        {
            int nIdx   = 0;
            int nTotal = 50000;

            reportProgress(nIdx, 0, "Loading database...");

            Log log = new Log("MNIST");

            log.OnWriteLine += Log_OnWriteLine;

            DatasetFactory factory = new DatasetFactory();

            loadFile(m_param.DataBatchFile1, "CIFAR-10.training", nTotal, ref nIdx);
            loadFile(m_param.DataBatchFile2, "CIFAR-10.training", nTotal, ref nIdx);
            loadFile(m_param.DataBatchFile3, "CIFAR-10.training", nTotal, ref nIdx);
            loadFile(m_param.DataBatchFile4, "CIFAR-10.training", nTotal, ref nIdx);
            loadFile(m_param.DataBatchFile5, "CIFAR-10.training", nTotal, ref nIdx);
            SourceDescriptor srcTrain = factory.LoadSource("CIFAR-10.training");

            m_factory.SaveImageMean(SimpleDatum.CalculateMean(log, m_rgImg.ToArray(), new WaitHandle[] { new ManualResetEvent(false) }), true, srcTrain.ID);

            m_rgImg = new List <SimpleDatum>();
            nIdx    = 0;
            nTotal  = 10000;
            loadFile(m_param.TestBatchFile, "CIFAR-10.testing", nTotal, ref nIdx);
            SourceDescriptor srcTest = factory.LoadSource("CIFAR-10.testing");

            m_factory.SaveImageMean(SimpleDatum.CalculateMean(log, m_rgImg.ToArray(), new WaitHandle[] { new ManualResetEvent(false) }), true, srcTest.ID);

            DatasetDescriptor ds = new DatasetDescriptor(0, "CIFAR-10", null, null, srcTrain, srcTest, "CIFAR-10", "CiFar-10 Dataset");

            factory.AddDataset(ds);
            factory.UpdateDatasetCounts(ds.ID);

            if (OnCompleted != null)
            {
                OnCompleted(this, new EventArgs());
            }
        }
Exemple #24
0
        /// <summary>
        /// Releases all resources used.
        /// </summary>
        /// <param name="bDisposing">Set to <i>true</i> when called by Dispose().</param>
        protected virtual void Dispose(bool bDisposing)
        {
            m_ds = null;

            if (m_TestingImages != null)
            {
                m_TestingImages.Dispose();
                m_TestingImages = null;
            }

            if (m_TrainingImages != null)
            {
                m_TrainingImages.Dispose();
                m_TrainingImages = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
Exemple #25
0
        //private string BandNameString(ILdfDataProvider fileRaster)
        //{
        //    if (fileRaster == null)
        //        return null;
        //    string[] bandNames = (fileRaster as ILdfDataProvider).Hdr.BandNames;
        //    if (bandNames == null || bandNames.Length == 0)
        //        return null;
        //    string bandNameString = "";
        //    foreach (string b in bandNames)
        //    {
        //        bandNameString = bandNameString + b + ",";
        //    }
        //    return bandNameString.TrimEnd(',');
        //}

        internal AbstractWarpDataset CreateOutFile(string outfilename, int dstBandCount, Size outSize, DataType dataType, PrjEnvelope prjEnv, SpatialReference spaRef, string[] options)
        {
            string dir = Path.GetDirectoryName(outfilename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            Envelope env = new Envelope {
                MaxX = prjEnv.MaxX, MinX = prjEnv.MinX, MaxY = prjEnv.MaxY, MinY = prjEnv.MinY
            };
            var rDs = DatasetFactory.CreateRasterDataset(outfilename, outSize.Width, outSize.Height, dstBandCount, dataType, "GTiff", null);

            //env
            double[] geoTrans = Enumerable.Repeat(0.0, 6).ToArray();
            geoTrans[0] = prjEnv.MinX;
            geoTrans[3] = prjEnv.MaxY;
            geoTrans[1] = prjEnv.Width / outSize.Width;
            geoTrans[5] = -prjEnv.Height / outSize.Height;
            rDs.SetProjection(spaRef.ExportToWkt());
            return(new WarpDataset(rDs, outfilename));
        }
Exemple #26
0
        private void Bn_ChooseFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "请选择要打开的数据:";
            openFileDialog.Filter = "Raster Files|*.tif;*.tiff;*.img";
            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            Tb_InputFile.Text           = openFileDialog.FileName;
            iSODataParams.InputFilePath = openFileDialog.FileName;
            IRasterDataset rasterDataset = DatasetFactory.OpenRasterDataset(openFileDialog.FileName, OpenMode.Update) as IRasterDataset;

            for (int i = 1; i <= rasterDataset.GetBandCount(); i++)
            {
                LB_BandDisplay.Items.Add("波段" + i.ToString());
            }
            IList <int> lowBand = new List <int>();

            lowBand.Add(0); lowBand.Add(1); lowBand.Add(2);
            iSODataParams.LowBands = lowBand;
        }
        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);
        }
Exemple #28
0
        /// <summary>
        /// Releases all resources used.
        /// </summary>
        /// <param name="bDisposing">Set to <i>true</i> when called by Dispose().</param>
        protected virtual void Dispose(bool bDisposing)
        {
            m_ds = null;

            StopAutomaticRefreshSchedule(true, true);

            if (m_TestingImages != null)
            {
                m_TestingImages.Dispose();
                m_TestingImages = null;
            }

            if (m_TrainingImages != null)
            {
                m_TrainingImages.Dispose();
                m_TrainingImages = null;
            }

            if (m_factory != null)
            {
                m_factory.Dispose();
                m_factory = null;
            }
        }
Exemple #29
0
        private void dataRefreshThread()
        {
            m_evtRefreshRunning.Set();
            DatasetFactory factory = new DatasetFactory(m_factory);
            Stopwatch      sw      = new Stopwatch();

            try
            {
                sw.Start();

                m_log.WriteLine("Starting refresh of " + m_nReplacementBatch.ToString("N0") + " items...");

                List <Tuple <int, SimpleDatum> > rgReplace = new List <Tuple <int, SimpleDatum> >();
                List <Tuple <int, DbItem> >      rgItems   = new List <Tuple <int, DbItem> >();
                List <DbItem> rgDbItems = new List <DbItem>();

                // Load the replacement set.
                for (int i = 0; i < m_nReplacementBatch; i++)
                {
                    int nIdx   = m_random.Next(m_rgImages.Length);
                    int?nLabel = null;

                    if (m_rgImages[nIdx] != null)
                    {
                        nLabel = m_rgImages[nIdx].Label;
                    }

                    DbItem img = m_refreshManager.GetNextImageId(nLabel);
                    rgItems.Add(new Tuple <int, DbItem>(nIdx, img));
                    rgDbItems.Add(img);

                    if (sw.Elapsed.TotalMilliseconds > 1000)
                    {
                        if (m_evtRefreshCancel.WaitOne(0))
                        {
                            return;
                        }

                        sw.Restart();
                    }
                }

                // Get the Datums, ordered by ID.
                List <SimpleDatum> rgImg = m_factory.GetImagesAt(rgDbItems, m_evtCancel);
                if (rgImg == null)
                {
                    return;
                }

                rgImg   = rgImg.OrderBy(p => p.ImageID).ToList();
                rgItems = rgItems.OrderBy(p => p.Item2.ID).ToList();

                if (rgImg.Count != rgItems.Count)
                {
                    List <Tuple <int, DbItem> > rgItems1 = new List <Tuple <int, DbItem> >();
                    int nIdx = 0;
                    for (int i = 0; i < rgImg.Count; i++)
                    {
                        while (nIdx < rgItems.Count && rgItems[nIdx].Item2.ID < rgImg[i].ImageID)
                        {
                            nIdx++;
                        }

                        if (rgItems[nIdx].Item2.ID == rgImg[i].ImageID)
                        {
                            rgItems1.Add(rgItems[nIdx]);
                            nIdx++;
                        }
                    }

                    rgItems = rgItems1;
                }

                for (int i = 0; i < rgItems.Count; i++)
                {
                    rgReplace.Add(new Tuple <int, SimpleDatum>(rgItems[i].Item1, rgImg[i]));
                }

                lock (m_syncObj)
                {
                    int nMismatchCount = 0;

                    for (int i = 0; i < rgReplace.Count; i++)
                    {
                        int nIdx = rgReplace[i].Item1;
                        if (m_rgImages[nIdx] != null && m_rgImages[nIdx].Label != rgReplace[i].Item2.Label)
                        {
                            nMismatchCount++;
                        }
                        else
                        {
                            m_rgImages[nIdx] = rgReplace[i].Item2;
                        }
                    }

                    if (nMismatchCount > 0)
                    {
                        m_log.WriteLine("WARNING: " + nMismatchCount.ToString("N0") + " label mismatches found!");
                    }
                }
            }
            finally
            {
                m_evtRefreshRunning.Reset();
                m_evtRefreshDone.Set();
            }
        }
Exemple #30
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            try
            {
                List <string> rgSqlInst = DatabaseInstanceQuery.GetInstances();

                m_bwProcess.RunWorkerAsync();

                if (!File.Exists("index.chm"))
                {
                    localHelpToolStripMenuItem.Enabled = false;
                }

                if (rgSqlInst == null || rgSqlInst.Count == 0)
                {
                    setStatus("You must download and install 'Microsoft SQL' or 'Microsoft SQL Express' first!");
                    setStatus("see 'https://www.microsoft.com/en-us/sql-server/sql-server-editions-express'");
                    setStatus("");
                    return;
                }
                else if (rgSqlInst.Count == 1)
                {
                    if (rgSqlInst[0] != ".\\MSSQLSERVER")
                    {
                        EntitiesConnection.GlobalDatabaseServerName = rgSqlInst[0];
                    }
                }
                else
                {
                    FormSqlInstances dlg = new FormSqlInstances(rgSqlInst);

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        if (dlg.Instance != ".\\MSSQLSERVER")
                        {
                            EntitiesConnection.GlobalDatabaseServerName = dlg.Instance;
                        }
                    }
                    else
                    {
                        setStatus("You are NOT connected to SQL.");
                    }
                }

                setStatus("Using SQL Instance '" + EntitiesConnection.GlobalDatabaseServerName + "'", false);

                DatabaseManagement dbMgr = new DatabaseManagement("DNN", "", EntitiesConnection.GlobalDatabaseServerName);
                bool      bExists;
                Exception err = dbMgr.DatabaseExists(out bExists);

                if (err != null)
                {
                    setStatus("ERROR: " + err.Message);
                }
                else if (!bExists)
                {
                    createDatabaseToolStripMenuItem_Click(this, new EventArgs());
                }
                else
                {
                    setStatus("Using database '" + dbMgr.Name + "'");
                }

                setStatus("");

                m_autoTest.OnProgress  += m_autoTest_OnProgress;
                m_autoTest.OnCompleted += m_autoTest_OnCompleted;

                setStatus("The MyCaffe Test App supports two different types of automated testing:");
                setStatus(" 1.) User interface based automated testing via the 'Test | Run Autotests UI', and");
                setStatus(" 2.) Server based automated testing via the 'Test | Start Server Autotests' menu.");
                setStatus("Server auto tests can easily integrate into other applications.");
                setStatus("NOTE: Known test failures are pre-set with a FAILURE status.");
                setStatus("----------------------------------------------------------------------------------");

                DatasetFactory factory  = new DatasetFactory();
                int            nCifarID = factory.GetDatasetID("CIFAR-10");
                int            nMnistID = factory.GetDatasetID("MNIST");

                if (nCifarID == 0 || nMnistID == 0)
                {
                    setStatus(" !Before running any automated tests, make sure to load the following datasets:");

                    if (nCifarID == 0)
                    {
                        setStatus("    CIFAR-10");
                    }

                    if (nMnistID == 0)
                    {
                        setStatus("    MNIST");
                    }

                    setStatus(" see the 'Database' menu.");
                }
            }
            catch (Exception excpt)
            {
                string strErr = excpt.Message;

                if (excpt.InnerException != null)
                {
                    strErr += " " + excpt.InnerException.Message;
                }

                if (strErr.Contains("login") && strErr.Contains("DNN"))
                {
                    strErr += " Make sure that this user can access the DNN database - this setting is made using the SQL Management Studio.";
                }

                setStatus("ERROR: " + strErr);
            }
        }