MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
ProjectEx.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.IO;
7
8namespace MyCaffe.basecode
9{
14 public class ProjectEx
15 {
16 ProjectDescriptor m_project;
17 StateDescriptor m_state;
18 RawProto m_protoModel = null;
19 RawProto m_protoSolver = null;
20 bool m_bExistTest = false;
21 bool m_bExistTrain = false;
22 bool m_bDatasetAdjusted = false;
23 bool m_bDefaultSaveImagesToFile = true;
24 Stage m_stage = Stage.NONE;
25 int m_nOriginalProjectID = 0;
26
30 public event EventHandler<OverrideProjectArgs> OnOverrideModel;
34 public event EventHandler<OverrideProjectArgs> OnOverrideSolver;
35
41 public ProjectEx(string strName, string strDsName = null)
42 {
43 m_project = new ProjectDescriptor(strName);
44 m_project.Dataset = new descriptors.DatasetDescriptor(strDsName);
45 m_state = new StateDescriptor(0, strName + " results", m_project.Owner);
46 }
47
57 public ProjectEx(ProjectDescriptor prj, StateDescriptor state = null, bool bExistTrain = false, bool bExistTest = false, bool bQueryModel = true, bool bQuerySolver = true)
58 {
59 m_project = prj;
60
61 if (state == null)
62 state = new StateDescriptor(0, prj.Name + " results", m_project.Owner);
63
64 m_state = state;
65
66 if (bQueryModel)
68 else
69 m_project.ModelName = getModelName(prj.ModelDescription);
70
71 if (bQuerySolver)
73 else
74 m_project.SolverName = getSolverType(prj.SolverDescription);
75
76 m_bExistTest = bExistTest;
77 m_bExistTrain = bExistTrain;
78 }
79
85 {
86 RawProtoCollection col = m_protoModel.FindChildren("layer");
87 foreach (RawProto layer in col)
88 {
89 RawProto type = layer.FindChild("type");
90 if (type.Value.ToLower() == "annotateddata")
91 return true;
92 }
93
94 return false;
95 }
96
97 private string parse(string str, string strTarget, string strDefault = "UNKNOWN")
98 {
99 if (str == null)
100 return strDefault;
101
102 int nPos1 = 0;
103
104 while (nPos1 < str.Length)
105 {
106 nPos1 = str.IndexOf(strTarget, nPos1);
107 if (nPos1 < 0)
108 return strDefault;
109
110 if (nPos1 == 0 || char.IsWhiteSpace(str[nPos1 - 1]) || str[nPos1 - 1] == '\n' || str[nPos1 - 1] == '\r')
111 break;
112
113 nPos1++;
114 }
115
116 if (nPos1 >= str.Length)
117 return strDefault;
118
119 nPos1 += strTarget.Length;
120
121 while (nPos1 < str.Length && (char.IsWhiteSpace(str[nPos1]) || str[nPos1] == '\"'))
122 {
123 nPos1++;
124 }
125
126 string strName;
127
128 int nPos2 = str.IndexOfAny(new char[] { ' ', '\n', '\r', '\"', '\t' }, nPos1);
129 if (nPos2 < 0)
130 strName = str.Substring(nPos1);
131 else
132 strName = str.Substring(nPos1, nPos2 - nPos1).Trim(' ', '\"');
133
134 return strName;
135 }
136
137 private string getModelName(string strDesc)
138 {
139 string strName = parse(strDesc, "name:");
140 return strName;
141 }
142
143 private string getSolverType(string strDesc)
144 {
145 string strName = parse(strDesc, "type:", "SGD");
146 return strName;
147 }
148
149 private void setDatasetFromProto(RawProto proto)
150 {
151 RawProtoCollection col = proto.FindChildren("layer");
152 string strSrcTest = null;
153 string strSrcTrain = null;
154 string strSrcTest2 = null;
155 string strSrcTrain2 = null;
156
157 foreach (RawProto rp in col)
158 {
159 RawProto protoType = rp.FindChild("type");
160 if (protoType != null && protoType.Value == "Data")
161 {
162 RawProto protoParam = rp.FindChild("data_param");
163 if (protoParam != null)
164 {
165 bool bPrimary = true;
166
167 RawProto protoPrimary = protoParam.FindChild("primary_data");
168 if (protoPrimary != null)
169 bPrimary = bool.Parse(protoPrimary.Value);
170
171 RawProto protoSrc = protoParam.FindChild("source");
172 if (protoSrc != null)
173 {
174 RawProto protoInclude = rp.FindChild("include");
175 if (protoInclude != null)
176 {
177 RawProto protoPhase = protoInclude.FindChild("phase");
178 if (protoPhase != null)
179 {
180 if (bPrimary)
181 {
182 if (protoPhase.Value == "TRAIN")
183 strSrcTrain = protoSrc.Value;
184 else if (protoPhase.Value == "TEST")
185 strSrcTest = protoSrc.Value;
186 }
187 else
188 {
189 if (protoPhase.Value == "TRAIN")
190 strSrcTrain2 = protoSrc.Value;
191 else if (protoPhase.Value == "TEST")
192 strSrcTest2 = protoSrc.Value;
193 }
194 }
195 }
196 }
197 }
198 }
199 }
200
201 if (strSrcTest != null)
202 {
203 bool bSaveImagesToFile = (m_project.Dataset.TestingSource != null) ? m_project.Dataset.TestingSource.SaveImagesToFile : m_bDefaultSaveImagesToFile;
204 m_project.Dataset.TestingSource = new SourceDescriptor(strSrcTest, bSaveImagesToFile);
205 }
206
207 if (strSrcTrain != null)
208 {
209 bool bSaveImagesToFile = (m_project.Dataset.TrainingSource != null) ? m_project.Dataset.TrainingSource.SaveImagesToFile : m_bDefaultSaveImagesToFile;
210 m_project.Dataset.TrainingSource = new SourceDescriptor(strSrcTrain, bSaveImagesToFile);
211 }
212
213 if (strSrcTest2 != null || strSrcTrain2 != null)
214 {
215 if (m_project.DatasetTarget == null)
216 m_project.DatasetTarget = new DatasetDescriptor(m_project.Dataset.Name + "_tgt");
217
218 if (strSrcTest2 != null)
219 {
220 bool bSaveImagesToFile = (m_project.DatasetTarget.TestingSource != null) ? m_project.DatasetTarget.TestingSource.SaveImagesToFile : m_bDefaultSaveImagesToFile;
221 m_project.Dataset.TestingSource = new SourceDescriptor(strSrcTest2, bSaveImagesToFile);
222 }
223
224 if (strSrcTrain2 != null)
225 {
226 bool bSaveImagesToFile = (m_project.DatasetTarget.TrainingSource != null) ? m_project.DatasetTarget.TrainingSource.SaveImagesToFile : m_bDefaultSaveImagesToFile;
227 m_project.Dataset.TrainingSource = new SourceDescriptor(strSrcTrain2, bSaveImagesToFile);
228 }
229 }
230 }
231
232 private void setDatasetToProto(RawProto proto)
233 {
234 RawProtoCollection col = proto.FindChildren("layer");
235 string strSrcTest = m_project.Dataset.TestingSourceName;
236 string strSrcTrain = m_project.Dataset.TrainingSourceName;
237 string strSrcTest2 = (m_project.DatasetTarget != null) ? m_project.DatasetTarget.TestingSourceName : null;
238 string strSrcTrain2 = (m_project.DatasetTarget != null ) ? m_project.DatasetTarget.TrainingSourceName : null;
239
240 foreach (RawProto rp in col)
241 {
242 RawProto protoType = rp.FindChild("type");
243 if (protoType != null && (protoType.Value == "Data" || protoType.Value == "AnnotatedData"))
244 {
245 RawProto protoParam = rp.FindChild("data_param");
246 if (protoParam != null)
247 {
248 bool bPrimary = true;
249
250 RawProto protoPrimary = protoParam.FindChild("primary_data");
251 if (protoPrimary != null)
252 bPrimary = bool.Parse(protoPrimary.Value);
253
254 RawProto protoSrc = protoParam.FindChild("source");
255 if (protoSrc != null)
256 {
257 RawProto protoInclude = rp.FindChild("include");
258 if (protoInclude != null)
259 {
260 RawProto protoPhase = protoInclude.FindChild("phase");
261 if (protoPhase != null)
262 {
263 if (bPrimary)
264 {
265 if (protoPhase.Value == "TRAIN")
266 {
267 if (strSrcTrain != null)
268 protoSrc.Value = strSrcTrain;
269 }
270 else if (protoPhase.Value == "TEST")
271 {
272 if (strSrcTest != null)
273 protoSrc.Value = strSrcTest;
274 }
275 }
276 else
277 {
278 if (protoPhase.Value == "TRAIN")
279 {
280 if (strSrcTrain2 != null)
281 protoSrc.Value = strSrcTrain2;
282 }
283 else if (protoPhase.Value == "TEST")
284 {
285 if (strSrcTest2 != null)
286 protoSrc.Value = strSrcTest2;
287 }
288 }
289 }
290 }
291 }
292 }
293 }
294 }
295 }
296
300 public bool DatasetAdjusted
301 {
302 get { return m_bDatasetAdjusted; }
303 set { m_bDatasetAdjusted = value; }
304 }
305
312 public string GetCustomTrainer(out string strProperties)
313 {
314 if (m_protoSolver == null)
316
317 strProperties = "";
318
319 RawProto rp = m_protoSolver.FindChild("custom_trainer");
320 if (rp == null)
321 return null;
322
323 if (rp.Value == null || rp.Value.Length == 0)
324 return null;
325
326 RawProto rprop = m_protoSolver.FindChild("custom_trainer_properties");
327 if (rprop != null)
328 strProperties = rprop.Value;
329
330 return rp.Value;
331 }
332
333 private Phase getPhase(RawProto rp)
334 {
335 RawProto rpInc = rp.FindChild("include");
336 if (rpInc == null)
337 return Phase.NONE;
338
339 RawProto rpPhase = rpInc.FindChild("phase");
340 if (rpPhase == null)
341 return Phase.NONE;
342
343 string strPhase = rpPhase.Value.ToUpper();
344
345 if (strPhase == Phase.TEST.ToString())
346 return Phase.TEST;
347
348 if (strPhase == Phase.TRAIN.ToString())
349 return Phase.TRAIN;
350
351 return Phase.NONE;
352 }
353
359 public int GetBatchSize(Phase phase)
360 {
361 if (m_protoModel == null)
363
364 RawProtoCollection col = m_protoModel.FindChildren("layer");
365
366 foreach (RawProto rp1 in col)
367 {
368 Phase p = getPhase(rp1);
369
370 if (p == phase || phase == Phase.NONE)
371 {
372 RawProto rp = rp1.FindChild("batch_data_param");
373
374 if (rp == null)
375 rp = rp1.FindChild("data_param");
376
377 if (rp == null)
378 rp = rp1.FindChild("memory_data_param");
379
380 if (rp != null)
381 {
382 rp = rp.FindChild("batch_size");
383
384 if (rp == null)
385 return 0;
386
387 return int.Parse(rp.Value);
388 }
389 }
390 }
391
392 return 0;
393 }
394
402 public double? GetLayerSetting(Phase phase, string strLayer, string strParam)
403 {
404 string strVal = GetLayerSettingEx(phase, strLayer, strParam);
405 if (string.IsNullOrEmpty(strVal))
406 return null;
407
408 return BaseParameter.ParseDouble(strVal);
409 }
410
418 public string GetLayerSettingEx(Phase phase, string strLayer, string strParam)
419 {
420 if (m_protoModel == null)
422
423 RawProtoCollection col = m_protoModel.FindChildren("layer");
424
425 foreach (RawProto rp1 in col)
426 {
427 Phase p = getPhase(rp1);
428
429 if (p == phase || phase == Phase.NONE)
430 {
431 RawProto rp = rp1.FindChild(strLayer);
432
433 if (rp != null)
434 {
435 rp = rp.FindChild(strParam);
436
437 if (rp == null)
438 return null;
439
440 return rp.Value;
441 }
442 }
443 }
444
445 return null;
446 }
447
453 public string GetSolverSetting(string strParam)
454 {
455 if (m_protoSolver == null)
457
458 RawProto proto = m_protoSolver.FindChild(strParam);
459 if (proto == null)
460 return null;
461
462 return proto.Value;
463 }
464
470 public double? GetSolverSettingAsNumeric(string strParam)
471 {
472 string strVal = GetSolverSetting(strParam);
473 if (strVal == null)
474 return null;
475
476 double dfVal;
477 if (!BaseParameter.TryParse(strVal, out dfVal))
478 return null;
479
480 return dfVal;
481 }
482
488 public int? GetSolverSettingAsInt(string strParam)
489 {
490 double? dfVal = GetSolverSettingAsNumeric(strParam);
491 if (!dfVal.HasValue)
492 return null;
493
494 return (int)dfVal.Value;
495 }
496
502 public bool? GetSolverSettingAsBool(string strParam)
503 {
504 string strVal = GetSolverSetting(strParam);
505 if (strVal == null)
506 return null;
507
508 return bool.Parse(strVal);
509 }
510
515 {
516 get { return m_project.Settings; }
517 set { m_project.Settings = value; }
518 }
519
523 public string Name
524 {
525 get { return m_project.Name; }
526 set { m_project.Name = value; }
527 }
528
532 public int ID
533 {
534 get { return m_project.ID; }
535 }
536
540 public int OriginalID
541 {
542 get
543 {
544 if (m_nOriginalProjectID > 0)
545 return m_nOriginalProjectID;
546
547 return ID;
548 }
549 set
550 {
551 m_nOriginalProjectID = value;
552 }
553 }
554
558 public string Owner
559 {
560 get { return m_project.Owner; }
561 set { m_project.Owner = value; }
562 }
563
567 public bool Active
568 {
569 get { return m_project.Active; }
570 }
571
576 {
577 get
578 {
579 if (m_protoSolver == null)
580 return TRAINING_CATEGORY.NONE;
581
582 string strCustomTrainer = GetSolverSetting("custom_trainer");
583 if (string.IsNullOrEmpty(strCustomTrainer))
584 return TRAINING_CATEGORY.NONE;
585
586 if (strCustomTrainer == "RL.Trainer")
587 return TRAINING_CATEGORY.REINFORCEMENT;
588
589 if (strCustomTrainer == "RNN.Trainer")
590 return TRAINING_CATEGORY.RECURRENT;
591
592 if (strCustomTrainer == "Dual.Trainer")
593 return TRAINING_CATEGORY.DUAL;
594
595 return TRAINING_CATEGORY.CUSTOM;
596 }
597 }
598
603 {
604 get { return m_stage; }
605 set { m_stage = value; }
606 }
607
612 {
613 get { return (double)m_project.Settings.SuperBoostProbability; }
614 set { m_project.Settings.SuperBoostProbability = value; }
615 }
616
621 {
622 get { return m_project.Parameters.Find("UseTrainingSourceForTesting", false); }
623 }
624
630 {
631 get { return m_project.Settings.EnableLabelBalancing; }
632 }
633
639 {
640 get { return m_project.Settings.EnableLabelBoosting; }
641 }
642
648 {
649 get { return m_project.Settings.EnableRandomInputSelection; }
650 }
651
658 {
659 get { return m_project.Settings.EnablePairInputSelection; }
660 }
661
665 public string GpuOverride
666 {
667 get { return m_project.GpuOverride; }
668 }
669
675 {
676 get { return m_project.Settings.DbLoadMethod; }
677 }
678
682 public int ImageLoadLimit
683 {
684 get { return m_project.Settings.DbLoadLimit; }
685 }
686
691 {
692 get { return m_project.Settings.DbAutoRefreshScheduledUpdateInMs; }
693 }
694
699 {
700 get { return m_project.Settings.DbAutoRefreshScheduledReplacementPercent; }
701 }
702
710 {
711 get { return m_project.Settings.SnapshotWeightUpdateMethod; }
712 }
713
718 {
719 get { return m_project.Settings.SnapshotLoadMethod; }
720 }
721
725 public string SolverDescription
726 {
727 get { return (m_protoSolver == null) ? null : m_protoSolver.ToString(); }
728 set
729 {
730 m_project.SolverName = getSolverType(value);
731 m_project.SolverDescription = value;
732 m_protoSolver = null;
733
734 if (value != null && value.Length > 0)
735 {
736 m_protoSolver = RawProto.Parse(value);
737
738 if (m_project.Dataset != null)
739 {
740 if (string.IsNullOrEmpty(m_project.Dataset.Name))
741 setDatasetFromProto(m_protoSolver);
742 else
743 setDatasetToProto(m_protoSolver);
744 }
745
746 RawProto rpType = m_protoSolver.FindChild("type");
747 if (rpType != null)
748 m_project.SolverName = rpType.Value;
749 }
750 }
751 }
752
756 public string ModelDescription
757 {
758 get { return (m_protoModel == null) ? null : m_protoModel.ToString(); }
759 set
760 {
761 m_project.ModelName = getModelName(value);
762 m_project.ModelDescription = value;
763 m_protoModel = null;
764
765 if (value != null && value.Length > 0)
766 {
767 m_protoModel = RawProto.Parse(value);
768
769 if (m_project.Dataset != null)
770 {
771 if (string.IsNullOrEmpty(m_project.Dataset.Name))
772 setDatasetFromProto(m_protoModel);
773 else
774 setDatasetToProto(m_protoModel);
775 }
776
777 RawProto rpName = m_protoModel.FindChild("name");
778 if (rpName != null)
779 m_project.ModelName = rpName.Value;
780 }
781 }
782 }
783
788 {
789 get { return m_project.Group; }
790 }
791
796 {
797 get { return m_project.Dataset.ModelGroup; }
798 }
799
804 {
805 get { return m_project.Dataset.DatasetGroup; }
806 }
807
812 {
813 get { return m_project.Parameters; }
814 }
815
820 {
821 get { return m_project.TotalIterations; }
822 set { m_project.TotalIterations = value; }
823 }
824
828 public bool HasResults
829 {
830 get { return m_state.HasResults; }
831 }
832
836 public int Iterations
837 {
838 get { return m_state.Iterations; }
839 set { m_state.Iterations = value; }
840 }
841
845 public double BestAccuracy
846 {
847 get { return m_state.Accuracy; }
848 set { m_state.Accuracy = value; }
849 }
850
854 public double BestError
855 {
856 get { return m_state.Error; }
857 set { m_state.Error = value; }
858 }
859
863 public byte[] SolverState
864 {
865 get { return m_state.State; }
866 set { m_state.State = value; }
867 }
868
872 public byte[] WeightsState
873 {
874 get { return m_state.Weights; }
875 set { m_state.Weights = value; }
876 }
877
881 public string DatasetName
882 {
883 get
884 {
885 if (m_project.Dataset != null)
886 return m_project.Dataset.Name;
887
888 return null;
889 }
890 }
891
896 {
897 get { return m_project.Dataset; }
898 }
899
907 {
908 get { return m_project.DatasetTarget; }
909 }
910
915 {
916 get
917 {
918 ParameterDescriptor p = m_project.Parameters.Find("TargetDatasetID");
919 if (p == null)
920 return 0;
921
922 int nID;
923 if (!int.TryParse(p.Value, out nID))
924 return 0;
925
926 return nID;
927 }
928
929 set
930 {
931 ParameterDescriptor p = m_project.Parameters.Find("TargetDatasetID");
932 if (p == null)
933 m_project.Parameters.Add(new ParameterDescriptor(0, "TargetDatasetID", value.ToString()));
934 else
935 p.Value = value.ToString();
936 }
937 }
938
943 {
944 get { return m_bExistTest; }
945 }
946
951 {
952 get { return m_bExistTrain; }
953 }
954
959 {
960 get { return m_project.AnalysisItems; }
961 }
962
966 public string ModelName
967 {
968 get { return m_project.ModelName; }
969 }
970
974 public string SolverType
975 {
976 get { return m_project.SolverName; }
977 }
978
985 public bool SetSolverVariable(string strVar, string strVal)
986 {
987 if (m_protoSolver != null)
988 {
989 RawProto protoVar = m_protoSolver.FindChild(strVar);
990
991 if (protoVar != null)
992 protoVar.Value = strVal;
993 else
994 m_protoSolver.Children.Add(new RawProto(strVar, strVal));
995
996 m_project.SolverDescription = m_protoSolver.ToString();
997
998 return true;
999 }
1000
1001 return false;
1002 }
1003
1008 public void LoadSolverFile(string strFile)
1009 {
1010 using (StreamReader sr = new StreamReader(strFile))
1011 {
1012 SolverDescription = sr.ReadToEnd();
1013 }
1014 }
1015
1020 public void LoadModelFile(string strFile)
1021 {
1022 using (StreamReader sr = new StreamReader(strFile))
1023 {
1024 ModelDescription = sr.ReadToEnd();
1025 }
1026 }
1027
1041 public RawProto CreateModelForRunning(string strName, int nNum, int nChannels, int nHeight, int nWidth, out RawProto protoTransform, out bool bSkipTransformParam, Stage stage = Stage.NONE, bool bSkipLossLayer = false)
1042 {
1043 return CreateModelForRunning(m_project.ModelDescription, strName, nNum, nChannels, nHeight, nWidth, out protoTransform, out bSkipTransformParam, stage, bSkipLossLayer);
1044 }
1045
1053 public static RawProto CreateModelForTraining(string strModelDescription, string strName, bool bCaffeFormat = false)
1054 {
1055 RawProto proto = RawProto.Parse(strModelDescription);
1056
1057 string strLayers = "layer";
1058 RawProtoCollection rgLayers = proto.FindChildren("layer");
1059 if (rgLayers.Count == 0)
1060 {
1061 rgLayers = proto.FindChildren("layers");
1062 strLayers = "layers";
1063 }
1064
1065 bool bDirty = false;
1066 RawProtoCollection rgRemove = new RawProtoCollection();
1067 RawProto protoSoftmax = null;
1068 RawProto protoName = proto.FindChild("name");
1069 int nTrainDataLayerIdx = -1;
1070 int nTestDataLayerIdx = -1;
1071 int nSoftmaxLossLayerIdx = -1;
1072 int nAccuracyLayerIdx = -1;
1073 int nIdx = 0;
1074
1075 foreach (RawProto layer in rgLayers)
1076 {
1077 bool bRemove = false;
1078 RawProto type = layer.FindChild("type");
1079 RawProto include = layer.FindChild("include");
1080 RawProto exclude = layer.FindChild("exclude");
1081
1082 string strType = type.Value.ToLower();
1083
1084 if (strType == "softmax")
1085 protoSoftmax = layer;
1086
1087 if (include != null)
1088 {
1089 RawProto phase = include.FindChild("phase");
1090 if (phase != null)
1091 {
1092 if (phase.Value != "TEST" && phase.Value != "TRAIN")
1093 bRemove = true;
1094 else
1095 {
1096 if (strType == "data" || strType == "tokenizeddata")
1097 {
1098 if (phase.Value == "TRAIN")
1099 nTrainDataLayerIdx = nIdx;
1100 else
1101 nTestDataLayerIdx = nIdx;
1102 }
1103 else if (strType == "accuracy")
1104 {
1105 nAccuracyLayerIdx = nIdx;
1106 }
1107 else if (strType == "softmaxwithloss")
1108 {
1109 nSoftmaxLossLayerIdx = nIdx;
1110 }
1111 }
1112 }
1113 }
1114
1115 if (!bRemove && exclude != null)
1116 {
1117 RawProto phase = exclude.FindChild("phase");
1118 if (phase != null)
1119 {
1120 if (phase.Value == "TEST" || phase.Value == "TRAIN")
1121 bRemove = true;
1122 }
1123 }
1124
1125 if (bRemove)
1126 {
1127 rgRemove.Add(layer);
1128 }
1129
1130 nIdx++;
1131 }
1132
1133 if (nTestDataLayerIdx < 0)
1134 {
1135 string strProto = getDataLayerProto(strLayers, strName, bCaffeFormat, 16, "", Phase.TEST);
1136 RawProto protoData = RawProto.Parse(strProto).Children[0];
1137
1138 if (nTrainDataLayerIdx > 0)
1139 rgLayers.Insert(nTrainDataLayerIdx + 1, protoData);
1140 else
1141 rgLayers.Insert(0, protoData);
1142
1143 bDirty = true;
1144 }
1145
1146 if (nTrainDataLayerIdx < 0)
1147 {
1148 string strProto = getDataLayerProto(strLayers, strName, bCaffeFormat, 16, "", Phase.TRAIN);
1149 RawProto protoData = RawProto.Parse(strProto).Children[0];
1150 rgLayers.Insert(0, protoData);
1151 bDirty = true;
1152 }
1153
1154 foreach (RawProto layer in rgRemove)
1155 {
1156 proto.RemoveChild(layer);
1157 }
1158
1159 if (protoSoftmax != null)
1160 {
1161 RawProto type = protoSoftmax.FindChild("type");
1162 if (type != null)
1163 type.Value = "SoftmaxWithLoss";
1164
1165 protoSoftmax.Children.Add(new RawProto("bottom", "label"));
1166 protoSoftmax.Children.Add(new RawProto("loss_weight", "1", null, RawProto.TYPE.NUMERIC));
1167
1168 string strInclude = "include { phase: TRAIN }";
1169 protoSoftmax.Children.Add(RawProto.Parse(strInclude).Children[0]);
1170
1171 string strLoss = "loss_param { normalization: VALID }";
1172 protoSoftmax.Children.Add(RawProto.Parse(strLoss).Children[0]);
1173 bDirty = true;
1174 }
1175
1176 if (nAccuracyLayerIdx < 0)
1177 {
1178 string strBottom = null;
1179 if (rgLayers.Count > 0)
1180 {
1181 RawProto last = rgLayers[rgLayers.Count - 1];
1182 RawProtoCollection colBtm = last.FindChildren("bottom");
1183
1184 if (colBtm.Count > 0)
1185 strBottom = colBtm[0].Value;
1186 }
1187
1188 if (strBottom != null)
1189 {
1190 string strProto = getAccuracyLayerProto(strLayers, strBottom);
1191 RawProto protoData = RawProto.Parse(strProto).Children[0];
1192 rgLayers.Add(protoData);
1193 bDirty = true;
1194 }
1195 }
1196
1197 if (bDirty || proto.FindChildren("input_dim").Count > 0)
1198 {
1199 rgLayers.Insert(0, protoName);
1200 proto = new RawProto("root", null, rgLayers);
1201 }
1202
1203 return proto;
1204 }
1205
1206 private static string getDataLayerProto(string strLayer, string strName, bool bCaffeFormat, int nBatchSize, string strSrc, Phase phase)
1207 {
1208 string strRgb = (bCaffeFormat) ? "BGR" : "RGB";
1209 string strPhase = phase.ToString();
1210 return strLayer + " { name: \"" + strName + "\" type: \"Data\" top: \"data\" top: \"label\" include { phase: " + strPhase + " } transform_param { scale: 1 mirror: True use_imagedb_mean: True color_order: " + strRgb + " } data_param { source: \"" + strSrc + "\" batch_size: " + nBatchSize.ToString() + " backend: IMAGEDB enable_random_selection: True } }";
1211 }
1212
1213 private static string getAccuracyLayerProto(string strLayer, string strBottom)
1214 {
1215 return strLayer + " { name: \"accuracy\" type: \"Accuracy\" bottom: \"" + strBottom + "\" bottom: \"label\" top: \"accuracy\" include { phase: TEST } accuracy_param { top_k: 1 } }";
1216 }
1217
1218 private static PhaseStageCollection getPhases(RawProto proto, string strType)
1219 {
1220 PhaseStageCollection psCol = new PhaseStageCollection();
1221
1222 RawProtoCollection type = proto.FindChildren(strType);
1223 if (type == null || type.Count == 0)
1224 return psCol;
1225
1226 return getPhases(type);
1227 }
1228
1229 private static PhaseStageCollection getPhases(RawProtoCollection col)
1230 {
1231 PhaseStageCollection psCol = new PhaseStageCollection();
1232
1233 foreach (RawProto proto1 in col)
1234 {
1235 RawProto protoPhase = proto1.FindChild("phase");
1236 if (protoPhase == null)
1237 continue;
1238
1239 Stage stage = Stage.NONE;
1240 RawProto protoStage = proto1.FindChild("stage");
1241 if (protoStage != null)
1242 {
1243 if (protoStage.Value == Stage.RL.ToString())
1244 stage = Stage.RL;
1245
1246 else if (protoStage.Value == Stage.RNN.ToString())
1247 stage = Stage.RNN;
1248 }
1249
1250 Phase phase = Phase.NONE;
1251 if (protoPhase != null)
1252 {
1253 if (protoPhase.Value == Phase.ALL.ToString())
1254 phase = Phase.ALL;
1255
1256 else if (protoPhase.Value == Phase.RUN.ToString())
1257 phase = Phase.RUN;
1258
1259 else if (protoPhase.Value == Phase.TEST.ToString())
1260 phase = Phase.TEST;
1261
1262 else if (protoPhase.Value == Phase.TRAIN.ToString())
1263 phase = Phase.TRAIN;
1264 }
1265
1266 psCol.Add(phase, stage);
1267 }
1268
1269 return psCol;
1270 }
1271
1272 private static bool includeLayer(RawProto layer, Stage stage, out PhaseStageCollection psInclude, out PhaseStageCollection psExclude)
1273 {
1274 psInclude = getPhases(layer, "include");
1275 psExclude = getPhases(layer, "exlcude").FindAllWith(stage);
1276
1277 PhaseStageCollection psInclude1 = psInclude.FindAllWith(Stage.NONE);
1278 PhaseStageCollection psInclude2 = psInclude.FindAllWith(stage);
1279 PhaseStageCollection psInclude3 = psInclude.FindAllWith(Phase.NONE, Phase.ALL, Phase.RUN);
1280 psExclude = psExclude.FindAllWith(Phase.RUN);
1281
1282 if (psExclude.Count > 0)
1283 return false;
1284
1285 if (psInclude.Count > 0)
1286 {
1287 if (psInclude3.Count == 0 || (psInclude1.Count == 0 && psInclude2.Count == 0))
1288 return false;
1289 }
1290
1291 return true;
1292 }
1293
1294
1309 public static RawProto CreateModelForRunning(string strModelDescription, string strName, int nNum, int nChannels, int nHeight, int nWidth, out RawProto protoTransform, out bool bSkipTransformParam, Stage stage = Stage.NONE, bool bSkipLossLayer = false)
1310 {
1311 PhaseStageCollection psInclude;
1312 PhaseStageCollection psExclude;
1313 RawProto proto = RawProto.Parse(strModelDescription);
1314 int nNameIdx = proto.FindChildIndex("name");
1315 int nInputInsertIdx = -1;
1316 int nInputShapeInsertIdx = -1;
1317 bool bNoInput = false;
1318 bool bNameSet = false;
1319
1320 protoTransform = null;
1321 bSkipTransformParam = false;
1322
1323 nNameIdx++;
1324 if (nNameIdx < 0)
1325 nNameIdx = 0;
1326
1327 RawProtoCollection rgLayers = proto.FindChildren("layer");
1328 bool bUsesLstm = false;
1329
1330 foreach (RawProto layer in rgLayers)
1331 {
1332 RawProto type = layer.FindChild("type");
1333 if (type != null)
1334 {
1335 string strType = type.Value.ToLower();
1336 if (strType == "lstm")
1337 {
1338 bUsesLstm = true;
1339 break;
1340 }
1341 else if (!bNameSet && (
1342 strType == "data" ||
1343 strType == "annotated_data" ||
1344 strType == "tokenizeddata" ||
1345 strType.StartsWith("tokenizeddatapairs")))
1346 {
1347 RawProtoCollection tops = layer.FindChildren("top");
1348 if (tops != null && tops.Count > 0)
1349 {
1350 if (strType == "tokenizeddata" ||
1351 strType.StartsWith("tokenizeddatapairs"))
1352 strName = "data";
1353 else
1354 strName = tops[0].Value;
1355 bNameSet = true;
1356 }
1357 }
1358 }
1359 }
1360
1361 List<Tuple<string, int, int, int, int>> rgInputs = new List<Tuple<string, int, int, int, int>>();
1362 rgInputs.Add(new Tuple<string, int, int, int, int>(strName, nNum, nChannels, nHeight, nWidth));
1363
1364 bool bFoundInput = false;
1365 bool bFoundMemoryData = false;
1366 bool bSkipBottomRename = false;
1367
1368 foreach (RawProto layer in rgLayers)
1369 {
1370 RawProto type = layer.FindChild("type");
1371 if (type != null)
1372 {
1373 string strType = type.Value.ToLower();
1374 if (strType == "input")
1375 {
1376 bFoundInput = true;
1377
1378 if (includeLayer(layer, stage, out psInclude, out psExclude))
1379 {
1380 rgInputs.Clear();
1381
1382 RawProtoCollection rgTop = layer.FindChildren("top");
1383 RawProto input_param = layer.FindChild("input_param");
1384 if (input_param != null)
1385 {
1386 RawProtoCollection rgShape = input_param.FindChildren("shape");
1387
1388 if (rgTop.Count == rgShape.Count)
1389 {
1390 for (int i = 0; i < rgTop.Count; i++)
1391 {
1392 if (bUsesLstm && i < 2)
1393 {
1394 RawProtoCollection rgDim = rgShape[i].FindChildren("dim");
1395 if (rgDim.Count > 1)
1396 {
1397 rgDim[1].Value = "1";
1398 }
1399 }
1400
1401 if (rgTop[i].Value.ToLower() != "label")
1402 {
1403 List<int> rgVal = new List<int>();
1404 RawProtoCollection rgDim = rgShape[i].FindChildren("dim");
1405 foreach (RawProto dim in rgDim)
1406 {
1407 rgVal.Add(int.Parse(dim.Value));
1408 }
1409
1410 nNum = (rgVal.Count > 0) ? rgVal[0] : 1;
1411 nChannels = (rgVal.Count > 1) ? rgVal[1] : 1;
1412 nHeight = (rgVal.Count > 2) ? rgVal[2] : 1;
1413 nWidth = (rgVal.Count > 3) ? rgVal[3] : 1;
1414
1415 rgInputs.Add(new Tuple<string, int, int, int, int>(rgTop[i].Value, nNum, nChannels, nHeight, nWidth));
1416 }
1417 }
1418 }
1419 }
1420 }
1421 }
1422 else if (strType == "memorydata")
1423 {
1424 bFoundMemoryData = true;
1425
1426 if (includeLayer(layer, stage, out psInclude, out psExclude))
1427 {
1428 bNoInput = true;
1429 rgInputs.Clear();
1430 }
1431 }
1432 else if (strType == "data")
1433 {
1434 if (rgInputs.Count > 0)
1435 {
1436 RawProtoCollection colTop = layer.FindChildren("top");
1437 if (colTop.Count > 0)
1438 {
1439 rgInputs[0] = new Tuple<string, int, int, int, int>(colTop[0].Value, rgInputs[0].Item2, rgInputs[0].Item3, rgInputs[0].Item4, rgInputs[0].Item5);
1440 break;
1441 }
1442 }
1443 }
1444 else if (strType == "tokenizeddata" || strType.StartsWith("tokenizeddatapairs"))
1445 {
1446 if (rgInputs.Count > 0)
1447 {
1448 RawProtoCollection colTop = layer.FindChildren("top");
1449 if (colTop.Count > 0)
1450 {
1451 if (strType.StartsWith("tokenizeddatapairs"))
1452 {
1453 rgInputs[0] = new Tuple<string, int, int, int, int>("encin", rgInputs[0].Item2, rgInputs[0].Item3, rgInputs[0].Item4, rgInputs[0].Item5);
1454 rgInputs.Add(new Tuple<string, int, int, int, int>("decin", rgInputs[0].Item2, rgInputs[0].Item3, rgInputs[0].Item4, rgInputs[0].Item5));
1455 layer.Children.Add<string>("bottom", new List<string>() { "encin", "decin" });
1456 }
1457 else
1458 {
1459 rgInputs[0] = new Tuple<string, int, int, int, int>("encin", rgInputs[0].Item2, rgInputs[0].Item3, rgInputs[0].Item4, rgInputs[0].Item5);
1460 layer.Children.Add<string>("bottom", new List<string>() { "encin" });
1461 layer.RemoveChild("top", "tgt");
1462 }
1463 bSkipBottomRename = true;
1464 break;
1465 }
1466 }
1467 }
1468
1469 if (bFoundInput && bFoundMemoryData)
1470 break;
1471 }
1472 }
1473
1474 RawProto input = null;
1475 RawProto input_shape = null;
1476 RawProtoCollection rgInput = null;
1477 RawProtoCollection rgInputShape = null;
1478
1479 if (!bNoInput)
1480 {
1481 rgInput = new RawProtoCollection();
1482 rgInputShape = new RawProtoCollection();
1483
1484 input = proto.FindChild("input");
1485 if (input != null)
1486 {
1487 input.Value = rgInputs[0].Item1;
1488 }
1489 else
1490 {
1491 for (int i = 0; i < rgInputs.Count; i++)
1492 {
1493 input = new RawProto("input", rgInputs[i].Item1, null, RawProto.TYPE.STRING);
1494 rgInput.Add(input);
1495 nInputInsertIdx = nNameIdx;
1496 nNameIdx++;
1497 }
1498 }
1499
1500 input_shape = proto.FindChild("input_shape");
1501 if (input_shape != null)
1502 {
1503 RawProtoCollection colDim = input_shape.FindChildren("dim");
1504
1505 if (colDim.Count > 0)
1506 colDim[0].Value = rgInputs[0].Item2.ToString();
1507
1508 if (colDim.Count > 1)
1509 colDim[1].Value = rgInputs[0].Item3.ToString();
1510
1511 if (colDim.Count > 2)
1512 colDim[2].Value = rgInputs[0].Item4.ToString();
1513
1514 if (colDim.Count > 3)
1515 colDim[3].Value = rgInputs[0].Item5.ToString();
1516 }
1517 else
1518 {
1519 for (int i = 0; i < rgInputs.Count; i++)
1520 {
1521 input_shape = new RawProto("input_shape", "");
1522
1523 nNum = rgInputs[i].Item2;
1524 nChannels = rgInputs[i].Item3;
1525 nHeight = rgInputs[i].Item4;
1526 nWidth = rgInputs[i].Item5;
1527
1528 input_shape.Children.Add(new RawProto("dim", nNum.ToString()));
1529 input_shape.Children.Add(new RawProto("dim", nChannels.ToString()));
1530
1531 if (nHeight > 1 || nWidth > 1)
1532 {
1533 input_shape.Children.Add(new RawProto("dim", nHeight.ToString()));
1534 input_shape.Children.Add(new RawProto("dim", nWidth.ToString()));
1535 }
1536
1537 rgInputShape.Add(input_shape);
1538 nInputShapeInsertIdx = nNameIdx;
1539 }
1540 }
1541 }
1542
1543 RawProto net_name = proto.FindChild("name");
1544 if (net_name != null)
1545 net_name.Value += "-Live";
1546
1547 RawProtoCollection rgRemove = new RawProtoCollection();
1548
1549 List<RawProto> rgProtoSoftMaxLoss = new List<basecode.RawProto>();
1550 RawProto protoSoftMax = null;
1551
1552 foreach (RawProto layer in rgLayers)
1553 {
1554 RawProto type = layer.FindChild("type");
1555 if (type != null)
1556 {
1557 string strType = type.Value.ToLower();
1558 bool bKeepLayer = false;
1559
1560 bool bInclude = includeLayer(layer, stage, out psInclude, out psExclude);
1561
1562 if (strType == "data" || strType == "annotateddata" || strType == "batchdata" || strType == "tokenizeddata" || strType.StartsWith("tokenizeddatapairs"))
1563 {
1564 if (psInclude.Find(Phase.TEST, stage) != null)
1565 protoTransform = layer.FindChild("transform_param");
1566
1567 if (strType == "tokenizeddata" || strType.StartsWith("tokenizeddatapairs"))
1568 {
1569 bSkipTransformParam = true;
1570
1571 if (psInclude != null && psInclude.Count > 0 && psInclude[0].Phase == Phase.TRAIN)
1572 {
1573 bInclude = true;
1574 bKeepLayer = true;
1575
1576 RawProto rpParam = layer.FindChild("tokenized_data_pairs_param");
1577 if (rpParam != null)
1578 {
1579 RawProto rpBatch = rpParam.FindChild("batch_size");
1580 if (rpBatch != null)
1581 rpBatch.Value = "1";
1582 }
1583 }
1584 }
1585 }
1586 else if (strType == "decode")
1587 {
1588 List<RawProto> rgBtm = new List<RawProto>();
1589
1590 foreach (RawProto child in layer.Children)
1591 {
1592 if (child.Name == "bottom")
1593 rgBtm.Add(child);
1594 }
1595
1596 if (rgBtm.Count > 0)
1597 rgBtm.RemoveAt(0);
1598
1599 foreach (RawProto btm in rgBtm)
1600 {
1601 layer.Children.Remove(btm);
1602 }
1603 }
1604
1605 if (!bInclude)
1606 {
1607 rgRemove.Add(layer);
1608 }
1609 else if (psExclude.Find(Phase.RUN, stage) != null)
1610 {
1611 rgRemove.Add(layer);
1612 }
1613 else if (strType == "input")
1614 {
1615 rgRemove.Add(layer);
1616 }
1617 else if (strType == "softmaxwithloss" ||
1618 strType == "softmaxcrossentropy_loss" ||
1619 strType == "softmaxcrossentropyloss" ||
1620 strType == "softmaxcrossentropy2_loss" ||
1621 strType == "softmaxcrossentropy2loss")
1622 {
1623 if (!bSkipLossLayer)
1624 {
1625 rgProtoSoftMaxLoss.Add(layer);
1626 bKeepLayer = true;
1627 }
1628 else
1629 {
1630 rgRemove.Add(layer);
1631 }
1632 }
1633 else if (strType == "memoryloss" ||
1634 strType == "contrastive_loss" ||
1635 strType == "contrastiveloss" ||
1636 strType == "euclidean_loss" ||
1637 strType == "euclideanloss" ||
1638 strType == "hinge_loss" ||
1639 strType == "hingeloss" ||
1640 strType == "infogain_loss" ||
1641 strType == "infogainloss" ||
1642 strType == "multinomiallogistic_loss" ||
1643 strType == "multinomiallogisticloss" ||
1644 strType == "sigmoidcrossentropy_loss" ||
1645 strType == "sigmoidcrossentropyloss" ||
1646 strType == "triplet_loss" ||
1647 strType == "tripletloss" ||
1648 strType == "triplet_loss_simple" ||
1649 strType == "tripletlosssimple")
1650 {
1651 rgRemove.Add(layer);
1652 }
1653 else if (strType == "softmax")
1654 {
1655 protoSoftMax = layer;
1656 }
1657 else if (strType == "labelmapping")
1658 {
1659 rgRemove.Add(layer);
1660 }
1661 else if (strType == "debug")
1662 {
1663 rgRemove.Add(layer);
1664 }
1665 else if (strType == "tokenizeddata" || strType.StartsWith("tokenizeddatapairs"))
1666 {
1667 if (psInclude.Count > 0 && psInclude[0].Phase == Phase.TRAIN)
1668 {
1669 RawProtoCollection rpInc = layer.FindChildren("include");
1670 if (rpInc != null)
1671 {
1672 foreach (RawProto rpInc1 in rpInc)
1673 {
1674 layer.Children.Remove(rpInc1);
1675 }
1676 }
1677 }
1678 }
1679
1680 if (!bKeepLayer && psInclude.FindAllWith(Phase.TEST, Phase.TRAIN).Count > 0 && psInclude.FindAllWith(Phase.RUN).Count == 0)
1681 {
1682 rgRemove.Add(layer);
1683 }
1684 else
1685 {
1686 RawProto max_btm = layer.FindChild("max_bottom_count");
1687 if (max_btm != null)
1688 {
1689 RawProto phase1 = max_btm.FindChild("phase");
1690 RawProto stage1 = max_btm.FindChild("stage");
1691
1692 if (phase1 != null && phase1.Value == "RUN" && (stage1 == null || stage1.Value == stage.ToString() || stage1.Value == Stage.NONE.ToString()))
1693 {
1694 RawProto count = max_btm.FindChild("count");
1695 int nCount = int.Parse(count.Value);
1696
1697 int nBtmIdx = layer.FindChildIndex("bottom");
1698 int nBtmEnd = layer.Children.Count;
1699 List<int> rgRemoveIdx = new List<int>();
1700
1701 for (int i = nBtmIdx; i < layer.Children.Count; i++)
1702 {
1703 if (layer.Children[i].Name != "bottom")
1704 {
1705 nBtmEnd = i;
1706 break;
1707 }
1708 }
1709
1710 for (int i = nBtmEnd - 1; i >= nBtmIdx + nCount; i--)
1711 {
1712 layer.Children.RemoveAt(i);
1713 }
1714 }
1715 }
1716 }
1717 }
1718
1719 RawProto exclude = layer.FindChild("exclude");
1720 if (exclude != null)
1721 {
1722 RawProto phase = exclude.FindChild("phase");
1723 if (phase != null)
1724 {
1725 if (phase.Value == "RUN")
1726 {
1727 if (!rgRemove.Contains(layer))
1728 rgRemove.Add(layer);
1729 }
1730 }
1731 }
1732 }
1733
1734 foreach (RawProto protoSoftMaxLoss in rgProtoSoftMaxLoss)
1735 {
1736 if (protoSoftMax != null)
1737 {
1738 rgRemove.Add(protoSoftMaxLoss);
1739 }
1740 else
1741 {
1742 RawProto type = protoSoftMaxLoss.FindChild("type");
1743 if (type != null)
1744 type.Value = "Softmax";
1745
1746 RawProtoCollection colBtm = protoSoftMaxLoss.FindChildren("bottom");
1747
1748 for (int i = 1; i < colBtm.Count; i++)
1749 {
1750 protoSoftMaxLoss.RemoveChild("bottom", colBtm[i].Value, true);
1751 }
1752 }
1753 }
1754
1755 foreach (RawProto layer in rgRemove)
1756 {
1757 proto.RemoveChild(layer);
1758 }
1759
1760 RawProto layer1 = proto.FindChild("layer");
1761 if (layer1 != null)
1762 {
1763 RawProto btm = layer1.FindChild("bottom");
1764 if (btm != null && !bSkipBottomRename)
1765 btm.Value = strName;
1766 }
1767
1768 if (input != null && input_shape != null)
1769 {
1770 if (protoTransform != null)
1771 {
1772 RawProto resize = protoTransform.FindChild("resize_param");
1773
1774 if (resize != null)
1775 {
1776 bool bActive = (bool)resize.FindValue("active", typeof(bool));
1777 if (bActive)
1778 {
1779 int nNewHeight = (int)resize.FindValue("height", typeof(int));
1780 int nNewWidth = (int)resize.FindValue("width", typeof(int));
1781
1782 if (rgInputShape[0].Children.Count < 1)
1783 rgInputShape[0].Children.Add(new RawProto("dim", "1"));
1784
1785 if (rgInputShape[0].Children.Count < 2)
1786 rgInputShape[0].Children.Add(new RawProto("dim", "1"));
1787
1788 if (rgInputShape[0].Children.Count < 3)
1789 rgInputShape[0].Children.Add(new RawProto("dim", nNewHeight.ToString()));
1790 else
1791 rgInputShape[0].Children[2] = new RawProto("dim", nNewHeight.ToString());
1792
1793 if (rgInputShape[0].Children.Count < 4)
1794 rgInputShape[0].Children.Add(new RawProto("dim", nNewWidth.ToString()));
1795 else
1796 rgInputShape[0].Children[3] = new RawProto("dim", nNewWidth.ToString());
1797 }
1798 }
1799 }
1800
1801 for (int i = rgInputShape.Count - 1; i >= 0; i--)
1802 {
1803 proto.Children.Insert(0, rgInputShape[i]);
1804 }
1805
1806 for (int i = rgInput.Count - 1; i >= 0; i--)
1807 {
1808 proto.Children.Insert(0, rgInput[i]);
1809 }
1810 }
1811
1812 return proto;
1813 }
1814
1822 public void SetDataset(DatasetDescriptor dataset)
1823 {
1824 if (dataset == null)
1825 return;
1826
1827 m_project.Dataset = dataset;
1828
1829 if (m_project.ModelDescription != null && m_project.ModelDescription.Length > 0)
1830 {
1831 bool bResized = false;
1832 string strProto = SetDataset(m_project.ModelDescription, dataset, out bResized);
1833 RawProto proto = RawProto.Parse(strProto);
1834
1835 if (OnOverrideModel != null)
1836 {
1837 OverrideProjectArgs args = new OverrideProjectArgs(proto);
1838 OnOverrideModel(this, args);
1839 proto = args.Proto;
1840 }
1841
1842 ModelDescription = proto.ToString();
1843 }
1844
1845 if (m_project.SolverDescription != null && m_project.SolverDescription.Length > 0)
1846 {
1847 if (OnOverrideSolver != null)
1848 {
1849 RawProto proto = RawProto.Parse(m_project.SolverDescription);
1850 OverrideProjectArgs args = new OverrideProjectArgs(proto);
1851 OnOverrideSolver(this, args);
1852 proto = args.Proto;
1853
1854 SolverDescription = proto.ToString();
1855 }
1856 }
1857 }
1858
1869 public static string SetDataset(string strModelDesc, DatasetDescriptor dataset, out bool bResized, bool bUpdateOutputs = false)
1870 {
1871 bResized = false;
1872
1873 if (dataset == null)
1874 return null;
1875
1876 if (dataset.Name == "MODEL")
1877 return strModelDesc;
1878
1879 string strTypeLast = null;
1880 RawProto protoLast = null;
1881 RawProto proto = RawProto.Parse(strModelDesc);
1882 List<RawProto> rgLastIp = new List<RawProto>();
1883 RawProtoCollection colLayers = proto.FindChildren("layer");
1884 RawProto protoDataTrainBatch = null;
1885 RawProto protoDataTestBatch = null;
1886
1887 if (colLayers.Count == 0)
1888 colLayers = proto.FindChildren("layers");
1889
1891
1892 foreach (RawProto protoChild in colLayers)
1893 {
1894 RawProto type = protoChild.FindChild("type");
1895 RawProto name = protoChild.FindChild("name");
1896
1897 string strType = type.Value.ToLower();
1898
1899 if (strType == "data")
1900 {
1901 int nCropSize = 0;
1902
1903 RawProto data_param = protoChild.FindChild("data_param");
1904 if (data_param != null)
1905 {
1906 RawProto batchProto = data_param.FindChild("batch_size");
1907
1908 RawProto include = protoChild.FindChild("include");
1909 if (include != null)
1910 {
1911 RawProto phase = include.FindChild("phase");
1912 if (phase != null)
1913 {
1914 RawProto source = data_param.FindChild("source");
1915 if (phase.Value == "TEST")
1916 {
1917 protoDataTestBatch = batchProto;
1918
1919 if (source != null)
1920 {
1921 source.Value = dataset.TestingSource.Name;
1922 nCropSize = dataset.TestingSource.Height;
1923 }
1924 else
1925 {
1926 data_param.Children.Add(new RawProto("source", dataset.TestingSource.Name, null, RawProto.TYPE.STRING));
1927 }
1928 }
1929 else
1930 {
1931 protoDataTrainBatch = batchProto;
1932
1933 if (source != null)
1934 {
1935 source.Value = dataset.TrainingSource.Name;
1936 nCropSize = dataset.TrainingSource.Height;
1937 }
1938 else
1939 {
1940 data_param.Children.Add(new RawProto("source", dataset.TrainingSource.Name, null, RawProto.TYPE.STRING));
1941 }
1942 }
1943 }
1944 }
1945 }
1946
1947 RawProto transform_param = protoChild.FindChild("transform_param");
1948 if (transform_param != null)
1949 {
1950 RawProto crop_size = transform_param.FindChild("crop_size");
1951 if (crop_size != null)
1952 {
1953 int nSize = int.Parse(crop_size.Value);
1954
1955 if (nCropSize != nSize)
1956 crop_size.Value = nCropSize.ToString();
1957 }
1958 }
1959 }
1960 else if (strType.Contains("loss"))
1961 {
1962 if (colIP.Count > 0)
1963 {
1964 rgLastIp.Add(colIP[0]);
1965 colIP.Clear();
1966 }
1967 }
1968 else if (strType == "inner_product" || strType == "innerproduct")
1969 {
1970 colIP.Insert(0, protoChild);
1971 }
1972
1973 protoLast = protoChild;
1974 strTypeLast = strType;
1975 }
1976
1977 if (protoDataTestBatch != null && protoDataTrainBatch != null)
1978 {
1979 int nTestSize = int.Parse(protoDataTestBatch.Value);
1980 int nTrainSize = int.Parse(protoDataTrainBatch.Value);
1981
1982 if (nTrainSize < nTestSize)
1983 protoDataTrainBatch.Value = nTestSize.ToString();
1984 }
1985
1986 if (bUpdateOutputs)
1987 {
1988 foreach (RawProto lastIp in rgLastIp)
1989 {
1990 RawProto protoParam = lastIp.FindChild("inner_product_param");
1991 if (protoParam != null)
1992 {
1993 RawProto protoNumOut = protoParam.FindChild("num_output");
1994 if (protoNumOut != null)
1995 {
1996 int nNumOut = dataset.TrainingSource.Labels.Count;
1997
1998 if (nNumOut > 0)
1999 {
2000 protoNumOut.Value = nNumOut.ToString();
2001 bResized = true;
2002 }
2003 }
2004 }
2005 }
2006 }
2007
2008 return proto.ToString();
2009 }
2010
2024 public static string FindLayerParameter(string strModelDescription, string strLayerName, string strLayerType, string strParam, string strField, Phase phaseMatch = Phase.NONE)
2025 {
2026 RawProto proto = RawProto.Parse(strModelDescription);
2027
2028 RawProtoCollection rgLayers = proto.FindChildren("layer");
2029 RawProto firstFound = null;
2030
2031 foreach (RawProto layer in rgLayers)
2032 {
2033 RawProto type = layer.FindChild("type");
2034 RawProto name = layer.FindChild("name");
2035
2036 if (strLayerType == type.Value.ToString() && (strLayerName == null || name.Value.ToString() == strLayerName))
2037 {
2038 if (phaseMatch != Phase.NONE)
2039 {
2040 RawProto include = layer.FindChild("include");
2041
2042 if (include != null)
2043 {
2044 RawProto phase = include.FindChild("phase");
2045 if (phase != null)
2046 {
2047 if (phase.Value == phaseMatch.ToString())
2048 {
2049 firstFound = layer;
2050 break;
2051 }
2052 }
2053 }
2054 else
2055 {
2056 if (firstFound == null)
2057 firstFound = layer;
2058 }
2059 }
2060 else
2061 {
2062 if (firstFound == null)
2063 firstFound = layer;
2064 }
2065 }
2066 }
2067
2068 if (firstFound == null)
2069 return null;
2070
2071 RawProto child = null;
2072
2073 if (strParam != null)
2074 child = firstFound.FindChild(strParam);
2075
2076 if (child != null)
2077 firstFound = child;
2078
2079 return firstFound.FindValue(strField);
2080 }
2081
2086 public bool DisableTesting()
2087 {
2088 // Force parse the proto if not already parsed.
2089 if (m_protoSolver == null)
2090 {
2091 string strProto = SolverDescription;
2092 SolverDescription = strProto;
2093 }
2094
2095 bool bSet = false;
2096 RawProto protoTestIter = m_protoSolver.FindChild("test_iter");
2097 RawProto protoTestInterval = m_protoSolver.FindChild("test_interval");
2098 RawProto protoTestInit = m_protoSolver.FindChild("test_initialization");
2099
2100 if (protoTestInterval != null)
2101 {
2102 if (protoTestInterval.Value != "0")
2103 {
2104 protoTestInterval.Value = "0";
2105 bSet = true;
2106 }
2107 }
2108
2109 if (protoTestInit != null)
2110 {
2111 if (protoTestInit.Value != "False")
2112 {
2113 protoTestInit.Value = "False";
2114 bSet = true;
2115 }
2116 }
2117
2118 if (protoTestIter != null)
2119 {
2120 m_protoSolver.RemoveChild(protoTestIter);
2121 bSet = true;
2122 }
2123
2124 if (bSet)
2125 SolverDescription = m_protoSolver.ToString();
2126
2127 return bSet;
2128 }
2129
2134 public override string ToString()
2135 {
2136 string strName = Name;
2137
2138 if (strName == null || strName.Length == 0)
2139 {
2140 string strModelDesc = ModelDescription;
2141
2142 if (strModelDesc != null && strModelDesc.Length > 0)
2143 {
2144 int nPos = strModelDesc.IndexOf("name:");
2145
2146 if (nPos < 0)
2147 nPos = strModelDesc.IndexOf("Name:");
2148
2149 if (nPos >= 0)
2150 {
2151 nPos += 5;
2152 int nPos2 = strModelDesc.IndexOfAny(new char[] { ' ', '\n', '\r' }, nPos);
2153
2154 if (nPos2 > 0)
2155 strName = strModelDesc.Substring(nPos + 5, nPos2).Trim();
2156 }
2157 }
2158
2159 if (strName.Length == 0)
2160 strName = "(ID = " + m_project.ID.ToString() + ")";
2161 }
2162
2163 return "Project: " + strName + " -> Dataset: " + m_project.Dataset.Name;
2164 }
2165 }
2166
2167 class PhaseStageCollection
2168 {
2169 List<PhaseStage> m_rgItems = new List<PhaseStage>();
2170
2171 public PhaseStageCollection()
2172 {
2173 }
2174
2175 public int Count
2176 {
2177 get { return m_rgItems.Count; }
2178 }
2179
2180 public PhaseStage this[int nIdx]
2181 {
2182 get { return m_rgItems[nIdx]; }
2183 }
2184
2185 public bool Add(Phase p, Stage s)
2186 {
2187 PhaseStage ps = Find(p, s);
2188 if (ps == null)
2189 {
2190 m_rgItems.Add(new PhaseStage(p, s));
2191 return true;
2192 }
2193
2194 return false;
2195 }
2196
2197 public PhaseStage Find(Phase p, Stage s)
2198 {
2199 foreach (PhaseStage ps in m_rgItems)
2200 {
2201 if (ps.Phase == p && ps.Stage == s)
2202 return ps;
2203 }
2204
2205 return null;
2206 }
2207
2208 public PhaseStageCollection FindAllWith(Stage stage)
2209 {
2210 PhaseStageCollection psCol = new PhaseStageCollection();
2211
2212 foreach (PhaseStage ps in m_rgItems)
2213 {
2214 if (ps.Stage == stage)
2215 psCol.Add(ps.Phase, ps.Stage);
2216 }
2217
2218 return psCol;
2219 }
2220 public PhaseStageCollection FindAllWith(params Phase[] phase)
2221 {
2222 PhaseStageCollection psCol = new PhaseStageCollection();
2223
2224 foreach (PhaseStage ps in m_rgItems)
2225 {
2226 if (phase.Contains(ps.Phase))
2227 psCol.Add(ps.Phase, ps.Stage);
2228 }
2229
2230 return psCol;
2231 }
2232 }
2233
2234 class PhaseStage
2235 {
2236 Phase m_phase = Phase.NONE;
2237 Stage m_stage = Stage.NONE;
2238
2239 public PhaseStage(Phase p, Stage s)
2240 {
2241 m_phase = p;
2242 m_stage = s;
2243 }
2244
2245 public Phase Phase
2246 {
2247 get { return m_phase; }
2248 }
2249
2250 public Stage Stage
2251 {
2252 get { return m_stage; }
2253 }
2254 }
2255}
The BaseParameter class is the base class for all other parameter classes.
static bool TryParse(string strVal, out double df)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
The OverrideProjectArgs is passed as an argument to the OnOverrideModel and OnOverrideSolver events f...
Definition: EventArgs.cs:181
RawProto Proto
Get/set the RawProto used.
Definition: EventArgs.cs:197
The ProjectEx class manages a project containing the solver description, model description,...
Definition: ProjectEx.cs:15
string GetLayerSettingEx(Phase phase, string strLayer, string strParam)
Returns the setting of a Layer (if found).
Definition: ProjectEx.cs:418
bool DisableTesting()
Disables the testing interval so that no test passes are run.
Definition: ProjectEx.cs:2086
SNAPSHOT_WEIGHT_UPDATE_METHOD SnapshotWeightUpdateMethod
Returns the snapshot weight update favor. The snapshot can favor an improving accuracy,...
Definition: ProjectEx.cs:710
GroupDescriptor ModelGroup
Return the model group descriptor of the group that the Project participates in (if any).
Definition: ProjectEx.cs:796
string GpuOverride
Returns the list of comma separated GPU ID's that are to be used when training this Project.
Definition: ProjectEx.cs:666
int TargetDatasetID
Get/set the dataset ID of the target dataset (if exists), otherwise return 0.
Definition: ProjectEx.cs:915
bool HasResults
Return whether or not the project has results from a training session.
Definition: ProjectEx.cs:829
ProjectEx(ProjectDescriptor prj, StateDescriptor state=null, bool bExistTrain=false, bool bExistTest=false, bool bQueryModel=true, bool bQuerySolver=true)
The ProjectEx constructor.
Definition: ProjectEx.cs:57
string? SolverDescription
Get/set the solver description script used by the Project.
Definition: ProjectEx.cs:726
RawProto CreateModelForRunning(string strName, int nNum, int nChannels, int nHeight, int nWidth, out RawProto protoTransform, out bool bSkipTransformParam, Stage stage=Stage.NONE, bool bSkipLossLayer=false)
Create a model description as a RawProto for running the Project.
Definition: ProjectEx.cs:1041
bool EnableRandomSelection
Returns whether or not random image selection is enabled. When enabled, images are randomly selected ...
Definition: ProjectEx.cs:648
string Name
Get/set the name of the Project.
Definition: ProjectEx.cs:524
ValueDescriptorCollection ProjectPerformanceItems
Return Project performance metrics.
Definition: ProjectEx.cs:959
int ID
Returns the ID of the Project in the database.
Definition: ProjectEx.cs:533
string DatasetName
Return the name of the dataset used.
Definition: ProjectEx.cs:882
SNAPSHOT_LOAD_METHOD SnapshotLoadMethod
Returns the snapshot load method. When loading the best error or accuracy, the snapshot loaded may no...
Definition: ProjectEx.cs:718
bool Active
Returns whether or not the Project is active.
Definition: ProjectEx.cs:568
int ImageLoadLimitRefreshPeriod
Returns the image load limit refresh period in milliseconds.
Definition: ProjectEx.cs:691
bool UseTrainingSourceForTesting
Returns whether or not the Project uses the training data source when testing (default = false).
Definition: ProjectEx.cs:621
int Iterations
Get/set the current number of iterations that the Project has been trained.
Definition: ProjectEx.cs:837
int TotalIterations
Get/set the total number of iterations that the Project has been trained.
Definition: ProjectEx.cs:820
bool ExistTrainResults
Return whether or not training results exist.
Definition: ProjectEx.cs:951
static RawProto CreateModelForRunning(string strModelDescription, string strName, int nNum, int nChannels, int nHeight, int nWidth, out RawProto protoTransform, out bool bSkipTransformParam, Stage stage=Stage.NONE, bool bSkipLossLayer=false)
Create a model description as a RawProto for running the Project.
Definition: ProjectEx.cs:1309
SettingsCaffe Settings
Get/set the Caffe setting to use with the Project.
Definition: ProjectEx.cs:515
static string FindLayerParameter(string strModelDescription, string strLayerName, string strLayerType, string strParam, string strField, Phase phaseMatch=Phase.NONE)
This method searches for a given parameter within a given layer, optionally for a certain Phase.
Definition: ProjectEx.cs:2024
string ModelName
Return the name of the model used by the Project.
Definition: ProjectEx.cs:967
bool RequiresDataCriteria()
Returns whether or not the data criteria is required by the current project model (e....
Definition: ProjectEx.cs:84
ProjectEx(string strName, string strDsName=null)
The ProjectEx constructor.
Definition: ProjectEx.cs:41
double ImageLoadLimitRefreshPercent
Returns the image load limit refresh percentage (to update).
Definition: ProjectEx.cs:699
double? GetSolverSettingAsNumeric(string strParam)
Get a setting from the solver descriptor as a double value.
Definition: ProjectEx.cs:470
ParameterDescriptorCollection Parameters
Returns any project parameters that may exist (if any).
Definition: ProjectEx.cs:812
void SetDataset(DatasetDescriptor dataset)
Sets the dataset used by the Project, overriding the current dataset used.
Definition: ProjectEx.cs:1822
DatasetDescriptor Dataset
Return the descriptor of the dataset used.
Definition: ProjectEx.cs:896
TRAINING_CATEGORY TrainingCategory
Returns the training category of the project, or NONE if no custom trainer is used.
Definition: ProjectEx.cs:576
int? GetSolverSettingAsInt(string strParam)
Get a setting from the solver descriptor as an integer value.
Definition: ProjectEx.cs:488
string GetCustomTrainer(out string strProperties)
Returns the custom trainer and properties used by the project (if any).
Definition: ProjectEx.cs:312
void LoadSolverFile(string strFile)
Load the solver description from a file.
Definition: ProjectEx.cs:1008
int ImageLoadLimit
Returns the image load limit.
Definition: ProjectEx.cs:683
bool ExistTestResults
Return whether or not testing results exist.
Definition: ProjectEx.cs:943
string SolverType
Return the type of the Solver used by the Project.
Definition: ProjectEx.cs:975
string? ModelDescription
Get/set the model description script used by the Project.
Definition: ProjectEx.cs:757
GroupDescriptor ProjectGroup
Return the project group descriptor of the group that the Project resides (if any).
Definition: ProjectEx.cs:788
EventHandler< OverrideProjectArgs > OnOverrideSolver
The OverrideSolver event fires each time the SetDataset function is called.
Definition: ProjectEx.cs:34
double? GetLayerSetting(Phase phase, string strLayer, string strParam)
Returns the setting of a Layer (if found).
Definition: ProjectEx.cs:402
byte[] WeightsState
Get/set the weight state.
Definition: ProjectEx.cs:873
DB_LOAD_METHOD ImageLoadMethod
Returns the method used to load the images into memory. Loading all images into memory has the highes...
Definition: ProjectEx.cs:675
override string ToString()
Returns a string representation of the Project.
Definition: ProjectEx.cs:2134
int GetBatchSize(Phase phase)
Returns the batch size of the project used in a given Phase.
Definition: ProjectEx.cs:359
bool EnablePairSelection
Returns whether or not pair selection is enabled. When using pair selection, images are queried in pa...
Definition: ProjectEx.cs:658
string GetSolverSetting(string strParam)
Get a setting from the solver descriptor.
Definition: ProjectEx.cs:453
bool DatasetAdjusted
Get/set whether or not the dataset for the project has been changed.
Definition: ProjectEx.cs:301
int OriginalID
Get/set the original project ID.
Definition: ProjectEx.cs:541
DatasetDescriptor DatasetTarget
Returns the target dataset (if exists) or null if it does not.
Definition: ProjectEx.cs:907
string Owner
Get/set the ID of the Project owner.
Definition: ProjectEx.cs:559
double BestAccuracy
Get/set the best accuracy observed while testing the Project.
Definition: ProjectEx.cs:846
void LoadModelFile(string strFile)
Load the model description from a file.
Definition: ProjectEx.cs:1020
double BestError
Get/set the best error observed while training the Project.
Definition: ProjectEx.cs:855
bool SetSolverVariable(string strVar, string strVal)
Set a given Solver variable in the solver description script.
Definition: ProjectEx.cs:985
bool EnableLabelBalancing
Returns whether or not label balancing is enabled. When enabled, first the label set is randomly sele...
Definition: ProjectEx.cs:630
GroupDescriptor DatasetGroup
Return the dataset group descriptor of the group that the Project participates in (if any).
Definition: ProjectEx.cs:804
bool EnableLabelBoosting
Returns whether or not label boosting is enabled. When using Label boosting, images are selected from...
Definition: ProjectEx.cs:639
static RawProto CreateModelForTraining(string strModelDescription, string strName, bool bCaffeFormat=false)
Create a model description as a RawProto for training the Project.
Definition: ProjectEx.cs:1053
byte[] SolverState
Get/set the solver state.
Definition: ProjectEx.cs:864
double SuperBoostProbability
Get/set the super boost probability used by the Project.
Definition: ProjectEx.cs:612
Stage Stage
Return the stage under which the project was opened.
Definition: ProjectEx.cs:603
EventHandler< OverrideProjectArgs > OnOverrideModel
The OverrrideModel event fires each time the SetDataset function is called.
Definition: ProjectEx.cs:30
static string SetDataset(string strModelDesc, DatasetDescriptor dataset, out bool bResized, bool bUpdateOutputs=false)
Sets the dataset of a model, overriding the current dataset used.
Definition: ProjectEx.cs:1869
bool? GetSolverSettingAsBool(string strParam)
Get a setting from the solver descriptor as a boolean value.
Definition: ProjectEx.cs:502
The RawProtoCollection class is a list of RawProto objects.
bool Remove(RawProto p)
Removes a RawProto from the collection.
void RemoveAt(int nIdx)
Removes the RawProto at a given index in the collection.
void Add(RawProto p)
Adds a RawProto to the collection.
void Insert(int nIdx, RawProto p)
Inserts a new RawProto into the collection at a given index.
int Count
Returns the number of items in the collection.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
TYPE
Defines the type of a RawProto node.
Definition: RawProto.cs:27
string Name
Returns the name of the node.
Definition: RawProto.cs:71
RawProtoCollection Children
Returns a collection of this nodes child nodes.
Definition: RawProto.cs:96
string Value
Get/set the value of the node.
Definition: RawProto.cs:79
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
override string ToString()
Returns the RawProto as its full prototxt string.
Definition: RawProto.cs:681
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
int FindChildIndex(string strName)
Searches for the index to a given node's child.
Definition: RawProto.cs:247
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
bool RemoveChild(RawProto p)
Removes a given child from this node's children.
Definition: RawProto.cs:188
RawProtoCollection FindChildren(params string[] rgstrName)
Searches for all children with a given name in this node's children.
Definition: RawProto.cs:263
The SettingsCaffe defines the settings used by the MyCaffe CaffeControl.
SNAPSHOT_WEIGHT_UPDATE_METHOD SnapshotWeightUpdateMethod
Get/set the snapshot update method.
bool EnableRandomInputSelection
Get/set random image selection. When enabled, images are randomly selected from the entire set,...
SNAPSHOT_LOAD_METHOD SnapshotLoadMethod
Get/set the snapshot load method.
double DbAutoRefreshScheduledReplacementPercent
Get/set the automatic refresh scheduled update replacement percentage used on refresh (default = 0....
int DbLoadLimit
Get/set the image database load limit.
bool EnableLabelBoosting
DEPRECIATED: Get/set label boosting. When using Label boosting, images are selected from boosted labe...
double SuperBoostProbability
Get/set the superboost probability used when selecting boosted images.
DB_LOAD_METHOD DbLoadMethod
Get/set the image database loading method.
bool EnablePairInputSelection
Get/set pair image selection. When using pair selection, images are queried in pairs where the first ...
int DbAutoRefreshScheduledUpdateInMs
Get/set the automatic refresh scheduled udpate period (default = 10000, only applies when ImageDbLoad...
bool EnableLabelBalancing
Get/set label balancing. When enabled, first the label set is randomly selected and then the image is...
string Owner
Get/set the owner of the item.
int ID
Get/set the database ID of the item.
string Name
Get/set the name of the item.
The DatasetDescriptor class describes a dataset which contains both a training data source and testin...
GroupDescriptor DatasetGroup
Returns the dataset group.
SourceDescriptor TrainingSource
Get/set the training data source.
GroupDescriptor ModelGroup
Get/set the dataset model group.
string? TrainingSourceName
Returns the training source name, or null if not specifies.
SourceDescriptor TestingSource
Get/set the testing data source.
string? TestingSourceName
Returns the testing source name or null if not specified.
DatasetDescriptor(int nID, string strName, GroupDescriptor grpModel, GroupDescriptor grpDs, SourceDescriptor srcTrain, SourceDescriptor srcTest, string strCreatorName, string strDescription, string strOwner=null, GYM_TYPE gymType=GYM_TYPE.NONE)
The DatasetDescriptor constructor.
The GroupDescriptor class defines a group.
The ParameterDescriptorCollection class contains a list of ParameterDescriptor's.
void Add(ParameterDescriptor p)
Adds a ParameterDescriptor to the collection.
ParameterDescriptor Find(string strName)
Searches for a parameter by name in the collection.
The ParameterDescriptor class describes a parameter in the database.
string Value
Get/set the value of the item.
The ProjectDescriptor class contains all information describing a project, such as its: dataset,...
ValueDescriptorCollection AnalysisItems
Returns the collection of analysis ValueDescriptors of the Project.
string SolverDescription
Get/set the solver description script.
GroupDescriptor Group
Get/set the project group.
string ModelDescription
Get/set the model description script.
DatasetDescriptor DatasetTarget
Get/set the secondary 'target' dataset (if used).
int TotalIterations
Get/set the total iterations.
virtual string GpuOverride
Get/set the GPU ID's to use as an override.
SettingsCaffe Settings
Get/set the settings of the Project.
bool Active
Returns whether or not the project is active.
ParameterDescriptorCollection Parameters
Returns the collection of parameters of the Project.
DatasetDescriptor Dataset
Get/set the dataset used.
The SourceDescriptor class contains all information describing a data source.
bool SaveImagesToFile
Gets whether or not the images are saved to the file system (true), or directly to the database (fals...
The StateDescriptor class contains the information related to the state of a project incuding the sol...
double Accuracy
Returns the accuracy observed while testing.
byte[] State
Get/set the state of a Solver in training.
bool? HasResults
Returns whether or not the state has results (e.g. it has been trained at least to some degree).
byte[] Weights
Get/set the weights of a trained Net.
double Error
Specifies the error observed whiel training.
int Iterations
Specifies the number of iterations run.
The ValueDescriptorCollection class contains a list of ValueDescriptor's.
The descriptors namespace contains all descriptor used to describe various items stored within the da...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
DB_LOAD_METHOD
Defines how to laod the items into the in-memory database.
Definition: Interfaces.cs:154
Phase
Defines the Phase under which to run a Net.
Definition: Interfaces.cs:61
SNAPSHOT_LOAD_METHOD
Defines the snapshot load method.
Definition: Interfaces.cs:204
SNAPSHOT_WEIGHT_UPDATE_METHOD
Defines the snapshot weight update method.
Definition: Interfaces.cs:181
TRAINING_CATEGORY
Defines the category of training.
Definition: Interfaces.cs:34
Stage
Specifies the stage underwhich to run a custom trainer.
Definition: Interfaces.cs:88
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12