2using System.Collections.Generic;
6using System.Threading.Tasks;
43 List<BatchSampler> m_rgBatchSamplers =
new List<BatchSampler>();
47 string m_strLabelMapFile;
64 private T[] m_rgTopData =
null;
65 private T[] m_rgTopLabel =
null;
79 : base(cuda, log, p, db, evtCancel)
82 m_log.
FAIL(
"Currently, the AnnotatedDataLayer requires the MyCaffe Image Database!");
86 m_tMinusOne = (T)Convert.ChangeType(-1, typeof(T));
89 m_log.
FAIL(
"Currently, the AnnotatedDataLayer requires the MyCaffe Image Database!");
91 Tuple<DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD> kvSel = db.
GetSelectionMethod();
111 m_log.
WriteError(
new Exception(
"The 'Load Image Data Criteria' must be set to TRUE in order to load the Annotation data."));
132 if (m_sampler !=
null)
168 m_rgBatchSamplers.Add(sampler);
177 m_log.
CHECK_EQ(nBatchSize, 1,
"The FIT_SMALL_SIZE resize mode only supports a batch size of 1.");
184 List<int> rgTopShape =
m_transformer.InferBlobShape(anno_datum);
186 rgTopShape[0] = nBatchSize;
187 colTop[0].Reshape(rgTopShape);
210 m_log.
WriteLine(
"WARNING: Annotation type stored in AnnotatedDatum is shadowed.");
239 rgLabelShape[2] = Math.Max(nNumBboxes, 1);
249 rgLabelShape[0] = nBatchSize;
252 colTop[1].Reshape(rgLabelShape);
298 m_log.
CHECK(batch.
Data.count() > 0,
"There is no space allocated for data!");
309 int nCount = batch.
Label.count();
310 m_log.
CHECK_GT(nCount, 0,
"The label count cannot be zero!");
312 if (m_rgTopLabel ==
null || m_rgTopLabel.Length < nCount)
313 m_rgTopLabel =
new T[nCount];
322 Dictionary<int, AnnotationGroupCollection> rgAllAnno =
null;
323 List<int> rgTopShape =
null;
324 bool bLabelDirty =
false;
326 for (
int i = 0; i < nBatchSize; i++)
338 datum =
m_cursor.GetValue(
null,
true);
352 rgTopShape[0] = nBatchSize;
354 batch.
Data.Reshape(rgTopShape);
357 for (
int k = 1; k < rgTopShape.Count; k++)
359 nDim *= rgTopShape[k];
362 int nTopLen = nDim * nBatchSize;
363 if (m_rgTopData ==
null || m_rgTopData.Length != nTopLen)
364 m_rgTopData =
new T[nTopLen];
377 expand_datum = distort_datum;
385 expand_datum = datum;
391 if (m_rgBatchSamplers.Count > 0)
393 List<NormalizedBBox> rgSampledBboxes = m_sampler.
GenerateBatchSamples(expand_datum, m_rgBatchSamplers);
396 if (rgSampledBboxes.Count > 0)
398 int nIdx = m_random.
Next(rgSampledBboxes.Count);
399 sampled_datum =
m_transformer.CropImage(expand_datum, rgSampledBboxes[nIdx]);
403 m_log.
CHECK(sampled_datum !=
null,
"The sampled datum cannot be null!");
404 List<int> rgShape =
m_transformer.InferBlobShape(sampled_datum);
409 batch.
Data.Reshape(rgShape);
413 int nOffset = batch.
Data.offset(i);
428 T[] rgTrans =
m_transformer.Transform(sampled_datum, out rgTransformedAnnoVec, out bMirror);
429 Array.Copy(rgTrans, 0, m_rgTopData, nDim * i, nDim);
434 for (
int g = 0; g < rgTransformedAnnoVec.Count; g++)
436 nNumBboxes += rgTransformedAnnoVec[g].annotations.Count;
444 if (rgAllAnno ==
null)
445 rgAllAnno =
new Dictionary<int, AnnotationGroupCollection>();
447 rgAllAnno.Add(i, rgTransformedAnnoVec);
452 Array.Copy(rgTrans, 0, m_rgTopData, nDim * i, nDim);
457 if (datum.DataCriteria ==
null || datum.DataCriteria.Length == 0)
461 int nLen = BitConverter.ToInt32(datum.DataCriteria, datum.DataCriteria.Length - (
sizeof(
int) * 4));
462 int nItemSize = BitConverter.ToInt32(datum.DataCriteria, datum.DataCriteria.Length - (
sizeof(
int) * 3));
463 int nDstIdx = i * nLen;
465 m_log.
CHECK_EQ(nItemSize, 1,
"Currently only byte sized labels are supported in multi-label scenarios.");
466 Array.Copy(datum.DataCriteria, 0, m_rgTopLabel, nDstIdx, nLen);
470 m_rgTopLabel[i] = (T)Convert.ChangeType(datum.Label, typeof(T));
486 batch.
Data.SetCPUData(m_rgTopData);
489 batch.
Label.SetCPUData(m_rgTopLabel);
506 batch.
Label.Reshape(rgLabelShape);
508 for (
int i = 0; i < m_rgTopLabel.Length; i++)
510 m_rgTopLabel[i] = m_tMinusOne;
513 batch.
Label.SetCPUData(m_rgTopLabel);
518 rgLabelShape[2] = nNumBboxes;
519 batch.
Label.Reshape(rgLabelShape);
520 int nCount = batch.
Label.count();
521 m_log.
CHECK_GT(nCount, 0,
"The label count cannot be zero!");
522 float[] rgTopLabel1 =
new float[nCount];
525 for (
int i = 0; i < nBatchSize; i++)
529 for (
int g = 0; g < rgAnnoGroups.
Count; g++)
533 for (
int a = 0; a < anno_group.
annotations.Count; a++)
538 rgTopLabel1[nIdx] = i;
544 rgTopLabel1[nIdx] = bbox.
xmin;
546 rgTopLabel1[nIdx] = bbox.
ymin;
548 rgTopLabel1[nIdx] = bbox.
xmax;
550 rgTopLabel1[nIdx] = bbox.
ymax;
552 rgTopLabel1[nIdx] = (bbox.
difficult) ? 1 : 0;
Defines a collection of AnnotationGroups.
int Count
Specifies the number of items in the collection.
The AnnoationGroup class manages a group of annotations.
int group_label
Get/set the group label.
List< Annotation > annotations
Get/set the group annoations.
The Annotation class is used by annotations attached to SimpleDatum's and used in SSD.
int instance_id
Get/set the instance ID.
NormalizedBBox bbox
Get/set the bounding box.
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
bool WaitOne(int nMs=int.MaxValue)
Waits for the signal state to occur.
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
METHOD
Defines the random number generation method to use.
int Next(int nMinVal, int nMaxVal, bool bMaxInclusive=true)
Returns a random int within the range
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void WriteError(Exception e)
Write an error as output.
void CHECK_GT(double df1, double df2, string str)
Test whether one number is greater than another.
The NormalizedBBox manages a bounding box used in SSD.
float ymax
Get/set the y maximum.
float xmax
Get/set the x maximum.
float xmin
Get/set the x minimum.
bool difficult
Get/set the difficulty.
float ymin
Get/set the y minimum.
The SimpleDatum class holds a data input within host memory.
ANNOTATION_TYPE
Specifies the annotation type when using annotations.
AnnotationGroupCollection annotation_group
When using annoations, each annotation group contains an annotation for a particular class used with ...
ANNOTATION_TYPE annotation_type
When using annotations, the annotation type specifies the type of annotation. Currently,...
The Utility class provides general utility funtions.
static List< int > Create(int nCount, int nStart, int nInc)
Create a new List and fill it with values starting with start and incrementing by inc.
The BlobCollection contains a list of Blobs.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
The SsdSampler is used by the SSD algorithm to sample BBoxes.
void Dispose()
Free all resources used.
List< NormalizedBBox > GenerateBatchSamples(SimpleDatum anno_datum, List< BatchSampler > rgBatchSamplers)
Generate samples from the annotated Datum using the list of BatchSamplers.
The Cursor is used to traverse through a given data source within the database.
A generic database class used to connect to the underlying database and create a Cursor that traverse...
bool m_bOutputLabels
Specifies whether or not the Layer should output labels.
DataTransformer< T > m_transformer
Specifies the DataTransformer used to transform each data item as it loaded.
The BasePrefetchingDataLayer is the base class for data Layers that pre-fetch data before feeding the...
CancelEvent m_evtCancel
Specifies the cancellation event for the internal thread.
Batch< T >[] m_rgPrefetch
Specifies the pre-fetch cache.
The Batch contains both the data and label Blobs of the batch.
Blob< T > Label
Returns the label Blob of the batch.
Blob< T > Data
Returns the data Blob of the batch.
Log m_log
Specifies the Log for output.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
void convert(BlobCollection< T > col)
Convert a collection of blobs from / to half size.
LayerParameter.LayerType m_type
Specifies the Layer type.
The AnnotatedDataLayer provides annotated data to the Net by assigning top Blobs directly....
SimpleDatum.ANNOTATION_TYPE m_AnnoType
Specifies the annotation type used if any.
void Next()
Retrieves the next item from the database and rolls the cursor over once the end of the dataset is re...
override void load_batch(Batch< T > batch)
Load a batch of data in the background (this is run on an internal thread within the BasePrefetchingD...
double m_dfTransTime
Specifies the transaction time.
override int MinTopBlobs
Specifies the minimum number of required top (output) Blobs: data
Cursor< T > m_cursor
Specifies the database used to traverse through the database.
override void DataLayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the DataLayer by starting up the pre-fetching.
Stopwatch m_swTimerTransaction
Specfies a second timer used to calculate the transaction time.
AnnotatedDataLayer(CudaDnn< T > cuda, Log log, LayerParameter p, IXDatabaseBase db, CancelEvent evtCancel)
The AnnotatedDataLayer constructor.
Stopwatch m_swTimerBatch
Specifies a first timer used to calcualte the batch time.
override void dispose()
Releases all GPU and host resources used by the Layer.
override int ExactNumBottomBlobs
No bottom blobs are used by this layer.
bool Skip()
Skip to the next value - used when training in a multi-GPU scenario.
DB< T > m_db
Specifies the database.
double m_dfReadTime
Specifies the read time.
Specifies the parameter for the data layer.
virtual uint batch_size
Specifies the batch size.
LABEL_TYPE label_type
(optional, default = SINGLE) Specifies the label type: SINGLE - the default which uses the 'Label' fi...
bool display_timing
(optional, default = false) Specifies whether or not to display the timing of each image read.
bool? enable_random_selection
(optional, default = null) Specifies whether or not to randomly query images from the data source....
bool? enable_pair_selection
(optional, default = null) Specifies whether or not to select images in a pair sequence....
string source
When used with the DATA parameter, specifies the data 'source' within the database....
LABEL_TYPE
Defines the label type.
Specifies the base parameter for all layers.
int solver_count
Returns the number of Solvers participating in a multi-GPU session for which the Solver using this La...
AnnotatedDataParameter annotated_data_param
Returns the parameter set when initialized with LayerType.ANNOTATED_DATA
int solver_rank
Returns the SolverRank of the Solver using this LayerParameter (if any).
TransformationParameter transform_param
Returns the parameter set when initialized with LayerType.TRANSFORM
DataParameter data_param
Returns the parameter set when initialized with LayerType.DATA
Phase phase
Specifies the Phase for which this LayerParameter is run.
LayerType
Specifies the layer type.
bool Active
When active, the parameter is used, otherwise it is ignored.
SimpleDatum.ANNOTATION_TYPE anno_type
Get/set the annotation type.
List< BatchSampler > batch_sampler
Get/set the batch sampler.
string label_map_file
Get/set the label map file.
Specifies a sample of batch of bboxes with provided constraints in SSD.
Specifies the parameters for the ResizeParameter for use with SSD.
ResizeMode
Defines the resizing mode.
ResizeMode resize_mode
Get/set the resizing mode.
The IXDatabaseBase interface defines the general interface to the in-memory database.
Tuple< DB_LABEL_SELECTION_METHOD, DB_ITEM_SELECTION_METHOD > GetSelectionMethod()
Returns the label and image selection method used.
void SetSelectionMethod(DB_LABEL_SELECTION_METHOD? lbl, DB_ITEM_SELECTION_METHOD? img)
Sets the label and image selection methods.
DB_VERSION GetVersion()
Returns the version of the MyCaffe Image Database being used.
The IXImageDatabaseBase interface defines the general interface to the in-memory image database.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
DB_ITEM_SELECTION_METHOD
Defines the item (e.g., image or temporal item) selection method.
Phase
Defines the Phase under which to run a Net.
DB_VERSION
Defines the image database version to use.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.data namespace contains dataset creators used to create common testing datasets such as M...
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe.layers.ssd namespace contains all Single-Shot MultiBox (SSD) related layers.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...