2using System.Collections.Generic;
17 List<Blob<T>> m_rgBlobs =
new List<Blob<T>>();
31 get {
return m_rgBlobs.Count; }
41 get {
return m_rgBlobs[nIdx]; }
42 set { m_rgBlobs[nIdx] = value; }
58 throw new Exception(
"Could not find the blob named '" + strName +
"' in the collection.");
69 for (
int i = 0; i < m_rgBlobs.Count; i++)
71 if (m_rgBlobs[i] !=
null && m_rgBlobs[i].Name == strName)
85 m_rgBlobs.Insert(nIdx, b);
119 return m_rgBlobs.Remove(b);
128 m_rgBlobs.RemoveAt(nIdx);
135 public void Clear(
bool bDispose =
false)
139 foreach (
Blob<T> b
in m_rgBlobs)
155 return m_rgBlobs.Contains(blob);
167 foreach (
Blob<T> b1
in m_rgBlobs)
169 if (b1 !=
null && b1.
Name.Contains(b.
Name))
182 return m_rgBlobs.GetEnumerator();
189 System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
191 return m_rgBlobs.GetEnumerator();
202 foreach (
Blob<T> b
in m_rgBlobs)
216 for (
int i = 0; i < m_rgBlobs.Count; i++)
218 m_rgBlobs[i].ReshapeLike(src[i]);
228 for (
int i = 0; i < m_rgBlobs.Count; i++)
230 m_rgBlobs[i].ReshapeLike(blob);
240 for (
int i = 0; i < m_rgBlobs.Count; i++)
242 m_rgBlobs[i].Reshape(rgShape);
253 public void Reshape(
int nN,
int nC,
int nH,
int nW)
255 for (
int i = 0; i < m_rgBlobs.Count; i++)
257 m_rgBlobs[i].Reshape(nN, nC, nH, nW);
269 throw new Exception(
"The source and destination should have the same count.");
271 for (
int i = 0; i < bSrc.
Count; i++)
273 m_rgBlobs[i].CopyFrom(bSrc[i], bCopyDiff,
true);
285 for (
int i = 0; i < src.
Count; i++)
289 int nSrcCount = bSrc.
count();
290 int nDstCount = bDst.
count();
292 if (nSrcCount != nDstCount)
293 throw new Exception(
"The src and dst blobs at index #" + i.ToString() +
" have different sizes!");
313 for (
int i = 0; i < m_rgBlobs.Count; i++)
315 m_rgBlobs[i].SetDiff(df);
325 for (
int i = 0; i < m_rgBlobs.Count; i++)
327 m_rgBlobs[i].SetData(df);
342 if (col.
Count != m_rgBlobs.Count)
343 throw new Exception(
"The input blob collection must have the same count at this blob collection!");
347 for (
int i = 0; i < m_rgBlobs.Count; i++)
349 if (i > 0 || !bSkipFirstItem)
368 if (colA.
Count != m_rgBlobs.Count)
369 throw new Exception(
"The input blob collection must have the same count at this blob collection!");
372 T fScale = (T)Convert.ChangeType(dfScale, typeof(T));
374 for (
int i = 0; i < m_rgBlobs.Count; i++)
376 if (i > 0 || !bSkipFirstItem)
377 colOut.
Add(m_rgBlobs[i].
MathAdd(colA[i], fScale));
392 T fVal = (T)Convert.ChangeType(dfVal, typeof(T));
394 for (
int i = 0; i < m_rgBlobs.Count; i++)
396 if (i > 0 || !bSkipFirstItem)
409 public void Save(BinaryWriter bw,
bool bData,
bool bDiff)
411 bw.Write(m_rgBlobs.Count);
413 foreach (
Blob<T> b
in m_rgBlobs)
415 b.
Save(bw, bData, bDiff);
431 int nCount = br.ReadInt32();
433 for (
int i = 0; i < nCount; i++)
449 public bool Share(
Blob<T> b, List<int> rgMinShape,
bool bThrowExceptions,
bool bAllowEndsWith =
false)
453 if (rgMinShape !=
null && rgMinShape.Count > 0)
455 nCount = rgMinShape[0];
456 for (
int i = 1; i < rgMinShape.Count; i++)
458 nCount *= rgMinShape[i];
462 foreach (
Blob<T> blobShare
in m_rgBlobs)
464 if (blobShare.
Name == b.
Name || (bAllowEndsWith && blobShare.
Name.EndsWith(b.
Name)))
468 if (blobShare.
count() < nCount)
470 if (bThrowExceptions)
471 throw new Exception(
"The blob to be shared is smaller that the expected minimum count!");
491 bool bRequested =
false;
493 foreach (
Blob<T> blob
in m_rgBlobs)
513 public Dictionary<string, Tuple<double, double, double, double>>
CollectMinMax(
Blob<T> blobWork,
bool bDiff =
false)
515 Dictionary<string, Tuple<double, double, double, double>> rgMinMax =
new Dictionary<string, Tuple<double, double, double, double>>();
516 Dictionary<string, int> rgDuplicates =
new Dictionary<string, int>();
518 foreach (
Blob<T> b
in m_rgBlobs)
520 Tuple<double, double, double, double> minmax = bDiff ? b.
minmax_diff(blobWork,
true) : b.
minmax_data(blobWork,
true);
521 string strName = b.
Name;
523 if (rgMinMax.ContainsKey(strName))
525 if (!rgDuplicates.ContainsKey(strName))
526 rgDuplicates.Add(strName, 1);
528 rgDuplicates[strName]++;
530 strName = b.
Name +
"_DUPLICATE_NAME_" + rgDuplicates[strName].ToString();
533 rgMinMax.Add(strName, minmax);
544 foreach (
Blob<T> b
in m_rgBlobs)
The Log class provides general output in text form.
The BlobCollection contains a list of Blobs.
BlobCollection()
The BlobCollection constructor.
void Dispose()
Release all resource used by the collection and its Blobs.
BlobCollection< T > MathSub(BlobCollection< T > col, bool bSkipFirstItem)
Create a new collection of cloned Blobs created by calling MathSub to subtract the Blobs in this coll...
void Add(Blob< T > b)
Add a new Blob to the collection.
void Accumulate(CudaDnn< T > cuda, BlobCollection< T > src, bool bAccumulateDiff)
Accumulate the diffs from one BlobCollection into another.
void SetData(double df)
Set all blob data to the value specified.
void SetDiff(double df)
Set all blob diff to the value specified.
bool Contains(Blob< T > blob)
Returns whether or not the collection contains a given blob.
BlobCollection< T > FindRelatedBlobs(Blob< T > b)
Find all Blobs in the collection that contain (in part or in whole) the name of a given Blob.
Dictionary< string, Tuple< double, double, double, double > > CollectMinMax(Blob< T > blobWork, bool bDiff=false)
Collect all min/max, inf and nan values from all Blobs in the collection.
BlobCollection< T > Clone()
Copy the collection and return it as a new collection.
bool SnapshotRequested(bool bReset)
Returns whether or not any blobs have a snapshot request set to true.
int Count
Returns the number of items in the collection.
void Clear(bool bDispose=false)
Remove all items from the collection.
bool Remove(Blob< T > b)
If it exists, remove a Blob from the collection.
void Insert(int nIdx, Blob< T > b)
Insert a blob at the given index.
Blob< T > FindBlob(string strName)
Finds a given blob in the collection based on its name.
bool Share(Blob< T > b, List< int > rgMinShape, bool bThrowExceptions, bool bAllowEndsWith=false)
Share the first Blob found with the same name as the given Blob.
void ReshapeLike(BlobCollection< T > src)
Reshapes all blobs in the collection to the sizes of the source.
void Save(BinaryWriter bw, bool bData, bool bDiff)
Save the collection to a binary writer.
void ReshapeLike(Blob< T > blob)
Reshapes all blobs in the collection to the sizes of the source.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
BlobCollection< T > MathAdd(BlobCollection< T > colA, double dfScale, bool bSkipFirstItem)
Create a new collection of cloned Blobs created by calling MathAdd to add the Blobs in this collectio...
BlobCollection< T > MathDiv(double dfVal, bool bSkipFirstItem)
Create a new collection of cloned Blobs created by calling MathDif to divide the Blobs in this collec...
IEnumerator< Blob< T > > GetEnumerator()
Get the enumerator for the collection.
void RemoveAt(int nIdx)
Remove a Blob at a given index in the collection.
void CopyFrom(BlobCollection< T > bSrc, bool bCopyDiff=false)
Copy the data or diff from another BlobCollection into this one.
void Reshape(int nN, int nC, int nH, int nW)
Reshapes all blobs in the collection to the given shape.
static BlobCollection< T > Load(CudaDnn< T > cuda, Log log, BinaryReader br, bool bData, bool bDiff)
Loads a new collection from a binary reader.
void Add(BlobCollection< T > rg)
Add another BlobCollection to this one.
The Blob is the main holder of data that moves through the Layers of the Net.
Tuple< double, double, double, double > minmax_data(Blob< T > work, bool bDetectNans=false, bool bUseChunks=false)
Returns the minimum and maximum values in the data of the Blob.
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
long mutable_gpu_data
Returns the data GPU handle used by the CudaDnn connection.
void Share(Blob< T > b)
Share another Blob with this one, by setting the data and diff to the same data and diff of the other...
Blob< T > Clone()
Copies the Blob, including its data and diff.
bool DiffExists
Returns whether or not the Diff portion exists.
Tuple< double, double, double, double > minmax_diff(Blob< T > work, bool bDetectNans=false, bool bUseChunks=false)
Returns the minimum and maximum values in the diff of the Blob.
void Save(BinaryWriter bw, bool bData, bool bDiff, bool bIncludeName=true)
Saves this Blob to a binary stream.
int count()
Returns the total number of items in the Blob.
string Name
Get/set the name of the Blob.
long gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
bool snapshot_requested
Get/set the snapshot request.
long gpu_data
Returns the data GPU handle used by the CudaDnn connection.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
void add(int n, long hA, long hB, long hC, long hY)
Adds A, B and C and places the result in Y.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...