MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
MgrPreprocessor.cs
1using MyCaffe.basecode;
2using MyCaffe.common;
3using MyCaffe.db.stream;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9
11{
16 public class MgrPreprocessor<T> : IDisposable
17 {
18 Extension<T> m_extension;
19 MyCaffeControl<T> m_mycaffe;
20 IXStreamDatabase m_idb;
21 Blob<T> m_blobInput = null;
22 Blob<T> m_blobOutput = null;
23
30 {
31 m_mycaffe = (MyCaffeControl<T>)imycaffe;
32 m_idb = idb;
33 m_extension = new Extension<T>(imycaffe as IXMyCaffeExtension<T>);
34 m_blobInput = new Blob<T>(m_mycaffe.Cuda, m_mycaffe.Log);
35 m_blobOutput = new Blob<T>(m_mycaffe.Cuda, m_mycaffe.Log);
36 }
37
41 public void Dispose()
42 {
43 if (m_blobInput != null)
44 {
45 m_blobInput.Dispose();
46 m_blobInput = null;
47 }
48
49 if (m_blobOutput != null)
50 {
51 m_blobOutput.Dispose();
52 m_blobOutput = null;
53 }
54 }
55
62 public void Initialize(string strExtPath, int nFields, int nDepth)
63 {
64 List<float> rgParam;
65
66 m_extension.Initialize(strExtPath);
67
68 rgParam = new List<float>();
69 rgParam.Add(nFields);
70 rgParam.Add(nDepth);
71 rgParam.Add(1); // call ProcessData after AddData within the pre-processor DLL.
72 float[] rgOut = m_extension.Run(Extension<T>.FUNCTION.INITIALIZE, rgParam.ToArray());
73 int nOutputFields = (int)rgOut[0];
74
75 m_blobInput.Reshape(1, 1, nFields, nDepth);
76 m_blobOutput.Reshape(1, 1, nOutputFields, nDepth);
77
78 rgParam = new List<float>();
79 rgParam.Add(m_blobInput.count());
80 rgParam.Add(m_blobInput.mutable_gpu_data);
81 rgParam.Add(m_blobInput.count());
82 rgParam.Add(m_blobInput.mutable_gpu_diff);
83 rgParam.Add(m_blobOutput.count());
84 rgParam.Add(m_blobOutput.mutable_gpu_data);
85 rgParam.Add(m_blobOutput.count());
86 rgParam.Add(m_blobOutput.mutable_gpu_diff);
87 m_extension.Run(Extension<T>.FUNCTION.SETMEMORY, rgParam.ToArray());
88 }
89
94 public void Reset(int nStartOffset)
95 {
96 m_idb.Reset(nStartOffset);
97 }
98
105 public Tuple<Blob<T>, SimpleDatum> Step(bool bGetSimpleDatum, int nWait)
106 {
107 SimpleDatum sd = m_idb.Query(nWait);
108 if (sd == null)
109 return null;
110
111 if (typeof(T) == typeof(float))
112 {
113 m_extension.Run(Extension<T>.FUNCTION.ADDDATA, sd.RealDataF);
114 }
115 else
116 {
117 m_extension.Run(Extension<T>.FUNCTION.ADDDATA, sd.RealDataD);
118 }
119
120 return new Tuple<Blob<T>, SimpleDatum>(m_blobOutput, null);
121 }
122 }
123}
The MyCaffeControl is the main object used to manage all training, testing and running of the MyCaffe...
Log Log
Returns the Log (for output) used.
CudaDnn< T > Cuda
Returns the CudaDnn connection used.
The SimpleDatum class holds a data input within host memory.
Definition: SimpleDatum.cs:161
float[] RealDataF
Return the float data. This field is valid when IsRealData = true.
double[] RealDataD
Return the double data. This field is valid when IsRealData = true.
The Blob is the main holder of data that moves through the Layers of the Net.
Definition: Blob.cs:25
long mutable_gpu_diff
Returns the diff GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1555
long mutable_gpu_data
Returns the data GPU handle used by the CudaDnn connection.
Definition: Blob.cs:1487
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
Definition: Blob.cs:442
int count()
Returns the total number of items in the Blob.
Definition: Blob.cs:739
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
Definition: Blob.cs:402
The Extension class is used to add new pre-processor extension DLL's to MyCaffe.
Definition: Extension.cs:15
The MgrPreprocessor manages the operations of the data pre-processor.
void Reset(int nStartOffset)
Reset the streaming database to the data start or an offset from the start.
void Dispose()
Release all resources used.
MgrPreprocessor(IXMyCaffe< T > imycaffe, IXStreamDatabase idb)
The constructor.
void Initialize(string strExtPath, int nFields, int nDepth)
Initialize the pre-processor.
Tuple< Blob< T >, SimpleDatum > Step(bool bGetSimpleDatum, int nWait)
Step to the next data in the streaming database and process it.
The IXMyCaffeExtension interface allows for easy extension management of the low-level software that ...
Definition: Interfaces.cs:614
The IXMyCaffe interface contains functions used to perform MyCaffe operations that work with the MyCa...
Definition: Interfaces.cs:410
The IXStreamDatabase interface is the main interface to the MyCaffe Streaing Database.
Definition: Interfaces.cs:52
void Reset(int nStartOffset=0)
Reset the query postion to the start established during Initialize.
SimpleDatum Query(int nWait=1000)
Query a setgment of data from the internal queueus.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.common namespace contains common MyCaffe classes.
Definition: BatchInput.cs:8
The MyCaffe.db.stream namespace contains all data streaming related classes.
The MyCaffe.preprocessor namespace contains all classes of the data preprocessors supported by MyCaff...
Definition: Extension.cs:9
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12