6using System.Collections.Generic;
9using System.Threading.Tasks;
35 m_blobWork =
new Blob<T>(cuda, log,
false);
44 if (m_blobWork !=
null)
58 List<NormalizedBBox> rgObjectBboxes =
new List<NormalizedBBox>();
61 return rgObjectBboxes;
67 for (
int j = 0; j < anno_group.
annotations.Count; j++)
70 rgObjectBboxes.Add(annotation.
bbox);
74 return rgObjectBboxes;
89 bool bSatisfy = !bHasJaccardOverlap && !bHasSampleCoverage && !bHasObjectCoverage;
97 for (
int i = 0; i < rgObjectBboxes.Count; i++)
102 if (bHasJaccardOverlap)
104 float fJaccardOverlap = m_util.
JaccardOverlap(sampledBBox, objectBbox);
116 if (bHasSampleCoverage)
118 float fSampleCoverage = m_util.
Coverage(sampledBBox, objectBbox);
130 if (bHasObjectCoverage)
132 float fObjectOverage = m_util.
Coverage(objectBbox, sampledBBox);
150 private float randomUniformValue(
float fMin,
float fMax)
152 fMin = (float)Math.Round(fMin, 5);
153 fMax = (float)Math.Round(fMax, 5);
155 m_log.CHECK_LE(fMin, fMax,
"The min mumst be <= the max!");
157 if (fMin == 0 && fMax == 0)
159 else if (fMin == 1 && fMax == 1)
164 float fRange = fMax - fMin;
166 return (
float)(dfRandom * fRange) + fMin;
173 m_log.CHECK_GE(sampler.
max_scale, sampler.
min_scale,
"The sampler max scale must be >= the min scale.");
174 m_log.CHECK_GT(sampler.
min_scale, 0,
"The sampler min scale must be > 0.");
175 m_log.CHECK_LE(sampler.
max_scale, 1,
"The sampler max scale must be <= 1.");
179 float fPow2Scale = (float)Math.Pow(fScale, 2.0);
181 fAspectRatio = (float)Math.Max(fAspectRatio, fPow2Scale);
182 fAspectRatio = (float)Math.Min(fAspectRatio, 1.0 / fPow2Scale);
183 float fSqrtAspectRatio = (float)Math.Sqrt(fAspectRatio);
186 float fBboxWidth = fScale * fSqrtAspectRatio;
187 float fBboxHeight = fScale / fSqrtAspectRatio;
190 float fWoff = randomUniformValue(0, 1.0f - fBboxWidth);
191 float fHoff = randomUniformValue(0, 1.0f - fBboxHeight);
193 return new NormalizedBBox(fWoff, fHoff, fWoff + fBboxWidth, fHoff + fBboxHeight);
205 List<NormalizedBBox> rgSampledBBoxes =
new List<NormalizedBBox>();
208 for (
int i = 0; i < batchSampler.
max_trials; i++)
217 sampledBbox = m_util.
Locate(sourceBBox, sampledBbox);
223 rgSampledBBoxes.Add(sampledBbox);
227 return rgSampledBBoxes;
238 List<NormalizedBBox> rgSampledBBoxes =
new List<NormalizedBBox>();
241 for (
int i = 0; i < rgBatchSamplers.Count; i++)
243 if (rgBatchSamplers[i].use_original_image)
246 rgSampledBBoxes.AddRange(
GenerateSamples(unitBbox, rgObjectBBoxes, rgBatchSamplers[i]));
250 return rgSampledBBoxes;
int Count
Specifies the number of items in the collection.
The AnnoationGroup class manages a group of annotations.
List< Annotation > annotations
Get/set the group annoations.
The Annotation class is used by annotations attached to SimpleDatum's and used in SSD.
NormalizedBBox bbox
Get/set the bounding box.
The CryptoRandom is a random number generator that can use either the standard .Net Random objec or t...
double NextDouble()
Returns a random double within the range .
The Log class provides general output in text form.
The NormalizedBBox manages a bounding box used in SSD.
The SimpleDatum class holds a data input within host memory.
AnnotationGroupCollection annotation_group
When using annoations, each annotation group contains an annotation for a particular class used with ...
The BBox class processes the NormalizedBBox data used with SSD.
float Coverage(NormalizedBBox bbox1, NormalizedBBox bbox2)
Compute the coverage of bbox1 by bbox2.
NormalizedBBox Locate(NormalizedBBox srcBbox, NormalizedBBox bbox)
Locate bbox in the coordinate system of the source Bbox.
float JaccardOverlap(NormalizedBBox bbox1, NormalizedBBox bbox2, bool bNormalized=true)
Calculates the Jaccard overlap between two bounding boxes.
The Blob is the main holder of data that moves through the Layers of the Net.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
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.
List< NormalizedBBox > GroupObjectBBoxes(SimpleDatum anno_datum)
Find all annotated NormalizedBBox.
SsdSampler(CudaDnn< T > cuda, Log log)
The constructor.
List< NormalizedBBox > GenerateSamples(NormalizedBBox sourceBBox, List< NormalizedBBox > rgObjectBboxes, BatchSampler batchSampler)
Generate samples from the NormalizedBBox using the BatchSampler.
bool SatisfySampleConstraint(NormalizedBBox sampledBBox, List< NormalizedBBox > rgObjectBboxes, SamplerConstraint sampleConstraint)
Check if the sampled bbox satisfies the constraints with all object 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.
Specifies a sample of batch of bboxes with provided constraints in SSD.
SamplerConstraint sample_constraint
Get/set the sample constraint.
Sampler sampler
Specifies the constraints for sampling the bbox
uint max_trials
Maximum number of trials for sampling to avoid an infinite loop.
uint max_sample
If provided (greater than zero), break when found certain number of samples satisfying the sample con...
Specifies the constratins for selecting sampled bbox used in SSD.
float? max_object_coverage
Get/set the maximum Object coverage between sampled bbox and all boxes in AnnotationGroup.
float? min_object_coverage
Get/set the minimum Object coverage between sampled bbox and all boxes in AnnotationGroup.
float? max_jaccard_overlap
Get/set the maximum Jaccard overlap between sampled bbox and all boxes in AnnotationGroup.
float? min_sample_coverage
Get/set the minimum Sample coverage between sampled bbox and all boxes in AnnotationGroup.
float? max_sample_coverage
Get/set the maximum Sample coverage between sampled bbox and all boxes in AnnotationGroup.
float? min_jaccard_overlap
Get/set the minimum Jaccard overlap between sampled bbox and all boxes in AnnotationGroup.
Specifies the sample of a bbox in the normalized space [0,1] with provided constraints used in SSD.
float max_scale
Get/set the maximum scale of the sampled bbox.
float max_aspect_ratio
Get/set the maximum aspect ratio of the sampled bbox.
float min_scale
Get/set the minimum scale of the sampled bbox.
float min_aspect_ratio
Get/set the minimum aspect ratio of the sampled bbox.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.fillers namespace contains all fillers including the Filler class.
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-...