/// <summary>
        /// The AnnotatedDataLayer constructor.
        /// </summary>
        /// <param name="cuda">Specifies the CudaDnn connection to Cuda.</param>
        /// <param name="log">Specifies the Log for output.</param>
        /// <param name="p">provides LayerParameter annotated_data_param.</param>
        /// <param name="db">Specifies the external database to use.</param>
        /// <param name="evtCancel">Specifies the CancelEvent used to cancel any pre-fetching operations.</param>
        public AnnotatedDataLayer(CudaDnn <T> cuda, Log log, LayerParameter p, IXImageDatabaseBase db, CancelEvent evtCancel)
            : base(cuda, log, p, db, evtCancel)
        {
            m_type      = LayerParameter.LayerType.ANNOTATED_DATA;
            m_random    = new CryptoRandom(CryptoRandom.METHOD.DEFAULT, p.transform_param.random_seed.GetValueOrDefault(0));
            m_tMinusOne = (T)Convert.ChangeType(-1, typeof(T));

            if (db == null)
            {
                m_log.FAIL("Currently, the AnnotatedDataLayer requires the MyCaffe Image Database!");
            }

            Tuple <IMGDB_LABEL_SELECTION_METHOD, IMGDB_IMAGE_SELECTION_METHOD> kvSel = db.GetSelectionMethod();
            IMGDB_IMAGE_SELECTION_METHOD imgSel = kvSel.Item2;

            if (m_param.data_param.enable_pair_selection.HasValue)
            {
                if (m_param.data_param.enable_pair_selection.Value)
                {
                    imgSel |= IMGDB_IMAGE_SELECTION_METHOD.PAIR;
                }
                else
                {
                    imgSel &= (~IMGDB_IMAGE_SELECTION_METHOD.PAIR);
                }
            }

            if (m_param.data_param.enable_random_selection.HasValue)
            {
                if (m_param.data_param.enable_random_selection.Value)
                {
                    imgSel |= IMGDB_IMAGE_SELECTION_METHOD.RANDOM;
                }
                else
                {
                    imgSel &= (~IMGDB_IMAGE_SELECTION_METHOD.RANDOM);
                }
            }

            if (!db.GetLoadImageDataCriteria())
            {
                m_log.WriteError(new Exception("The 'Load Image Data Criteria' must be set to TRUE in order to load the Annotation data."));
            }

            db.SetSelectionMethod(null, imgSel);

            m_db = new data.DB <T>(db);
            m_db.Open(p.data_param.source);

            if (p.data_param.display_timing)
            {
                m_swTimerBatch       = new Stopwatch();
                m_swTimerTransaction = new Stopwatch();
            }

            m_sampler = new SsdSampler <T>(cuda, log);
        }
        /** @copydoc Layer::dispose */
        protected override void dispose()
        {
            base.dispose();

            if (m_sampler != null)
            {
                m_sampler.Dispose();
                m_sampler = null;
            }
        }
Exemple #3
0
        /// <summary>
        /// The AnnotatedDataLayer constructor.
        /// </summary>
        /// <param name="cuda">Specifies the CudaDnn connection to Cuda.</param>
        /// <param name="log">Specifies the Log for output.</param>
        /// <param name="p">provides LayerParameter annotated_data_param.</param>
        /// <param name="db">Specifies the external database to use.</param>
        /// <param name="evtCancel">Specifies the CancelEvent used to cancel any pre-fetching operations.</param>
        public AnnotatedDataLayer(CudaDnn <T> cuda, Log log, LayerParameter p, IXImageDatabase db, CancelEvent evtCancel)
            : base(cuda, log, p, db, evtCancel)
        {
            m_type = LayerParameter.LayerType.ANNOTATED_DATA;

            Tuple <IMGDB_LABEL_SELECTION_METHOD, IMGDB_IMAGE_SELECTION_METHOD> kvSel = db.GetSelectionMethod();
            IMGDB_IMAGE_SELECTION_METHOD imgSel = kvSel.Item2;

            if (m_param.data_param.enable_pair_selection.HasValue)
            {
                if (m_param.data_param.enable_pair_selection.Value)
                {
                    imgSel |= IMGDB_IMAGE_SELECTION_METHOD.PAIR;
                }
                else
                {
                    imgSel &= (~IMGDB_IMAGE_SELECTION_METHOD.PAIR);
                }
            }

            if (m_param.data_param.enable_random_selection.HasValue)
            {
                if (m_param.data_param.enable_random_selection.Value)
                {
                    imgSel |= IMGDB_IMAGE_SELECTION_METHOD.RANDOM;
                }
                else
                {
                    imgSel &= (~IMGDB_IMAGE_SELECTION_METHOD.RANDOM);
                }
            }

            if (!db.GetLoadImageDataCriteria())
            {
                m_log.WriteError(new Exception("The 'Load Image Data Criteria' must be set to TRUE in order to load the Annotation data."));
            }

            db.SetSelectionMethod(null, imgSel);

            m_db = new data.DB(db);
            m_db.Open(p.data_param.source);
            m_cursor = m_db.NewCursor();

            if (p.data_param.display_timing)
            {
                m_swTimerBatch       = new Stopwatch();
                m_swTimerTransaction = new Stopwatch();
            }

            m_sampler = new SsdSampler <T>(cuda, log);
        }