2using System.Collections.Generic;
6using System.Threading.Tasks;
15 string m_strModelDescription;
16 string m_strSolverDescription =
null;
19 string m_strLastModelFileName =
"";
20 string m_strLastSolverFileName =
"";
21 string m_strLastImageMeanFileName =
"";
22 string m_strLastWeightsFileName =
"";
23 string m_strOriginalDownloadFile =
null;
24 List<int> m_rgInputShape =
new List<int>();
34 public MyCaffeModelData(
string strModelDesc,
byte[] rgWeights,
byte[] rgImageMean =
null,
string strSolverDescription =
null, List<int> rgInputShape =
null)
36 m_strModelDescription = strModelDesc;
37 m_rgWeights = rgWeights;
38 m_rgImageMean = rgImageMean;
39 m_strSolverDescription = strSolverDescription;
41 if (rgInputShape !=
null)
42 m_rgInputShape = rgInputShape;
50 get {
return m_rgInputShape; }
51 set { m_rgInputShape = value; }
59 get {
return m_strModelDescription; }
60 set { m_strModelDescription = value; }
68 get {
return m_strSolverDescription; }
69 set { m_strSolverDescription = value; }
77 get {
return m_rgWeights; }
85 get {
return m_rgImageMean; }
93 get {
return m_strOriginalDownloadFile; }
94 set { m_strOriginalDownloadFile = value; }
102 public void Save(
string strFolder,
string strName)
104 string strModel = strFolder.TrimEnd(
'\\') +
"\\" + strName +
"_model_desc.prototxt";
106 if (File.Exists(strModel))
107 File.Delete(strModel);
109 m_strLastModelFileName = strModel;
110 using (StreamWriter sr =
new StreamWriter(strModel))
112 sr.WriteLine(m_strModelDescription);
115 if (!
string.IsNullOrEmpty(m_strSolverDescription))
117 string strSolver = strFolder.TrimEnd(
'\\') +
"\\" + strName +
"_solver_desc.prototxt";
119 if (File.Exists(strSolver))
120 File.Delete(strSolver);
122 m_strLastSolverFileName = strSolver;
123 using (StreamWriter sr =
new StreamWriter(strSolver))
125 sr.WriteLine(strSolver);
129 if (m_rgWeights !=
null)
131 string strWts = strFolder.TrimEnd(
'\\') +
"\\" + strName +
"_weights.mycaffemodel";
133 if (File.Exists(strWts))
136 m_strLastWeightsFileName = strWts;
137 using (FileStream fs =
new FileStream(strWts, FileMode.CreateNew, FileAccess.Write))
138 using (BinaryWriter bw =
new BinaryWriter(fs))
140 bw.Write(m_rgWeights);
145 m_strLastWeightsFileName =
"";
148 if (m_rgImageMean !=
null)
150 string strWts = strFolder.TrimEnd(
'\\') +
"\\" + strName +
"_image_mean.bin";
152 if (File.Exists(strWts))
155 m_strLastImageMeanFileName = strWts;
156 using (FileStream fs =
new FileStream(strWts, FileMode.CreateNew, FileAccess.Write))
157 using (BinaryWriter bw =
new BinaryWriter(fs))
159 bw.Write(m_rgImageMean);
164 m_strLastImageMeanFileName =
"";
173 get {
return m_strLastModelFileName; }
181 get {
return m_strLastSolverFileName; }
189 get {
return m_strLastWeightsFileName; }
197 get {
return m_strLastImageMeanFileName; }
The MyCaffeModelData object contains the model descriptor, model weights and optionally the image mea...
string LastSavedModeDescriptionFileName
Returns the file name of the last saved model description file.
void Save(string strFolder, string strName)
Save the model data to the specified folder under the specified name.
MyCaffeModelData(string strModelDesc, byte[] rgWeights, byte[] rgImageMean=null, string strSolverDescription=null, List< int > rgInputShape=null)
The constructor.
byte[] Weights
Returns the model weights.
string SolverDescription
Get/set the solver description.
string LastSavedImageMeanFileName
Returns the file name of the last saved image mean file.
string OriginalDownloadFile
Specifies the original download file, if any.
byte[] ImageMean
Returns the image mean if one was specified, or null.
string LastSavedWeightsFileName
Returns the file name of the last saved weights file.
string LastSaveSolverDescriptionFileName
Returns the file name of the last saved solver description file.
List< int > InputShape
Get/set the data input shape.
string ModelDescription
Get/set the model descriptor.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.