Ejemplo n.º 1
0
        public void TestLoadLimitNextSequential(IMAGEDB_LOAD_METHOD loadMethod, int nLoadLimit)
        {
            List <string> rgDs = new List <string>()
            {
                "MNIST", "CIFAR-10", "MNIST"
            };
            IXImageDatabase db = new MyCaffeImageDatabase();

            foreach (string strDs in rgDs)
            {
                DatasetFactory df  = new DatasetFactory();
                int            nDs = df.GetDatasetID(strDs);
                if (nDs == 0)
                {
                    throw new Exception("The dataset '" + strDs + "' does not exist - you need to load it.");
                }

                SettingsCaffe settings = new SettingsCaffe();
                settings.ImageDbLoadMethod = loadMethod;
                settings.ImageDbLoadLimit  = nLoadLimit;

                Stopwatch sw = new Stopwatch();

                sw.Start();
                db.InitializeWithDsName(settings, strDs);
                db.SetSelectionMethod(IMGDB_LABEL_SELECTION_METHOD.NONE, IMGDB_IMAGE_SELECTION_METHOD.NONE);
                string str = sw.ElapsedMilliseconds.ToString();
                Trace.WriteLine(strDs + " Initialization Time: " + str + " ms.");

                DatasetDescriptor ds = db.GetDatasetByName(strDs);
                Dictionary <int, List <SimpleDatum> > rg      = new Dictionary <int, List <SimpleDatum> >();
                Dictionary <int, List <SimpleDatum> > rgFirst = new Dictionary <int, List <SimpleDatum> >();

                int    nTotal    = ds.TrainingSource.ImageCount;
                int    nCount    = 0;
                double dfTotalMs = 0;

                while (nCount < nTotal)
                {
                    for (int i = 0; i < nLoadLimit; i++)
                    {
                        sw.Reset();
                        sw.Start();
                        SimpleDatum d1 = db.QueryImage(ds.TrainingSource.ID, i);
                        dfTotalMs += sw.ElapsedMilliseconds;
                        sw.Stop();

                        if (!rg.Keys.Contains(d1.Index))
                        {
                            rg.Add(d1.Index, new List <SimpleDatum>()
                            {
                                d1
                            });
                        }
                        else
                        {
                            rg[d1.Index].Add(d1);
                        }

                        if (nCount == 0)
                        {
                            if (!rgFirst.Keys.Contains(d1.Index))
                            {
                                rgFirst.Add(d1.Index, new List <SimpleDatum>()
                                {
                                    d1
                                });
                            }
                            else
                            {
                                rgFirst[d1.Index].Add(d1);
                            }
                        }
                    }

                    db.LoadNextSet(null);
                    nCount += nLoadLimit;
                }

                str = (dfTotalMs / (double)nCount).ToString();
                Trace.WriteLine("Average Query Time: " + str + " ms.");

                // Verify that all items have been queried
                Assert.AreEqual(nTotal, rg.Count);

                Dictionary <int, List <SimpleDatum> > rgWrapAround = new Dictionary <int, List <SimpleDatum> >();

                for (int i = 0; i < nLoadLimit; i++)
                {
                    SimpleDatum d1 = db.QueryImage(ds.TrainingSource.ID, i);

                    if (!rgWrapAround.Keys.Contains(d1.Index))
                    {
                        rgWrapAround.Add(d1.Index, new List <SimpleDatum>()
                        {
                            d1
                        });
                    }
                    else
                    {
                        rgWrapAround[d1.Index].Add(d1);
                    }
                }

                // Verify that the reads wrap around to the start.
                Assert.AreEqual(rgWrapAround.Count, rgFirst.Count);

                List <KeyValuePair <int, List <SimpleDatum> > > rg1 = new List <KeyValuePair <int, List <SimpleDatum> > >();
                List <KeyValuePair <int, List <SimpleDatum> > > rg2 = new List <KeyValuePair <int, List <SimpleDatum> > >();

                foreach (KeyValuePair <int, List <SimpleDatum> > kv in rgWrapAround)
                {
                    rg1.Add(kv);
                }

                foreach (KeyValuePair <int, List <SimpleDatum> > kv in rgFirst)
                {
                    rg2.Add(kv);
                }

                for (int i = 0; i < rg1.Count; i++)
                {
                    Assert.AreEqual(rg1[i].Key, rg2[i].Key);
                    Assert.AreEqual(rg1[i].Value.Count, rg2[i].Value.Count);

                    for (int j = 0; j < rg1[i].Value.Count; j++)
                    {
                        Assert.AreEqual(rg1[i].Value[j].Label, rg2[i].Value[j].Label);
                    }
                }
            }

            db.CleanUp();

            IDisposable idisp = db as IDisposable;

            if (idisp != null)
            {
                idisp.Dispose();
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        public void TestQuerySequential(IMAGEDB_LOAD_METHOD loadMethod, int nLoadLimit)
        {
            List <string> rgDs = new List <string>()
            {
                "MNIST", "CIFAR-10", "MNIST"
            };
            IXImageDatabase db = new MyCaffeImageDatabase();

            foreach (string strDs in rgDs)
            {
                DatasetFactory df  = new DatasetFactory();
                int            nDs = df.GetDatasetID(strDs);
                if (nDs == 0)
                {
                    throw new Exception("The dataset '" + strDs + "' does not exist - you need to load it.");
                }

                SettingsCaffe settings = new SettingsCaffe();
                settings.ImageDbLoadMethod = loadMethod;
                settings.ImageDbLoadLimit  = nLoadLimit;

                Stopwatch sw = new Stopwatch();

                sw.Start();
                db.InitializeWithDsName(settings, strDs);
                string str = sw.ElapsedMilliseconds.ToString();
                Trace.WriteLine(strDs + " Initialization Time: " + str + " ms.");

                DatasetDescriptor ds = db.GetDatasetByName(strDs);
                Dictionary <int, List <SimpleDatum> > rg = new Dictionary <int, List <SimpleDatum> >();

                int    nCount    = 100;
                double dfTotalMs = 0;

                for (int i = 0; i < nCount; i++)
                {
                    sw.Reset();
                    sw.Start();
                    SimpleDatum d = db.QueryImage(ds.TrainingSource.ID, 0, IMGDB_LABEL_SELECTION_METHOD.NONE, IMGDB_IMAGE_SELECTION_METHOD.NONE);
                    dfTotalMs += sw.ElapsedMilliseconds;
                    sw.Stop();

                    if (!rg.Keys.Contains(d.Index))
                    {
                        rg.Add(d.Index, new List <SimpleDatum>()
                        {
                            d
                        });
                    }
                    else
                    {
                        rg[d.Index].Add(d);
                    }
                }

                str = (dfTotalMs / (double)nCount).ToString();
                Trace.WriteLine("Average Query Time: " + str + " ms.");

                // Verify sequential selection, so all indexes should be the same.

                foreach (KeyValuePair <int, List <SimpleDatum> > kv in rg)
                {
                    Assert.AreEqual(kv.Value.Count, nCount);
                }
            }

            db.CleanUp();

            IDisposable idisp = db as IDisposable;

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