2using System.Collections.Generic;
22 public class Net<T> : IDisposable
36 List<Layer<T>> m_rgLayers =
new List<Layer<T>>();
37 List<string> m_rgstrLayerNames =
new List<string>();
38 DictionaryEx<string, int> m_rgLayerNamesIndex =
new DictionaryEx<string, int>(0);
39 List<bool> m_rgbLayerNeedBackward =
new List<bool>();
43 List<string> m_rgstrBlobNames =
new List<string>();
44 DictionaryEx<string, int> m_rgBlobNamesIndex =
new DictionaryEx<string, int>(0);
45 List<bool> m_rgbBlobNeedBackward =
new List<bool>();
50 List<BlobCollection<T>> m_rgcolBottomVecs =
new List<BlobCollection<T>>();
51 List<List<int>> m_rgrgnBottomIdVecs;
52 List<List<bool>> m_rgrgbBottomNeedBackward =
new List<List<bool>>();
55 List<BlobCollection<T>> m_rgcolTopVecs =
new List<BlobCollection<T>>();
56 List<List<int>> m_rgrgnTopIdVecs =
new List<List<int>>();
60 List<double> m_rgdfBlobLossWeights =
new List<double>();
61 List<List<int>> m_rgrgnParamIdVecs =
new List<List<int>>();
62 List<int> m_rgnParamOwners =
new List<int>();
63 List<string> m_rgstrParamDisplayNames =
new List<string>();
64 List<KeyValuePair<int, int>> m_rgParamLayerIndices =
new List<KeyValuePair<int, int>>();
65 DictionaryEx<string, int> m_rgParamNamesIndex =
new DictionaryEx<string, int>(0);
68 List<int> m_rgnNetInputBlobIndices =
new List<int>();
69 List<int> m_rgnNetOutputBlobIndices =
new List<int>();
82 List<int> m_rgnLearnableParamIds =
new List<int>();
85 List<double?> m_rgdfParamsLr =
new List<double?>();
88 List<double?> m_rgdfParamsWeightDecay =
new List<double?>();
91 long m_lMemoryUsed = 0;
94 bool m_bDebugInfo =
false;
106 string m_strBestResultTargetNodeToMask =
null;
107 int m_nBestResultCount = 5;
108 BEST_RESULT_TYPE m_nBestResultType = BEST_RESULT_TYPE.BY_CHANNEL;
110 long m_hWorkspaceData = 0;
111 ulong m_lWorkspaceSizeInBytes = 0;
113 Net<T> m_sharedNet =
null;
114 bool m_bBreakOnFirstNan =
false;
115 bool m_bDetectDetailedNans =
false;
116 bool m_bEnableLayerDebugging =
false;
118 List<Layer<T>> m_rgConnectedLayers =
new List<Layer<T>>();
120 int m_nLastNonFrozenLayerIdx = 0;
121 string m_strDataSource =
null;
122 Layer<T> m_labelMappingLayer =
null;
123 bool m_bFirstForwardInputWarning =
true;
138#pragma warning disable 1591
140 public enum BEST_RESULT_TYPE
146#pragma warning restore 1591
163 m_sharedNet = sharedNet;
167 m_blobWork =
new Blob<T>(cuda, log);
169 m_evtCancel = evtCancel;
177 Init(p, phaseOverride, evtTrainingCompleted);
184 protected virtual void Dispose(
bool bDisposing)
186 foreach (
Layer<T> layer
in m_rgConnectedLayers)
192 m_rgConnectedLayers.Clear();
194 foreach (
Layer<T> layer
in m_rgLayers)
201 if (m_colBlobs !=
null)
212 m_rgcolBottomVecs.
Clear();
219 m_rgcolTopVecs.
Clear();
221 if (m_colNetOutputBlobs !=
null)
224 m_colNetOutputBlobs =
null;
227 if (m_colParams !=
null)
233 if (m_colLearnableParams !=
null)
235 m_colLearnableParams.
Dispose();
236 m_colLearnableParams =
null;
239 if (m_hWorkspaceData != 0)
244 m_hWorkspaceData = 0;
245 m_lWorkspaceSizeInBytes = 0;
248 if (m_blobWork !=
null)
260 if (m_debugBlob !=
null)
262 m_debugBlob.Dispose();
271 for (
int i = 0; i < p.
layer.Count; i++)
274 m_log.
WriteLine(
"WARNING: Layer '" + p.
layer[i].name +
"' uses the LSTM_SIMPLE type, we recommend using the LSTM with CUDNN engine instead.");
277 m_log.
WriteLine(
"WARNING: Layer '" + p.
layer[i].name +
"' uses the LSTM type with the CAFFE engine (which is quite slow), we recommend using the LSTM with CUDNN engine instead.");
291 m_bFirstForwardInputWarning =
true;
295 if (phaseOverride !=
Phase.NONE)
297 m_phase = phaseOverride;
305 m_phaseOriginal = m_phase;
307 scanForRecommendations(p);
318 m_strName = param.
name;
320 DictionaryEx<string, int> blob_name_to_idx =
new DictionaryEx<string, int>(0);
321 List<string> available_blobs =
new List<string>();
323 m_log.
CHECK(param.
input_dim.Count == 0 || param.
input_shape.Count == 0,
"Must specify either input_shape OR depreciated input_dim, not both.");
328 m_log.
CHECK_EQ(param.
input.Count * 4, param.
input_dim.Count,
"Incorrect inpub blob dimension specification.");
338 for (
int input_id = 0; input_id < param.
input.Count; input_id++)
341 AppendTop(param, layer_id, input_id, available_blobs, blob_name_to_idx);
345 m_rgcolBottomVecs =
new List<BlobCollection<T>>();
346 m_rgcolTopVecs =
new List<BlobCollection<T>>();
347 m_rgrgnBottomIdVecs =
new List<List<int>>();
348 m_rgrgnParamIdVecs =
new List<List<int>>();
349 m_rgrgnTopIdVecs =
new List<List<int>>();
350 m_rgrgbBottomNeedBackward =
new List<List<bool>>();
352 Dictionary<string, Layer<T>> rgSyncLayers =
new Dictionary<string, Layer<T>>();
354 for (
int layer_id = 0; layer_id < param.
layer.Count; layer_id++)
358 m_rgrgnBottomIdVecs.Add(
new List<int>());
359 m_rgrgnTopIdVecs.Add(
new List<int>());
360 m_rgrgnParamIdVecs.Add(
new List<int>());
361 m_rgrgbBottomNeedBackward.Add(
new List<bool>());
364 if (param.
layer[layer_id].phase ==
Phase.NONE)
365 param.
layer[layer_id].phase = m_phase;
370 m_log.
CHECK_EQ(layer_param.
propagate_down.Count, layer_param.
bottom.Count,
"propagate_down param must be specified either 0 or bottom.Count times.");
381 if (m_sharedNet !=
null)
399 m_labelMappingLayer = layer1;
401 m_rgLayers.Add(layer1);
403 m_rgstrLayerNames.Add(layer_param.
name);
406 bool need_backward =
false;
409 for (
int bottom_id = 0; bottom_id < layer_param.
bottom.Count; bottom_id++)
411 int blob_id =
AppendBottom(param, layer_id, bottom_id, available_blobs, blob_name_to_idx);
414 need_backward |= m_rgbBlobNeedBackward[blob_id];
417 int num_top = layer_param.
top.Count;
418 for (
int top_id = 0; top_id < num_top; top_id++)
421 if (param.
layer[layer_id] !=
null && param.
layer[layer_id].top[top_id] ==
"null")
424 AppendTop(param, layer_id, top_id, available_blobs, blob_name_to_idx);
429 int nBlobID =
blobs.Count - 1;
430 m_rgnNetInputBlobIndices.Add(nBlobID);
431 m_colNetInputBlobs.
Add(
blobs[nBlobID]);
438 Layer<T> layer = m_rgLayers[layer_id];
443 while (num_top < needed_num_top)
448 AppendTop(param, layer_id, num_top,
null,
null);
454 m_rgLayers[layer_id].SetNetParameterUsed(param);
455 m_rgLayers[layer_id].Setup(m_rgcolBottomVecs[layer_id], m_rgcolTopVecs[layer_id]);
458 m_log.
WriteLine(
"Setting up " + m_rgstrLayerNames[layer_id]);
460 for (
int top_id = 0; top_id < m_rgcolTopVecs[layer_id].Count; top_id++)
462 int nIdx = m_rgrgnTopIdVecs[layer_id][top_id];
464 if (m_rgdfBlobLossWeights.Count <= nIdx)
465 Utility.Resize<
double>(ref m_rgdfBlobLossWeights, nIdx + 1, 0.0);
467 double dfLoss = layer.
loss(top_id);
469 m_rgdfBlobLossWeights[nIdx] = dfLoss;
473 string strOut =
"Top shape: " + m_rgcolTopVecs[layer_id][top_id].shape_string;
476 strOut +=
" with loss weight " + dfLoss.ToString();
481 m_lMemoryUsed += m_rgcolTopVecs[layer_id][top_id].count();
484 m_log.
WriteLine(
"Memory required for data: " + (m_lMemoryUsed *
Utility.BaseTypeSize<T>()).ToString());
487 int num_param_blobs = m_rgLayers[layer_id].blobs.Count();
488 m_log.
CHECK_LE(param_size, num_param_blobs,
"Too many params specified for layer " + layer_param.
name);
492 for (
int param_id = 0; param_id < num_param_blobs; param_id++)
494 ParamSpec param_spec = (param_id < param_size) ? layer_param.
parameters[param_id] : default_param_spec;
495 bool param_need_backward = (param_spec.
lr_mult != 0.0) ? true :
false;
497 need_backward |= param_need_backward;
498 m_rgLayers[layer_id].set_param_propagate_down(param_id, param_need_backward);
501 for (
int param_id = 0; param_id < num_param_blobs; param_id++)
515 List<KeyValuePair<string, Layer<T>>> rgSyncLayers1 = rgSyncLayers.ToList();
516 for (
int i = 0; i < rgSyncLayers1.Count; i++)
518 if (rgSyncLayers1[i].Key == layer_param.
name)
521 m_rgConnectedLayers.Add(layer);
522 rgSyncLayers.Remove(layer_param.
name);
529 m_rgbLayerNeedBackward.Add(need_backward);
533 for (
int top_id = 0; top_id < m_rgrgnTopIdVecs[layer_id].Count; top_id++)
535 int nIdx = m_rgrgnTopIdVecs[layer_id][top_id];
536 m_rgbBlobNeedBackward[nIdx] =
true;
541 if (rgSyncLayers.Count > 0)
543 string strLayer =
"";
545 foreach (KeyValuePair<
string,
Layer<T>> kv
in rgSyncLayers)
547 strLayer += kv.Key +
", ";
550 strLayer = strLayer.TrimEnd(
',',
' ');
551 m_log.
FAIL(
"The following layers are expected to be marked with 'synchronize_target = True': '" + strLayer +
"'.");
560 List<string> blobs_under_loss =
new List<string>();
561 List<string> blobs_skip_backp =
new List<string>();
563 for (
int layer_id = m_rgLayers.Count - 1; layer_id >= 0; layer_id--)
565 bool layer_contributes_loss =
false;
566 bool layer_skip_propagate_down =
true;
568 for (
int top_id = 0; top_id < m_rgcolTopVecs[layer_id].Count; top_id++)
570 int nIdx = m_rgrgnTopIdVecs[layer_id][top_id];
571 string blob_name = m_rgstrBlobNames[nIdx];
573 if (m_rgLayers[layer_id].loss(top_id) != 0 || blobs_under_loss.Contains(blob_name))
574 layer_contributes_loss =
true;
576 if (!blobs_skip_backp.Contains(blob_name))
577 layer_skip_propagate_down =
false;
579 if (layer_contributes_loss && !layer_skip_propagate_down)
585 if (m_rgbLayerNeedBackward[layer_id] && layer_skip_propagate_down)
587 m_rgbLayerNeedBackward[layer_id] =
false;
589 for (
int bottom_id = 0; bottom_id < m_rgcolBottomVecs[layer_id].Count; bottom_id++)
591 m_rgrgbBottomNeedBackward[layer_id][bottom_id] =
false;
595 if (!layer_contributes_loss)
596 m_rgbLayerNeedBackward[layer_id] =
false;
600 if (m_rgbLayerNeedBackward[layer_id])
601 m_log.
WriteLine(m_rgstrLayerNames[layer_id] +
" needs backward computation.");
603 m_log.
WriteLine(m_rgstrLayerNames[layer_id] +
" does not need backward computation.");
606 for (
int bottom_id = 0; bottom_id < m_rgcolBottomVecs[layer_id].Count; bottom_id++)
608 if (layer_contributes_loss)
610 int nIdx = m_rgrgnBottomIdVecs[layer_id][bottom_id];
611 string blob_name = m_rgstrBlobNames[nIdx];
613 blobs_under_loss.Add(blob_name);
617 m_rgrgbBottomNeedBackward[layer_id][bottom_id] =
false;
620 if (!m_rgrgbBottomNeedBackward[layer_id][bottom_id])
622 int nIdx = m_rgrgnBottomIdVecs[layer_id][bottom_id];
623 string blob_name = m_rgstrBlobNames[nIdx];
625 blobs_skip_backp.Add(blob_name);
633 for (
int layer_id = 0; layer_id < m_rgLayers.Count; layer_id++)
635 m_rgbLayerNeedBackward[layer_id] =
true;
637 for (
int bottom_id = 0; bottom_id < m_rgrgbBottomNeedBackward[layer_id].Count; bottom_id++)
639 m_rgrgbBottomNeedBackward[layer_id][bottom_id] = m_rgrgbBottomNeedBackward[layer_id][bottom_id] || m_rgLayers[layer_id].AllowForceBackward(bottom_id);
641 int nIdx = m_rgrgnBottomIdVecs[layer_id][bottom_id];
642 m_rgbBlobNeedBackward[nIdx] = m_rgbBlobNeedBackward[nIdx] || m_rgrgbBottomNeedBackward[layer_id][bottom_id];
645 for (
int param_id = 0; param_id < m_rgLayers[layer_id].blobs.Count; param_id++)
647 m_rgLayers[layer_id].set_param_propagate_down(param_id,
true);
653 foreach (
string blob_name
in available_blobs)
655 m_log.
WriteLine(
"This network produces output " + blob_name);
656 int nIdx = blob_name_to_idx[blob_name];
657 Blob<T> blob = m_colBlobs[nIdx];
659 m_colNetOutputBlobs.
Add(blob);
660 m_rgnNetOutputBlobIndices.Add(nIdx);
663 for (
int blob_id = 0; blob_id < m_rgstrBlobNames.Count; blob_id++)
665 string blob_name = m_rgstrBlobNames[blob_id];
666 m_rgBlobNamesIndex[blob_name] = blob_id;
669 for (
int layer_id = 0; layer_id < m_rgstrLayerNames.Count; layer_id++)
671 string layer_name = m_rgstrLayerNames[layer_id];
672 m_rgLayerNamesIndex[layer_name] = layer_id;
675 if (m_sharedNet ==
null)
681 for (
int i = 0; i < m_rgLayers.Count; i++)
683 m_nLastNonFrozenLayerIdx = i;
685 if (!m_rgLayers[i].layer_param.freeze_learning && m_rgLayers[i].layer_param.type !=
LayerParameter.
LayerType.SPLIT)
690 for (
int i=m_rgLayers.Count-1; i>=0; i--)
700 if (lossLayer !=
null)
702 for (
int i = 0; i < m_rgLayers.Count; i++)
704 if (m_rgLayers[i].layer_param.connect_loss_event)
709 m_bDebugInfo = param.debug_info;
710 m_log.
WriteLine(
"Network initialization done.");
712 catch (Exception excpt)
714 foreach (
Layer<T> layer
in m_rgConnectedLayers)
719 m_rgConnectedLayers.Clear();
721 foreach (
Layer<T> layer
in m_rgLayers)
727 m_rgstrLayerNames.Clear();
728 m_rgLayerNamesIndex.Clear();
729 m_rgbBlobNeedBackward.Clear();
731 m_rgBlobNamesIndex.Clear();
732 m_rgbBlobNeedBackward.Clear();
733 m_rgcolBottomVecs.Clear();
734 m_rgrgbBottomNeedBackward.Clear();
735 m_rgcolTopVecs.Clear();
736 m_rgrgnTopIdVecs.Clear();
737 m_rgdfBlobLossWeights.Clear();
738 m_rgrgnParamIdVecs.Clear();
739 m_rgnParamOwners.Clear();
740 m_rgstrParamDisplayNames.Clear();
741 m_rgParamLayerIndices.Clear();
742 m_rgParamNamesIndex.Clear();
743 m_rgnNetInputBlobIndices.Clear();
744 m_rgnNetOutputBlobIndices.Clear();
745 m_colNetInputBlobs.
Clear();
746 m_colNetOutputBlobs.
Clear();
748 m_colLearnableParams.
Clear();
749 m_rgnLearnableParamIds.Clear();
750 m_rgdfParamsLr.Clear();
751 m_rgdfParamsWeightDecay.Clear();
753 m_bDebugInfo =
false;
764 private void layer_OnGetIteration(
object sender, GetIterationArgs e)
770 private void layer_OnSetWorkspace(
object sender, WorkspaceArgs e)
772 if (e.WorkspaceSizeInBytes == 0)
783 if (e.WorkspaceSizeInBytes > m_lWorkspaceSizeInBytes)
785 m_lWorkspaceSizeInBytes = e.WorkspaceSizeInBytes;
787 if (m_hWorkspaceData != 0)
790 ulong lCount = CudaDnn<T>.ConvertByteSizeToCount(m_lWorkspaceSizeInBytes);
791 m_hWorkspaceData = m_cuda.
AllocMemory((
long)lCount);
797 private void layer_OnGetWorkspace(
object sender, WorkspaceArgs e)
805 e.WorkspaceData = m_hWorkspaceData;
806 e.WorkspaceSizeInBytes = m_lWorkspaceSizeInBytes;
816 Phase phaseOriginal = m_phase;
820 for (
int i = 0; i < m_rgLayers.Count; i++)
822 m_rgLayers[i].SetPhase(
phase);
825 return phaseOriginal;
833 m_phase = m_phaseOriginal;
835 for (
int i = 0; i < m_rgLayers.Count; i++)
837 m_rgLayers[i].SetPhase(m_phase);
846 get {
return m_bBreakOnFirstNan; }
847 set { m_bBreakOnFirstNan = value; }
856 get {
return m_bDetectDetailedNans; }
857 set { m_bDetectDetailedNans = value; }
868 get {
return m_bEnableLayerDebugging; }
871 if (m_bEnableLayerDebugging == value)
874 foreach (
Layer<T> layer
in m_rgLayers)
884 m_bEnableLayerDebugging = value;
886 if (m_bEnableLayerDebugging)
887 m_log.
WriteLine(
"WARNING: Layer debugging enabled, training will be slow.");
889 m_log.
WriteLine(
"Layer debugging disabled.");
893#pragma warning disable 1591
895 public void EnableBestResultMask(
string strTargetNode,
int nBestResultCount = 5, BEST_RESULT_TYPE resultType = BEST_RESULT_TYPE.BY_CHANNEL)
897 m_strBestResultTargetNodeToMask = strTargetNode;
898 m_nBestResultCount = nBestResultCount;
899 m_nBestResultType = resultType;
902 public void DisableBestResultMask()
904 m_strBestResultTargetNodeToMask =
null;
905 m_nBestResultCount = 50;
908#pragma warning restore 1591
917 string strSrc = m_strDataSource;
919 if (m_labelMappingLayer !=
null)
922 if (
string.IsNullOrEmpty(strSrc))
939 string strSrc = m_strDataSource;
941 if (
string.IsNullOrEmpty(strSrc))
958 string strSrc = m_strDataSource;
960 if (
string.IsNullOrEmpty(strSrc))
977 string strSrc = m_strDataSource;
979 if (
string.IsNullOrEmpty(strSrc))
998 foreach (
Layer<T> layer
in m_rgLayers)
1006 return m_lastBatchInput;
1009 private void setInput(BatchInput biInput)
1011 m_lastBatchInput = biInput;
1025 for (
int i = 0; i < param.
layer.Count; i++)
1028 string layer_name = layer_param.
name;
1030 m_log.
CHECK(layer_param.
include.Count == 0 || layer_param.
exclude.Count == 0,
"Specify either include rules or exclude rules; not both.");
1034 bool layer_included = (layer_param.
include.Count == 0) ?
true :
false;
1036 for (
int j = 0; layer_included && j < layer_param.
exclude.Count; j++)
1039 layer_included =
false;
1042 for (
int j = 0; !layer_included & j < layer_param.
include.Count; j++)
1045 layer_included =
true;
1049 param_filtered.
layer.Add(layer_param.
Clone(
true));
1052 return param_filtered;
1072 m_log.
WriteLine(
"The NetState phase (" + state.
phase.ToString() +
") differed from the phase (" + rule.
phase.ToString() +
") specified by a rule in layer " + strLayer);
1082 m_log.
WriteLine(
"The NetState level (" + state.
level.ToString() +
") is below the min_level ( " + rule.
min_level.Value.ToString() +
") specified by a rule in layer " + strLayer);
1092 m_log.
WriteLine(
"The NetState level (" + state.
level.ToString() +
") is above the max_level ( " + rule.
max_level.Value.ToString() +
") specified by a rule in layer " + strLayer);
1099 for (
int i = 0; i < rule.
stage.Count; i++)
1102 bool has_stage =
false;
1104 for (
int j = 0; !has_stage && j < state.
stage.Count; j++)
1115 m_log.
WriteLine(
"The NetState did not contain stage '" + rule.
stage[i] +
"' specified by a rule in layer " + strLayer);
1122 for (
int i = 0; i < rule.
not_stage.Count; i++)
1125 bool has_stage =
false;
1127 for (
int j = 0; !has_stage && j < state.
stage.Count; j++)
1138 m_log.
WriteLine(
"The NetState contained a not_stage '" + rule.
not_stage[i] +
"' specified by a rule in layer " + strLayer);
1154 protected void AppendTop(
NetParameter param,
int layer_id,
int top_id, List<string> available_blobs, DictionaryEx<string, int> blob_name_to_idx)
1160 layer_param = param.
layer[layer_id].Clone(
false);
1162 if (layer_param !=
null)
1164 if (layer_param.
top.Count > top_id)
1165 blob_name = layer_param.
top[top_id];
1167 blob_name =
"(automatic)";
1171 blob_name = param.
input[top_id];
1175 if (blob_name_to_idx !=
null && layer_param !=
null && layer_param.
bottom.Count > top_id && blob_name == layer_param.
bottom[top_id])
1178 m_log.
WriteLine(layer_param.
name +
" -> " + blob_name +
" (in-place)");
1179 int nIdx = blob_name_to_idx[blob_name];
1180 m_rgcolTopVecs[layer_id].Add(m_colBlobs[nIdx]);
1181 m_rgrgnTopIdVecs[layer_id].Add(nIdx);
1183 else if (blob_name_to_idx !=
null && blob_name_to_idx.ContainsKey(blob_name))
1187 m_log.
FAIL(
"Top blob '" + blob_name +
"' produced by multiple sources.");
1194 if (layer_param !=
null)
1197 m_log.
WriteLine(
"Input " + top_id.ToString() +
" -> " + blob_name);
1201 blob_pointer.
Name = blob_name;
1224 if (m_sharedNet !=
null && layer_id >= 0 && layer_id < param.
layer.Count() - 1)
1225 m_sharedNet.
blobs.Share(blob_pointer,
null,
false);
1227 int blob_id = m_colBlobs.
Count;
1228 m_colBlobs.
Add(blob_pointer);
1229 m_rgstrBlobNames.Add(blob_name);
1230 m_rgbBlobNeedBackward.Add(
false);
1232 if (blob_name_to_idx !=
null)
1233 blob_name_to_idx[blob_name] = blob_id;
1250 m_rgnNetInputBlobIndices.Add(blob_id);
1251 m_colNetInputBlobs.
Add(blob_pointer);
1255 m_rgrgnTopIdVecs[layer_id].Add(blob_id);
1256 m_rgcolTopVecs[layer_id].Add(blob_pointer);
1260 if (available_blobs !=
null)
1261 available_blobs.Add(blob_name);
1272 protected int AppendBottom(
NetParameter param,
int layer_id,
int bottom_id, List<string> available_blobs, DictionaryEx<string, int> blob_name_to_idx)
1275 string blob_name = layer_param.
bottom[bottom_id];
1277 if (!available_blobs.Contains(blob_name))
1278 m_log.
FAIL(
"Unknown bottom blob '" + blob_name +
"' (layer '" + layer_param.
name +
"', bottom index " + bottom_id.ToString() +
")");
1280 int blob_id = blob_name_to_idx[blob_name];
1281 m_log.
WriteLine(m_rgstrLayerNames[layer_id] +
" <- " + blob_name);
1283 m_rgcolBottomVecs[layer_id].Add(m_colBlobs[blob_id]);
1284 m_rgrgnBottomIdVecs[layer_id].Add(blob_id);
1285 available_blobs.Remove(blob_name);
1287 bool need_backward = m_rgbBlobNeedBackward[blob_id];
1292 m_rgrgbBottomNeedBackward[layer_id].Add(need_backward);
1306 int param_size = layer_param.
parameters.Count;
1307 string param_name = (param_size > param_id) ? layer_param.
parameters[param_id].name :
"";
1309 if (param_name.Length > 0)
1310 m_rgstrParamDisplayNames.Add(param_name);
1312 m_rgstrParamDisplayNames.Add(param_id.ToString());
1314 int net_param_id = m_colParams.
Count;
1317 Blob<T> learning_param = m_rgLayers[layer_id].blobs[param_id];
1318 learning_param.
freeze_learning = m_rgLayers[layer_id].layer_param.freeze_learning;
1320 m_colParams.
Add(learning_param);
1321 m_rgrgnParamIdVecs[layer_id].Add(net_param_id);
1322 m_rgParamLayerIndices.Add(
new KeyValuePair<int ,int>(layer_id, param_id));
1327 if (param_size == 0 || param_name.Length == 0 || (param_name.Length > 0 && !m_rgParamNamesIndex.ContainsKey(param_name)))
1332 m_rgnParamOwners.Add(-1);
1334 if (param_name.Length > 0)
1335 m_rgParamNamesIndex[param_name] = net_param_id;
1337 int learnable_param_id = m_rgnLearnableParamIds.Count;
1338 m_colLearnableParams.
Add(m_colParams[net_param_id]);
1339 m_rgnLearnableParamIds.Add(learnable_param_id);
1340 m_rgdfParamsLr.Add(param_spec.
lr_mult);
1341 m_rgdfParamsWeightDecay.Add(param_spec.
decay_mult);
1346 int owner_net_param_id = m_rgParamNamesIndex[param_name];
1347 m_rgnParamOwners.Add(owner_net_param_id);
1349 KeyValuePair<int,int> owner_index = m_rgParamLayerIndices[owner_net_param_id];
1350 int owner_layer_id = owner_index.Key;
1351 int owner_param_id = owner_index.Value;
1353 m_log.
WriteLine(
"Sharing parameters '" + param_name +
"' owned by layer '" + m_rgstrLayerNames[owner_layer_id] +
"', param index " + owner_param_id.ToString());
1355 Blob<T> this_blob = m_rgLayers[layer_id].blobs[param_id];
1356 Blob<T> owner_blob = m_rgLayers[owner_layer_id].blobs[owner_param_id];
1357 int param_size2 = layer_param.
parameters.Count;
1362 m_log.
CHECK_EQ(this_blob.
count(), owner_blob.
count(),
"Cannot share param '" + param_name +
"' owned by layer '" + m_rgstrLayerNames[owner_layer_id] +
"' with layer '" + m_rgstrLayerNames[layer_id] +
"'; count mismatch. Owner layer param shape is " + owner_blob.
shape_string +
"; sharing layer shape is " + this_blob.
shape_string);
1367 m_log.
CHECK(
Utility.Compare<
int>(this_blob.
shape(), owner_blob.
shape()),
"Cannot share param '" + param_name +
"' owned by layer '" + m_rgstrLayerNames[owner_layer_id] +
"' with layer '" + m_rgstrLayerNames[layer_id] +
"'; shape mismatch. Owner layer param shape is " + owner_blob.
shape_string +
"; sharing layer expects shape " + this_blob.
shape_string);
1370 int learnable_param_id = m_rgnLearnableParamIds[owner_net_param_id];
1371 m_rgnLearnableParamIds.Add(learnable_param_id);
1373 if (param_spec.
lr_mult != 1.0)
1375 if (m_rgdfParamsLr[learnable_param_id].HasValue)
1376 m_log.
CHECK_EQ(param_spec.
lr_mult, m_rgdfParamsLr[learnable_param_id].Value,
"Shared param '" + param_name +
"' has mismatched lr_mult.");
1378 m_rgdfParamsLr[learnable_param_id] = param_spec.
lr_mult;
1383 if (m_rgdfParamsWeightDecay[learnable_param_id].HasValue)
1384 m_log.
CHECK_EQ(param_spec.
decay_mult, m_rgdfParamsWeightDecay[learnable_param_id].Value,
"Shared param '" + param_name +
"' has mismatched decay_mult.");
1386 m_rgdfParamsWeightDecay[learnable_param_id] = param_spec.
decay_mult;
1404 if (nEnd ==
int.MaxValue)
1405 nEnd = m_rgLayers.Count - 1;
1407 m_log.
CHECK_GE(nStart, 0,
"Start must be >= 0.");
1408 m_log.
CHECK_LT(nEnd, m_rgLayers.Count,
"End must be < the layer count of " + m_rgLayers.Count.ToString());
1411 for (
int i = nStart; i <= nEnd; i++)
1413 double dfLayerLoss = m_rgLayers[i].Forward(m_rgcolBottomVecs[i], m_rgcolTopVecs[i]);
1414 dfLoss += dfLayerLoss;
1422 if (m_strBestResultTargetNodeToMask !=
null && m_rgLayers[i].layer_param.name == m_strBestResultTargetNodeToMask)
1426 m_log.
FAIL(
"Could not find the Best Result Target Node '" + m_strBestResultTargetNodeToMask +
"'!");
1428 if (m_nBestResultType == BEST_RESULT_TYPE.BY_CHANNEL)
1429 blob.KeepBestResultsByChannel(m_nBestResultCount);
1431 blob.KeepBestResultsByWeight(m_nBestResultCount);
1462 return m_colNetOutputBlobs;
1474 if (m_colNetInputBlobs.
Count == 0)
1476 if (m_bFirstForwardInputWarning)
1478 m_log.
WriteLine(
"WARNING: bottom inputs are ignored, for this net does not take input.");
1479 m_bFirstForwardInputWarning =
false;
1484 for (
int i = 0; i < colBottom.
Count && i < m_colNetInputBlobs.
Count; i++)
1486 m_colNetInputBlobs[i].
CopyFrom(colBottom[i],
false, bReshape);
1499 public void Backward(
int nStart =
int.MaxValue,
int nEnd = 0)
1501 if (nStart ==
int.MaxValue)
1502 nStart = m_rgLayers.Count - 1;
1504 m_log.
CHECK_GE(nEnd, 0,
"End must be greater than 0.");
1505 m_log.
CHECK_LT(nStart, m_rgLayers.Count,
"Start must be less than the number of layers (" + m_rgLayers.Count.ToString() +
")");
1507 for (
int i = nStart; i >= nEnd; i--)
1509 if (m_rgbLayerNeedBackward[i])
1511 m_rgLayers[i].Backward(m_rgcolTopVecs[i], m_rgrgbBottomNeedBackward[i], m_rgcolBottomVecs[i]);
1520 double dfAsumData = 0;
1521 double dfAsumDiff = 0;
1522 double dfSumsqData = 0;
1523 double dfSumsqDiff = 0;
1525 for (
int i = 0; i < m_colLearnableParams.
Count; i++)
1527 dfAsumData +=
Utility.ConvertVal<T>(m_colLearnableParams[i].asum_data());
1528 dfAsumDiff +=
Utility.ConvertVal<T>(m_colLearnableParams[i].asum_diff());
1529 dfSumsqData +=
Utility.ConvertVal<T>(m_colLearnableParams[i].sumsq_data());
1530 dfSumsqDiff +=
Utility.ConvertVal<T>(m_colLearnableParams[i].sumsq_diff());
1533 double dfL2NormData = Math.Sqrt(dfSumsqData);
1534 double dfL2NormDiff = Math.Sqrt(dfSumsqDiff);
1536 m_log.
WriteLine(
" [Backward] All net params (data, diff): L1 norm = (" + dfAsumData.ToString() +
", " + dfAsumDiff.ToString() +
"; L2 norm = (" + dfL2NormData.ToString() +
", " + dfL2NormDiff.ToString() +
")");
1546 Blob<T> blob = m_colNetInputBlobs[input_id];
1547 int nIdx = m_rgnNetInputBlobIndices[input_id];
1548 string blob_name = m_rgstrBlobNames[nIdx];
1551 m_log.
WriteLine(
" [Forward] Input " + blob_name +
" data: " + data_abs_val_mean.ToString());
1560 for (
int top_id = 0; top_id < m_rgcolTopVecs[layer_id].Count; top_id++)
1562 Blob<T> blob = m_rgcolTopVecs[layer_id][top_id];
1563 int nIdx = m_rgrgnTopIdVecs[layer_id][top_id];
1564 string blob_name = m_rgstrBlobNames[nIdx];
1566 double data_abs_val_mean = data_asum / blob.
count();
1568 m_log.
WriteLine(
" [Forward] Layer " + m_rgstrLayerNames[layer_id] +
", top blob " + blob_name +
" data: " + data_abs_val_mean.ToString() +
" asum: " + data_asum.ToString());
1571 for (
int param_id = 0; param_id < m_rgLayers[layer_id].blobs.Count; param_id++)
1573 Blob<T> blob = m_rgLayers[layer_id].blobs[param_id];
1574 int net_param_id = m_rgrgnParamIdVecs[layer_id][param_id];
1575 string blob_name = m_rgstrParamDisplayNames[net_param_id];
1577 double data_abs_val_mean = data_asum / blob.
count();
1579 m_log.
WriteLine(
" [Forward] Layer " + m_rgstrLayerNames[layer_id] +
", param blob " + blob_name +
" data: " + data_abs_val_mean.ToString() +
" asum: " + data_asum.ToString());
1591 for (
int bottom_id = 0; bottom_id < bottom_vec.
Count; bottom_id++)
1593 if (!m_rgrgbBottomNeedBackward[layer_id][bottom_id])
1596 Blob<T> blob = bottom_vec[bottom_id];
1597 int nIdx = m_rgrgnBottomIdVecs[layer_id][bottom_id];
1598 string blob_name = m_rgstrBlobNames[nIdx];
1600 double diff_abs_val_mean = diff_asum / blob.
count();
1602 m_log.
WriteLine(
" [Backward] Layer " + m_rgstrLayerNames[layer_id] +
", bottom blob " + blob_name +
" diff: " + diff_abs_val_mean.ToString() +
" asum: " + diff_asum.ToString());
1605 for (
int param_id = 0; param_id < m_rgLayers[layer_id].blobs.Count; param_id++)
1607 if (!m_rgLayers[layer_id].param_propagate_down(param_id))
1610 Blob<T> blob = m_rgLayers[layer_id].blobs[param_id];
1612 double diff_abs_val_mean = diff_asum / blob.
count();
1614 m_log.
WriteLine(
" [Backward] Layer " + m_rgstrLayerNames[layer_id] +
", param blob " + param_id.ToString() +
" diff: " + diff_abs_val_mean.ToString() +
" asum: " + diff_asum.ToString());
1624 Blob<T> blob = m_colBlobs[param_id];
1625 int param_owner = m_rgnParamOwners[param_id];
1626 int nIdx = m_rgParamLayerIndices[param_id].Key;
1627 string layer_name = m_rgstrLayerNames[nIdx];
1628 string param_display_name = m_rgstrParamDisplayNames[param_id];
1630 double diff_abs_val_mean = diff_asum / blob.
count();
1632 if (param_owner < 0)
1635 m_log.
WriteLine(
" [Update] Layer " + layer_name +
", param " + param_display_name +
" data: " + data_abs_val_mean.ToString() +
"; diff: " + diff_abs_val_mean.ToString() +
" asum: " + diff_asum.ToString());
1639 int nIdx2 = m_rgParamLayerIndices[param_owner].Key;
1640 string owner_layer_name = m_rgstrLayerNames[nIdx2];
1641 int nIdx3 = m_rgnParamOwners[param_id];
1642 string param_display_name_owner = m_rgstrParamDisplayNames[nIdx3];
1643 m_log.
WriteLine(
" [Update] Layer " + layer_name +
", param blob " + param_display_name +
" (owned by layer " + owner_layer_name +
", param " + param_display_name_owner +
") diff: " + diff_abs_val_mean.ToString() +
" asum: " + diff_asum.ToString());
1658 int num_source_layers = srcNet.
layers.Count();
1660 for (
int i = 0; i < num_source_layers; i++)
1664 int target_layer_id = 0;
1666 while (target_layer_id != m_rgstrLayerNames.Count && m_rgstrLayerNames[target_layer_id] != source_layer_name)
1671 if (target_layer_id == m_rgstrLayerNames.Count)
1674 m_log.
WriteLine(
"Ignoring source layer " + source_layer_name,
true);
1679 m_log.
WriteLine(
"Copying source layer " + source_layer_name);
1682 m_log.
CHECK_EQ(target_blobs.
Count, source_layer.
blobs.Count,
"Incompatible number of blobs for layer " + source_layer_name);
1684 for (
int j = 0; j < target_blobs.
Count; j++)
1687 if (!target_blobs[j].reshape_when_sharing)
1688 m_log.
CHECK(
Utility.Compare<
int>(target_blobs[j].shape(), source_blob.
shape()),
"Cannot share param " + j.ToString() +
" weights from layer '" + source_layer_name +
"'; shape mismatch. Source param shape is " + source_blob.
shape_string +
"; target param shape is " + target_blobs[j].shape_string);
1690 target_blobs[j].ShareData(source_blob);
1701 m_log.
CHECK_EQ(m_rgLayers.Count, dstNet.m_rgLayers.Count,
"Both networks must have the same number of layers!");
1703 for (
int i = 0; i < m_rgLayers.Count; i++)
1705 m_log.
CHECK_EQ(m_rgLayers[i].internal_blobs.Count, dstNet.m_rgLayers[i].internal_blobs.Count,
"Both networks must have the same number of internal blobs at layer " + i.ToString());
1706 dstNet.m_rgLayers[i].internal_blobs.CopyFrom(m_rgLayers[i].internal_blobs);
1716 int num_source_layers =
layers.Count();
1718 for (
int i = 0; i < num_source_layers; i++)
1722 int target_layer_id = 0;
1724 while (target_layer_id != dstNet.m_rgstrLayerNames.Count && dstNet.m_rgstrLayerNames[target_layer_id] != source_layer_name)
1729 if (target_layer_id == dstNet.m_rgstrLayerNames.Count)
1731 m_log.
WriteLine(
"Ignoring source layer " + source_layer_name,
true);
1735 m_log.
WriteLine(
"Copying source layer " + source_layer_name);
1737 m_log.
CHECK_EQ(target_blobs.
Count, source_layer.
blobs.Count,
"Incompatible number of blobs for layer " + source_layer_name);
1739 for (
int j = 0; j < target_blobs.
Count; j++)
1742 m_log.
CHECK(
Utility.Compare<
int>(target_blobs[j].shape(), source_blob.
shape()),
"Cannot copy param " + j.ToString() +
" weights from layer '" + source_layer_name +
"'; shape mismatch. Source param shape is " + source_blob.
shape_string +
"; target param shape is " + target_blobs[j].shape_string);
1743 target_blobs[j].
CopyFrom(source_blob);
1756 foreach (
Layer<T> sourceLayer
in m_rgLayers)
1760 if (rgLayerNames.ContainsKey(source_layer_name))
1762 string strTargetLayer = rgLayerNames[source_layer_name];
1764 if (strTargetLayer !=
null && strTargetLayer.Length > 0)
1766 foreach (
Layer<T> targetLayer
in dstNet.m_rgLayers)
1770 m_log.
WriteLine(
"Copying source layer " + source_layer_name);
1772 m_log.
CHECK_EQ(target_blobs.
Count, sourceLayer.
blobs.Count,
"Incompatible number of blobs for layer " + source_layer_name);
1775 for (
int i = 0; i < nCount; i++)
1778 m_log.
CHECK(
Utility.Compare<
int>(target_blobs[i].shape(), source_blob.
shape()),
"Cannot copy param " + i.ToString() +
" weights from layer '" + source_layer_name +
"'; shape mismatch. Source param shape is " + source_blob.
shape_string +
"; target param shape is " + target_blobs[i].shape_string);
1781 target_blobs[i].CopyFromAndTransposeHeightWidth(source_blob,
false);
1783 target_blobs[i].
CopyFrom(source_blob,
false,
false);
1802 for (
int i = 0; i < m_rgLayers.Count; i++)
1804 m_rgLayers[i].SetNetReshapeRequest();
1805 m_rgLayers[i].Reshape(m_rgcolBottomVecs[i], m_rgcolTopVecs[i]);
1816 int num_source_layers = param.
layer.Count();
1818 for (
int i = 0; i < num_source_layers; i++)
1821 string source_layer_name = source_layer.
name;
1822 int target_layer_id = 0;
1824 while (target_layer_id != m_rgstrLayerNames.Count && m_rgstrLayerNames[target_layer_id] != source_layer_name)
1829 if (target_layer_id == m_rgstrLayerNames.Count)
1831 m_log.
WriteLine(
"Ignoring source layer " + source_layer_name,
true);
1835 m_log.
WriteLine(
"Copying source layer " + source_layer_name);
1837 m_log.
CHECK_EQ(target_blobs.
Count, source_layer.
blobs.Count,
"Incompatible number of blobs for layer " + source_layer_name);
1839 for (
int j = 0; j < target_blobs.
Count; j++)
1841 if (!target_blobs[j].ShapeEquals(source_layer.
blobs[j]))
1845 m_log.
FAIL(
"Cannot copy param " + j.ToString() +
" weights from layer " + source_layer_name +
"; shape mismatch. Source param shape is " + source_blob.
shape_string +
"; target param shape is " + target_blobs[j].shape_string +
". To learn this layer's arameters from scratch rather than copying from the saved net, rename the layer.");
1848 target_blobs[j].FromProto(source_layer.
blobs[j],
false);
1858 get {
return m_param; }
1871 foreach (
Layer<T> layer
in m_rgLayers)
1873 if (layer.
blobs.Count > 0)
1898 for (
int i = 0; i < m_colLearnableParams.
Count; i++)
1900 m_colLearnableParams[i].Update();
1909 for (
int i = 0; i < m_colLearnableParams.
Count; i++)
1911 Blob<T> blob = m_colLearnableParams[i];
1925 for (
int i = 0; i < m_colParams.
Count; i++)
1927 if (m_rgnParamOwners[i] < 0)
1930 int nIdx = m_rgnParamOwners[i];
1931 m_colParams[i].ShareData(m_colParams[nIdx]);
1932 m_colParams[i].ShareDiff(m_colParams[nIdx]);
1948 Forward(colBottom, out dfLocalLoss);
1950 if (m_bBreakOnFirstNan)
1955 if (strFirstNan !=
null)
1961 Backward(
int.MaxValue, m_nLastNonFrozenLayerIdx);
1972 get {
return m_strName; }
1980 get {
return m_rgstrLayerNames; }
1988 get {
return m_rgstrBlobNames; }
1996 get {
return m_colBlobs; }
2004 get {
return m_rgLayers; }
2012 get {
return m_phase; }
2021 get {
return m_rgcolBottomVecs; }
2030 get {
return m_rgcolTopVecs; }
2040 m_log.
CHECK_GE(layer_id, 0,
"Invalid layer id.");
2041 m_log.
CHECK_LT(layer_id, m_rgrgnTopIdVecs.Count,
"Invalid layer id.");
2042 return m_rgrgnTopIdVecs[layer_id];
2052 m_log.
CHECK_GE(layer_id, 0,
"Invalid layer id.");
2053 m_log.
CHECK_LT(layer_id, m_rgrgnBottomIdVecs.Count,
"Invalid layer id.");
2054 return m_rgrgnBottomIdVecs[layer_id];
2062 get {
return m_rgrgbBottomNeedBackward; }
2070 get {
return m_rgdfBlobLossWeights; }
2078 get {
return m_rgbLayerNeedBackward; }
2086 get {
return m_colParams; }
2110 m_colLearnableParams = col;
2118 get {
return m_colLearnableParams; }
2126 get {
return m_rgdfParamsLr; }
2134 get {
return m_rgdfParamsWeightDecay; }
2142 get {
return m_rgParamNamesIndex; }
2150 get {
return m_rgnParamOwners; }
2158 get {
return m_rgstrParamDisplayNames; }
2169 foreach (
Blob<T> blob
in m_colParams)
2171 if (blob.
Name == strName)
2175 if (bThrowExceptionOnError)
2176 m_log.
FAIL(
"Unknown parameter blob name '" + strName +
"'");
2186 get {
return m_colNetInputBlobs.
Count; }
2194 get {
return m_colNetOutputBlobs.
Count; }
2202 get {
return m_colNetInputBlobs; }
2210 get {
return m_colNetOutputBlobs; }
2218 get {
return m_rgnNetOutputBlobIndices; }
2226 get {
return m_rgnNetInputBlobIndices; }
2236 return m_rgBlobNamesIndex.ContainsKey(strBlobName);
2251 int nIdx = m_rgBlobNamesIndex[strName];
2252 blob_ptr = m_colBlobs[nIdx];
2256 if (bThrowExceptionOnError)
2257 m_log.
FAIL(
"Unknown blob name " + strName);
2273 return m_rgBlobNamesIndex[strName];
2283 return m_rgLayerNamesIndex.ContainsKey(strLayer);
2298 int nIdx = m_rgLayerNamesIndex[strLayer];
2299 layer_ptr = m_rgLayers[nIdx];
2303 if (bThrowExceptionOnError)
2304 m_log.
FAIL(
"Unknown layer name " + strLayer);
2320 return m_rgLayerNamesIndex[strLayer];
2332 m_bDebugInfo = bVal;
2352 DictionaryEx<string, KeyValuePair<int, int>> blob_name_to_last_top_idx =
new DictionaryEx<string,KeyValuePair<int,int>>(
new KeyValuePair<int,int>(-1, -1));
2353 DictionaryEx<KeyValuePair<int, int>, KeyValuePair<int, int>> bottom_idx_to_source_top_idx =
new DictionaryEx<KeyValuePair<int,int>,KeyValuePair<int,int>>(
new KeyValuePair<int,int>(-1, -1));
2354 DictionaryEx<KeyValuePair<int, int>,
int> top_idx_to_bottom_count =
new DictionaryEx<KeyValuePair<int,int>,
int>(0);
2355 DictionaryEx<KeyValuePair<int, int>,
double> top_idx_to_loss_weight =
new DictionaryEx<KeyValuePair<int,int>,
double>(0);
2356 DictionaryEx<KeyValuePair<int, int>,
int> top_idx_to_bottom_split_idx =
new DictionaryEx<KeyValuePair<int,int>,
int>(0);
2357 DictionaryEx<int, string> layer_idx_to_layer_name =
new DictionaryEx<int,string>(
"");
2359 layer_idx_to_layer_name[-1] =
"input";
2363 for (
int i = 0; i < param.
input.Count; i++)
2365 string blob_name = param.
input[i];
2366 blob_name_to_last_top_idx[blob_name] =
new KeyValuePair<int, int>(-1, i);
2369 for (
int i = 0; i < param.
layer.Count; i++)
2372 layer_idx_to_layer_name[i] = layer_param.
name;
2374 for (
int j = 0; j < layer_param.
bottom.Count; j++)
2376 string blob_name = layer_param.
bottom[j];
2378 if (!blob_name_to_last_top_idx.ContainsKey(blob_name))
2379 m_log.
FAIL(
"Unknown bottom blob '" + blob_name +
"' (layer '" + layer_param.
name +
"', bottom index " + j.ToString() +
")");
2381 KeyValuePair<int, int> bottom_idx =
new KeyValuePair<int, int>(i, j);
2382 KeyValuePair<int, int> top_idx = blob_name_to_last_top_idx[blob_name];
2383 bottom_idx_to_source_top_idx[bottom_idx] = top_idx;
2384 top_idx_to_bottom_count[top_idx]++;
2387 for (
int j = 0; j < layer_param.
top.Count; j++)
2389 string blob_name = layer_param.
top[j];
2390 blob_name_to_last_top_idx[blob_name] =
new KeyValuePair<int, int>(i, j);
2395 int last_loss = Math.Min(layer_param.
loss_weight.Count, layer_param.
top.Count);
2397 for (
int j = 0; j < last_loss; j++)
2399 string blob_name = layer_param.
top[j];
2400 KeyValuePair<int, int> top_idx = blob_name_to_last_top_idx[blob_name];
2401 top_idx_to_loss_weight[top_idx] = layer_param.
loss_weight[j];
2403 if (top_idx_to_loss_weight[top_idx] != 0)
2404 top_idx_to_bottom_count[top_idx]++;
2410 for (
int i = 0; i < param.
input.Count; i++)
2412 int split_count = top_idx_to_bottom_count[
new KeyValuePair<int, int>(-1, i)];
2414 if (split_count > 1)
2416 string layer_name = layer_idx_to_layer_name[-1];
2417 string blob_name = param.
input[i];
2418 double kZeroLossWeight = 0;
2419 LayerParameter split_layer_param = CreateSplitLayer(layer_name, blob_name, i, split_count, kZeroLossWeight);
2420 param_split.
layer.Add(split_layer_param);
2424 for (
int i = 0; i < param.
layer.Count; i++)
2427 param_split.
layer.Add(layer_param);
2430 for (
int j = 0; j < layer_param.
bottom.Count; j++)
2432 KeyValuePair<int, int> top_idx = bottom_idx_to_source_top_idx[
new KeyValuePair<int, int>(i, j)];
2433 int split_count = top_idx_to_bottom_count[top_idx];
2435 if (split_count > 1)
2437 string layer_name = layer_idx_to_layer_name[top_idx.Key];
2438 string blob_name = layer_param.
bottom[j];
2440 layer_param.
bottom[j] = SplitBlobName(layer_name, blob_name, top_idx.Value, top_idx_to_bottom_split_idx[top_idx]++);
2446 for (
int j = 0; j < layer_param.
top.Count; j++)
2448 KeyValuePair<int, int> top_idx =
new KeyValuePair<int, int>(i, j);
2449 int split_count = top_idx_to_bottom_count[top_idx];
2451 if (split_count > 1)
2453 string layer_name = layer_idx_to_layer_name[i];
2454 string blob_name = layer_param.
top[j];
2455 double loss_weight = top_idx_to_loss_weight[top_idx];
2456 LayerParameter split_layer_param = CreateSplitLayer(layer_name, blob_name, j, split_count, loss_weight);
2457 param_split.
layer.Add(split_layer_param);
2459 if (loss_weight != 0)
2462 top_idx_to_bottom_split_idx[top_idx]++;
2471 private LayerParameter CreateSplitLayer(
string layer_name,
string blob_name,
int blob_idx,
int split_count,
double loss_weight)
2474 split_layer_param.
bottom.Add(blob_name);
2476 for (
int k = 0; k < split_count; k++)
2478 split_layer_param.
top.Add(SplitBlobName(layer_name, blob_name, blob_idx, k));
2480 if (loss_weight != 0)
2489 return split_layer_param;
2492 private string SplitLayerName(
string layer_name,
string blob_name,
int blob_idx)
2494 return blob_name +
"_" + layer_name +
"_" + blob_idx.
ToString() +
"_split";
2497 private string SplitBlobName(
string layer_name,
string blob_name,
int blob_idx,
int split_idx)
2499 return blob_name +
"_" + layer_name +
"_" + blob_idx.ToString() +
"_split_" + split_idx.ToString();
2510 public void LoadWeights(
byte[] rgWeights,
IXPersist<T> persist, List<string> inputWtInfo =
null, List<string> targetWtInfo =
null,
string strSkipBlobType =
null)
2512 if (rgWeights ==
null)
2515 List<string> rgExpectedShapes =
new List<string>();
2518 foreach (
Blob<T> b
in m_colLearnableParams)
2523 if (inputWtInfo !=
null && inputWtInfo.Count == 0)
2526 if (targetWtInfo !=
null && targetWtInfo.Count == 0)
2527 targetWtInfo =
null;
2529 bool bSizeToFit = (inputWtInfo !=
null && targetWtInfo !=
null) ?
true :
false;
2531 persist.LoadWeights(rgWeights, rgExpectedShapes, m_colLearnableParams, bSizeToFit, out bLoadedDiffs, inputWtInfo, targetWtInfo, strSkipBlobType);
2543 foreach (
Blob<T> blob
in m_colLearnableParams)
2545 foreach (
Layer<T> layer
in m_rgLayers)
2547 if (layer.
blobs.Contains(blob))
2552 return persist.SaveWeights(m_colLearnableParams, bSaveDiff);
2564 if (layer.
blobs.Contains(b))
2578 for (
int i = 0; i <
layers.Count; i++)
2596 if (blob.
Name == strName)
2600 foreach (
Layer<T> layer
in m_rgLayers)
2604 if (blob.
Name == strName)
2610 if (blob.
Name == strName)
2627 for (
int i = 0; i < m_rgLayers.Count; i++)
2629 if (m_rgLayers[i].layer_param.name == strLayer)
2636 return m_rgcolBottomVecs[nLayerIdx];
2648 for (
int i = 0; i < m_rgLayers.Count; i++)
2650 if (m_rgLayers[i].layer_param.name == strLayer)
2657 return m_rgcolTopVecs[nLayerIdx];
2666 if (m_rgLayers.Count == 0)
2669 int nLayerIdx = m_rgLayers.Count - 1;
2670 Layer<T> layer = m_rgLayers[nLayerIdx];
2675 layer = m_rgLayers[nLayerIdx];
2694 if (m_blobWork ==
null)
2695 m_blobWork =
new common.
Blob<T>(m_cuda, m_log);
2699 for (
int i = 0; i < m_rgLayers.Count; i++)
2701 debugInfo.Add(m_rgLayers[i], m_rgcolBottomVecs[i], m_rgcolTopVecs[i]);
2731 foreach (
Layer<T> layer
in m_rgLayers)
2733 if (rgstrLayers ==
null || rgstrLayers.Length == 0 || rgstrLayers.Contains(layer.
layer_param.
name))
2750 if (!type.HasValue &&
string.IsNullOrEmpty(strName))
2751 throw new Exception(
"You must specify either a layer type or name, or both.");
2753 foreach (
Layer<T> layer
in m_rgLayers)
2755 bool bTypeMatch = !type.HasValue;
2756 bool bNameMatch =
string.IsNullOrEmpty(strName);
2758 if (type.HasValue && layer.
type == type.Value)
2761 if (!
string.IsNullOrEmpty(strName) && layer.
layer_param.
name == strName)
2764 if (bTypeMatch && bNameMatch)
2778 List<Layer<T>> rgLayers =
new List<Layer<T>>();
2780 foreach (
Layer<T> layer
in m_rgLayers)
2782 if (layer.
type == type)
2783 rgLayers.Add(layer);
2808 for (
int i = m_rgLayers.Count - 1; i >= 0; i--)
2810 if (m_rgLayers[i].type == type)
2811 return m_rgLayers[i];
2822 get {
return m_cuda; }
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
bool IsEnabled
Returns whether or not the Log is enabled.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
void CHECK_EQ(double df1, double df2, string str)
Test whether one number is equal to another.
void CHECK_LE(double df1, double df2, string str)
Test whether one number is less than or equal to another.
void CHECK_GE(double df1, double df2, string str)
Test whether one number is greater than or equal to another.
void CHECK_LT(double df1, double df2, string str)
Test whether one number is less than another.
The Utility class provides general utility funtions.
The BlobCollection contains a list of Blobs.
void Dispose()
Release all resource used by the collection and its Blobs.
void Add(Blob< T > b)
Add a new Blob to the collection.
int Count
Returns the number of items in the collection.
void Clear(bool bDispose=false)
Remove all items from the collection.
void CopyFrom(BlobCollection< T > bSrc, bool bCopyDiff=false)
Copy the data or diff from another BlobCollection into this one.
The Blob is the main holder of data that moves through the Layers of the Net.
Blob(CudaDnn< T > cuda, Log log, bool bIncludeDiff=true, bool bUseHalfSize=false)
The Blob constructor.
object Tag
Returns a user defined object associated with the Blob.
string shape_string
Returns a string describing the Blob's shape.
T asum_diff()
Compute the sum of absolute values (L1 norm) of the diff.
void Reshape(int nNum, int nChannels, int nHeight, int nWidth, bool? bUseHalfSize=null)
DEPRECIATED; use
void FromProto(BlobProto bp, bool bReshape=true)
Create a new Blob from a given BlobProto.
BlobProto ToProto(bool bWriteDiff=false)
Writes the Blob to a new BlobProto.
bool freeze_learning
Specifies whether or not the diff is applied to the data during Update. When freeze learning = true,...
List< int > shape()
Returns an array where each element contains the shape of an axis of the Blob.
T asum_data()
Compute the sum of absolute values (L1 norm) of the data.
int count()
Returns the total number of items in the Blob.
string Name
Get/set the name of the Blob.
virtual void Dispose(bool bDisposing)
Releases all resources used by the Blob (including both GPU and Host).
void SetDiff(double dfVal, int nIdx=-1)
Either sets all of the diff items in the Blob to a given value, or alternatively only sets a single i...
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
void ResetGhostMemory()
Resets the ghost memory by enabling it if this instance was configured to use ghost memory.
void FreeMemory(long hMem)
Free previously allocated GPU memory.
void SynchronizeDevice()
Synchronize the operations on the current device.
long AllocMemory(List< double > rg)
Allocate a block of GPU memory and copy a list of doubles to it.
void DisableGhostMemory()
Disables the ghost memory, if enabled.
The GetWorkBlobArgs are passed to the Layer::OnGetWorkBlob event which is supported for debugging onl...
Blob< T > Blob
Specifies the blob.
Connects Layer's together into a direct acrylic graph (DAG) specified by a NetParameter
bool has_layer(string strLayer)
Returns whether or not the Net has a given Layer by its name.
int num_outputs
Returns the number of outputs.
List< Layer< T > > layers
Returns the layers.
int layer_index_by_name(string strLayer)
Returns a Layer's index given its name.
void Reshape()
Reshape all layers from the bottom to the top.
double ForwardFromTo(int nStart=0, int nEnd=int.MaxValue)
The FromTo variant of forward and backward operate on the (topological) ordering by which the net is ...
void CopyInternalBlobsTo(Net< T > dstNet)
Copy the internal blobs from one net to another.
BlobCollection< T > parameters
Returns the parameters.
List< bool > layer_need_backward
Returns a collection of items that tell whether each layer nees a backward pass or not.
BlobCollection< T > Forward()
Run forward with the input Blob's already fed separately.
Layer< T > FindLayer(string strType, string strName)
Find the layer with the matching type, name and or both.
List< string > layer_names
Returns the layer names.
bool EnableBreakOnFirstNaN
Enable/disable break the first NaN functionality where training stops immediately upon detecting a Na...
List< int > input_blob_indices
Returns a list of the input Blob indexes.
bool EnableDetailedNanDetection
Enable/disable whether or not detailed nans are detected - this will make debugging slower and is onl...
void BackwardDebugInfo(int layer_id)
Helper for displaying debug info in Backward.
string LabelQueryEpochs
Return the label query epochs for the active datasource.
void SetLearnedParameters(BlobCollection< T > col)
Sets the learned parameters.
BlobCollection< T > input_blobs
Returns the collection of input Blobs.
int FindLayerIndexOwningBlob(Blob< T > b)
Finds the index of the Layer that owns a given Blob.
void SetEnablePassthrough(bool bEnable)
Enables/disables passthrough on each layer of the net.
string ActiveLabelCounts
Returns the active label counts observed during training.
bool has_blob(string strBlobName)
Returns whether or not the Net contains a given Blob.
void CopyTrainedLayersTo(Net< T > dstNet)
Copies the trained layer of this Net to another Net.
Layer< T > FindLastLayer(LayerParameter.LayerType type)
Find the last layer with the matching type.
void set_debug_info(bool bVal)
Sets the debug information flag.
bool ForwardBackward(BlobCollection< T > colBottom, out double dfLocalLoss, TRAIN_STEP step=TRAIN_STEP.NONE)
Runs a Forward pass followed by a Backward pass.
string BoostQueryHitPercents
Return the boost query hit percentages for the active datasource.
void CopyTrainedLayersFrom(NetParameter param)
For an already initialized net, CopyTrainedLayersFrom copies the already trained layers from another ...
void ShareWeights()
Shares weight data of owner blobs with shared blobs.
NetParameter InsertSplits(NetParameter param)
Create a new NetParameter and insert splits into it based on a given NetParameter.
void CopyTrainedLayersTo(Net< T > dstNet, DictionaryEx< string, string > rgLayerNames, bool bTranspose)
Copies the trained layers of this Net to another Net.
Layer< T > layer_by_name(string strLayer, bool bThrowExceptionOnError=true)
Returns a Layer given its name.
void Backward(int nStart=int.MaxValue, int nEnd=0)
The network backward should take no input and output, since it solely computes the gradient w....
int AppendBottom(NetParameter param, int layer_id, int bottom_id, List< string > available_blobs, DictionaryEx< string, int > blob_name_to_idx)
Append a new bottom blob to the net.
Phase phase
Returns the network phase: TRAIN or TEST
string GetDataSource()
Returns the data source used by the network.
BlobCollection< T > Forward(out double dfLoss)
Run forward with the input Blob's already fed separately.
bool EnableLayerDebugging
Enable/disable layer debugging which causes each layer to check for NAN/INF on each forward/backward ...
void RestorePhase()
Restore the network phase to its original state.
DebugInformation< T > GetDebugInformation(bool bDetectNans)
Returns the DebugInformation for the Net.
BlobCollection< T > FindBottomBlobsOfLayer(string strLayer)
Returns the collection of bottom blobs for a given layer.
virtual void Dispose(bool bDisposing)
Releases all resources (GPU and Host) used by the Net.
List< double?> params_lr
Returns the learnable parameter learning rate multipliers.
void LoadWeights(byte[] rgWeights, IXPersist< T > persist, List< string > inputWtInfo=null, List< string > targetWtInfo=null, string strSkipBlobType=null)
Loads new weights into the Net.
int num_inputs
Returns the number of inputs.
NetParameter ToProto(bool bIncludeBlobs)
Writes the net to a proto.
void AppendTop(NetParameter param, int layer_id, int top_id, List< string > available_blobs, DictionaryEx< string, int > blob_name_to_idx)
Append a new input or top blob to the net.
Blob< T > FindBlob(string strName)
Finds a Blob in the Net by name.
bool StateMeetsRule(NetState state, NetStateRule rule, string strLayer)
Returns whether NetState state meets NetStateRule rule.
byte[] SaveWeights(IXPersist< T > persist, bool bSaveDiff=false)
Save the weights to a byte array.
Layer< T > FindLayer(LayerParameter.LayerType? type, string strName)
Find the layer with the matching type, name and or both.
BlobCollection< T > output_blobs
Returns the collection of output Blobs.
List< string > blob_names
Returns the blob names.
void ClearParamDiffs()
Zero out the diffs of all netw parameters. This should be run before Backward.
Blob< T > param_by_name(string strName, bool bThrowExceptionOnError=true)
Returns a parameter given its name.
EventHandler< WorkspaceArgs > OnSetWorkspace
Specifies the OnSetWorkspace event that fires when the setWorkspace() function is called by a layer t...
Phase SetPhase(Phase phase)
Change the phase of the network.
List< List< bool > > bottom_need_backward
Returns the collection of lists that tell whether or not the bottom of each layer needs a backward pa...
void InputDebugInfo(int input_id)
Helper for displaying debug info in Forward about input blobs.
BlobCollection< T > learnable_parameters
Returns the learnable parameters.
BlobCollection< T > layer_blobs(string strLayerName)
Returns the collection of Blobs internal to a Layer.
void AppendParam(NetParameter param, int layer_id, int param_id)
Append a new parameter blob to the net.
DictionaryEx< string, int > param_names_index
Returns the dictionary look for parameter names to their indexes.
Blob< T > FindLossBottomBlob()
Find the bottom blob of the Loss layer if it exists, otherwise null is returned.
List< double > blob_loss_weights
Returns the collection of blob loss weights.
NetParameter net_param
Returns the net parameter.
Net(CudaDnn< T > cuda, Log log, NetParameter p, CancelEvent evtCancel, IXDatabaseBase db, Phase phaseOverride=Phase.NONE, AutoResetEvent evtTrainingCompleted=null, Net< T > sharedNet=null, onGetWorkspace getws=null, onSetWorkspace setws=null)
The Net constructor.
void Dispose()
Releases all resources (GPU and Host) used by the Net.
Blob< T > blob_by_name(string strName, bool bThrowExceptionOnError=true)
Returns a blob given its name.
string name
Returns the network name.
void ShareTrainedLayersWith(Net< T > srcNet, bool bEnableLog=false)
For an already initialized net, implicitly compies (i.e., using no additional memory) the pre-trained...
BlobCollection< T > blobs
Returns the blobs.
BlobCollection< T > Forward(BlobCollection< T > colBottom, out double dfLoss, bool bReshape=false)
Run forward using a set of bottom blobs and return the result.
int blob_index_by_name(string strName)
Returns the index of a blob given its name.
string LabelQueryHitPercents
Return the label query hit percentages for the active datasource.
List< int > bottom_ids(int layer_id)
Returns the ids of the bottom blobs of layer i.
bool ReInitializeParameters(WEIGHT_TARGET target, params string[] rgstrLayers)
Re-initializes the blobs and each of the specified layers by re-running the filler (if any) specified...
EventHandler< GetIterationArgs > OnGetIteration
Specifies the OnGetIteration event that fires when a layer needs to get the current iteration from th...
Layer< T > FindLayerOwningBlob(Blob< T > b)
Finds the Layer that owns a given Blob.
void UpdateDebugInfo(int param_id)
Helper for displaying debug info in Update.
List< Layer< T > > FindLayers(LayerParameter.LayerType type)
Find the layers with the matching type.
List< int > top_ids(int layer_id)
Returns the ids of the top blobs of layer i.
List< double?> params_weight_decay
Returns the learnable parameter decay multipliers.
EventHandler< WorkspaceArgs > OnGetWorkspace
Specifies the OnGetWorkspace event that fires when the getWorkspace() function is called by a layer t...
void ForwardDebugInfo(int layer_id)
Helper for displaying debug info in Forward.
void Update()
Updates the network weights based on the diff values computed.
NetParameter FilterNet(NetParameter param)
Removes layers that the user specified should be excluded given the current phase,...
List< BlobCollection< T > > top_vecs
Returns the top vecs for each layer – usually y ou won't need this unless you do per-layer checks suc...
BlobCollection< T > FindTopBlobsOfLayer(string strLayer)
Returns the collection of top blobs for a given layer.
List< int > param_owners
Returns the list of parameter owner indexes.
List< int > output_blob_indices
Returns a list of the output Blob indexes.
List< BlobCollection< T > > bottom_vecs
Returns the bottom vecs for each layer – usually you won't need this unless you do per-layer checks s...
void Init(NetParameter p, Phase phaseOverride=Phase.NONE, AutoResetEvent evtTrainingCompleted=null)
Initialize a network with a NetParameter.
List< string > param_display_names
Returns the list of parameter display names.
CudaDnn< T > Cuda
Returns the instance of CudaDnn used by this network.
The DataLayer loads data from the IXImageDatabase database. This layer is initialized with the MyCaff...
/b DEPRECIATED (use DataLayer DataLabelMappingParameter instead) The LabelMappingLayer converts origi...
An interface for the units of computation which can be composed into a Net.
EventHandler< WorkspaceArgs > OnGetWorkspace
Specifies the OnGetWorkspace event that fires when the getWorkspace() function is called by a layer t...
virtual void SetOnDebug(EventHandler< GetWorkBlobArgs< T > > fn)
Set the OnDebug event.
virtual bool AutoTopBlobs
Return whether "anonymous" top (output) Blobs are created automatically by the Layer.
double loss(int nTopIdx)
Returns the scalar loss associated with the top Blob at a given index.
void SetEnablePassthrough(bool bEnable)
Enables/disables the pass-through mode.
virtual bool ReInitializeParameters(WEIGHT_TARGET target)
Re-initialize the parameters of the layer.
EventHandler< GetIterationArgs > OnGetIteration
Specifies the OnGetIteration event that fires when a layer needs to get the current iteration from th...
LayerParameter.? LayerType parent_layer_type
Optionally, specifies the parent layer type (e.g. LOSS, etc.)
LayerParameter.LayerType type
Returns the LayerType of this Layer.
virtual int ExactNumTopBlobs
Returns the exact number of top (output) Blobs required by the Layer, or -1 if no exact number is req...
void Dispose()
Releases all GPU and host resources used by the Layer.
virtual int MinTopBlobs
Returns the minimum number of top (output) Blobs required by the Layer, or -1 if no minimum number is...
virtual void ResetOnDebug(EventHandler< GetWorkBlobArgs< T > > fn)
Reset the OnDebug event, disabling it.
EventHandler< WorkspaceArgs > OnSetWorkspace
Specifies the OnSetWorkspace event that fires when the setWorkspace() function is called by a layer t...
static Layer< T > Create(CudaDnn< T > cuda, Log log, LayerParameter p, CancelEvent evtCancel, IXDatabaseBase db=null, TransferInput trxinput=null)
Create a new Layer based on the LayerParameter.
LayerParameter layer_param
Returns the LayerParameter for this Layer.
virtual void ConnectLoss(LossLayer< T > layer)
Called to connect the loss OnLoss event to a specified layer (typically the data layer).
BlobCollection< T > blobs
Returns the collection of learnable parameter Blobs for the Layer.
BlobCollection< T > internal_blobs
Returns the collection of internal Blobs used by the Layer.
The LayerParameterEx class is used when sharing another Net to conserve GPU memory and extends the La...
The LossLayer provides an interface for Layer's that take two blobs as input – usually (1) prediction...
string synchronize_with
(optional, default = null) Specifies a secondary (target) dataset to syncrhonize with.
string source
When used with the DATA parameter, specifies the data 'source' within the database....
Specifies whether to use the NVIDIA cuDnn version or Caffe version of a given forward/backward operat...
Engine
Defines the type of engine to use.
Specifies the base parameter for all layers.
List< ParamSpec > parameters
Specifies the ParamSpec parameters of the LayerParameter.
string name
Specifies the name of this LayerParameter.
List< double > loss_weight
Specifies the loss weight.
LayerType type
Specifies the type of this LayerParameter.
List< bool > propagate_down
Specifies whether or not the LayerParameter (or protions of) should be backpropagated.
List< NetStateRule > include
Specifies the NetStateRule's for which this LayerParameter should be included.
int GetParameterCount()
Returns the number of ParamSpec parameters used by the layer.
List< NetStateRule > exclude
Specifies the NetStateRule's for which this LayerParameter should be excluded.
List< string > top
Specifies the active top connections (in the bottom, out the top)
int solver_count
Returns the number of Solvers participating in a multi-GPU session for which the Solver using this La...
int solver_rank
Returns the SolverRank of the Solver using this LayerParameter (if any).
DataParameter data_param
Returns the parameter set when initialized with LayerType.DATA
List< string > bottom
Specifies the active bottom connections (in the bottom, out the top).
LayerType
Specifies the layer type.
override string ToString()
Returns a string representation of the LayerParameter.
static ? LayerType GetType(string strType)
Converts the string type into a LayerType, or null if no match is found.
List< BlobProto > blobs
Specifies the blobs of the LayerParameter.
virtual LayerParameter Clone(bool bCloneBlobs)
Creates a new copy of this instance of the parameter.
Specifies the parameters use to create a Net
NetState state
The current 'state' of the network, including the phase, level and stage. Some layers may be included...
List< string > input
The input blobs to the network.
bool force_backward
Whether the network will force every layer to carry out backward operation. If set False,...
string DebugString()
Returns a debug string for the network.
List< int > input_dim
DEPRECIATED - 4D input dimensions - use 'input_shape' instead. If specified, for each input blob ther...
string name
The name of the network.
List< LayerParameter > layer
The layers that make up the net. Each of their configurations, including connectivity and behavior,...
NetParameter Clone(bool bCloneLayers=true, int? nSolverCount=null, int? nSolverRank=null)
Creates a new copy of this instance of the parameter.
List< BlobShape > input_shape
The shape of the input blobs.
Specifies the NetState which includes the phase, level and stage for which a given Net is to run unde...
int level
Specifies the level of the NetState.
Phase phase
Specifies the Phase of the NetState.
List< string > stage
Specifies the stages of the NetState.
Specifies a NetStateRule used to determine whether a Net falls within a given include or exclude patt...
List< string > stage
Customizable sets of stages to include. The net must have ALL of the specified stages and NONE of the...
int? min_level
Set the minimum levels in which the layer should be used. Leave undefined to meet the rule regardless...
Phase phase
Set phase to require the NetState to have a particular phase (TRAIN or TEST) to meet this rule.
int? max_level
Set the maximum levels in which the layer should be used. Leave undefined to meet the rule regardless...
List< string > not_stage
Customizable sets of stages to exclude. The net must have ALL of the specified stages and NONE of the...
Specifies training parameters (multipliers on global learning constants, and the name of other settin...
double decay_mult
Specifies the multiplier used on the global weight decay for this parameter.
DimCheckMode
Defines the dimension check mode.
double lr_mult
Specifies the multiplier used on the global learning rate for this parameter.
The IXDatabaseBase interface defines the general interface to the in-memory database.
DB_VERSION GetVersion()
Returns the version of the MyCaffe Image Database being used.
The IXImageDatabaseBase interface defines the general interface to the in-memory image database.
The IXPersist interface is used by the CaffeControl to load and save weights.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Phase
Defines the Phase under which to run a Net.
DB_VERSION
Defines the image database version to use.
The MyCaffe.common namespace contains common MyCaffe classes.
delegate void onSetWorkspace(object sender, WorkspaceArgs e)
Delegate used to set the OnSetworkspace event.
delegate void onGetWorkspace(object sender, WorkspaceArgs e)
Delegate used to set the OnGetworkspace event.
TRAIN_STEP
Defines the training stepping method (if any).
WEIGHT_TARGET
Defines the type of weight to target in re-initializations.
The MyCaffe.data namespace contains dataset creators used to create common testing datasets such as M...
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe.fillers namespace contains all fillers including the Filler class.
The MyCaffe.layers namespace contains all layers that have a solidified code base,...
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-...