5using System.Collections.Generic;
8using System.Threading.Tasks;
18 List<int> m_rgGpuID =
new List<int>();
20 int m_nAccumBatchSize;
21 int m_nBatchSizePerDevice;
24 int m_nTestIter = 100;
25 string m_strTrainDataSource;
26 string m_strTestDataSource;
31 bool m_bUsePool5 =
false;
32 bool m_bUseDilationConv5 =
false;
34 List<Tuple<int, bool>> m_rgIpLayers;
35 bool m_bSiamese =
false;
72 public ResNetModelBuilder(
string strBaseDirectory,
string strDataset,
int nChannels,
bool bSiamese, List<Tuple<int, bool>> rgIpLayers,
bool bUsePool5,
bool bUseDilationConv5,
MODEL model,
int nBatchSize = 32,
int nAccumBatchSize = 32, List<int> rgGpuId =
null,
NetParameter net =
null)
73 : base(strBaseDirectory, net)
78 m_rgGpuID =
new List<int>(rgGpuId);
80 m_nChannels = nChannels;
81 m_bSiamese = bSiamese;
82 m_rgIpLayers = rgIpLayers;
84 m_strModel = model.ToString();
85 m_nBatchSize = nBatchSize;
86 m_nAccumBatchSize = nAccumBatchSize;
87 m_nIterSize = m_nAccumBatchSize / m_nBatchSize;
89 m_nBatchSizePerDevice = (m_rgGpuID.Count == 1) ? m_nBatchSize : m_nBatchSize / m_rgGpuID.Count;
90 m_nIterSize = (
int)Math.Ceiling((
float)m_nAccumBatchSize / (m_nBatchSizePerDevice * m_rgGpuID.Count));
91 m_nGpuID = m_rgGpuID[0];
94 m_bUseDilationConv5 = bUseDilationConv5;
95 m_bUsePool5 = bUsePool5;
96 m_strDataset = strDataset;
102 m_transformTrain.
mirror =
true;
104 m_transformTrain.
mean_value =
new List<double>();
114 m_transformTest.
mean_value =
new List<double>();
164 string strData1 =
null;
165 string strData2 =
null;
167 m_strTrainDataSource = m_strDataset +
".training";
168 m_strTestDataSource = m_strDataset +
".testing";
172 string strDataName =
"data";
173 string strLayerPostfix =
"";
174 bool bNamedParams =
false;
178 strDataName =
"pair_data";
179 strLayerPostfix =
"_p";
184 addDataLayer(m_strTrainDataSource,
Phase.TRAIN, m_nBatchSize,
true, m_transformTrain, strDataName, m_bSiamese);
185 data =
addDataLayer(m_strTestDataSource,
Phase.TEST, m_nBatchSize,
true, m_transformTest, strDataName, m_bSiamese);
196 slice.
top.Add(strData1);
197 slice.
top.Add(strData2);
198 strDataName =
"data";
201 lastLayer = addBody(bDeploy, strDataName, bNamedParams);
207 decode.
name =
"decode1";
208 decode.
decode_param.target = param.beta.DecodeParameter.TARGET.CENTROID;
217 silence1.
name =
"silence1";
221 lastLayer = addBody(
false, strDataName + strLayerPostfix, bNamedParams, strLayerPostfix,
Phase.RUN);
228 loss.
top.Add(
"match");
239 silence.
name =
"silence2";
241 silence.
bottom[0] =
"match";
245 accuracy.
name =
"accuracy";
247 accuracy.
top.Add(accuracy.
name);
265 softmax.
name =
"softmax";
275 accuracy.
name =
"accuracy";
277 accuracy.
top.Add(accuracy.
name);
286 private LayerParameter addBody(
bool bDeploy,
string strDataName,
bool bNamedParams =
false,
string strLayerPostfix =
"",
Phase phaseExclude =
Phase.NONE)
293 lastLayer =
addResNetBody(strDataName, 4, 11, m_bUsePool5, m_bUseDilationConv5, bNamedParams, strLayerPostfix, phaseExclude);
296 case MODEL.RESNET101:
297 lastLayer =
addResNetBody(strDataName, 4, 23, m_bUsePool5, m_bUseDilationConv5, bNamedParams, strLayerPostfix, phaseExclude);
300 case MODEL.RESNET152:
301 lastLayer =
addResNetBody(strDataName, 8, 36, m_bUsePool5, m_bUseDilationConv5, bNamedParams, strLayerPostfix, phaseExclude);
305 throw new Exception(
"The model type '" + m_model.ToString() +
"' is not supported.");
308 for (
int i = 0; i < m_rgIpLayers.Count; i++)
311 string strName =
"fc" + (i + 1).ToString();
312 ip.
name = strName + strLayerPostfix;
The ModelBuilder is an abstract class that is overridden by a base class used to programically build ...
SolverParameter m_solver
Specifies the base solver to use.
void addExclusion(LayerParameter p, Phase phase)
Add a phase exclusion.
LayerParameter addResNetBody(string strDataName, int nBlock3Count=4, int nBlock4Count=23, bool bUsePool5=true, bool bUseDilationConv5=false, bool bNamedParams=false, string strLayerPostfix="", Phase phaseExclude=Phase.NONE)
Create a ResNet101 Body.
NetParameter m_net
Specifies the base net to be altered.
NetParameter createNet(string strName)
Create the base network parameter for the model and set its name to the 'm_strModel' name.
LayerParameter addDataLayer(string strSource, Phase phase, int nBatchSize=32, bool bOutputLabel=true, TransformationParameter transform=null, string strName="data", bool bSiamese=false)
Add the Data layer.
LayerParameter connectAndAddLayer(string fromLayer, LayerParameter toLayer, string fromLayer2=null)
Connect the from layer to the 'to' layer.
The ResNetModelBuilder adds the extra layers to a 'base' model for the ResNet model.
MODEL
Defines the type of model to create.
override NetParameter CreateModel(bool bDeploy=false)
Create the training model.
ResNetModelBuilder(string strBaseDirectory, string strDataset, int nChannels, bool bSiamese, List< Tuple< int, bool > > rgIpLayers, bool bUsePool5, bool bUseDilationConv5, MODEL model, int nBatchSize=32, int nAccumBatchSize=32, List< int > rgGpuId=null, NetParameter net=null)
The constructor.
override NetParameter CreateDeployModel()
Create the testing SSD model for the pascal dataset.
override SolverParameter CreateSolver()
Create the base solver to use.
override LayerParameter addExtraLayers(bool bUseBatchNorm=true, double dfLrMult=1)
Add extra layers (for SSD with the Pascal dataset) on top of a 'base' network (e.g....
double margin
Margin for dissimilar pair.
int axis
Specifies the first axis to be lumped into a single inner product computation; all preceding axes are...
bool enable_noise
Enable/disable noise in the inner-product layer (default = false).
uint num_output
The number of outputs for the layer.
Specifies the base parameter for all layers.
List< ParamSpec > parameters
Specifies the ParamSpec parameters of the LayerParameter.
SliceParameter slice_param
Returns the parameter set when initialized with LayerType.SLICE
string name
Specifies the name of this LayerParameter.
List< double > loss_weight
Specifies the loss weight.
SoftmaxParameter softmax_param
Returns the parameter set when initialized with LayerType.SOFTMAX
List< NetStateRule > include
Specifies the NetStateRule's for which this LayerParameter should be included.
List< NetStateRule > exclude
Specifies the NetStateRule's for which this LayerParameter should be excluded.
ContrastiveLossParameter contrastive_loss_param
Returns the parameter set when initialized with LayerType.CONTRASTIVE_LOSS
List< string > top
Specifies the active top connections (in the bottom, out the top)
InnerProductParameter inner_product_param
Returns the parameter set when initialized with LayerType.INNERPRODUCT
DecodeParameter decode_param
Returns the parameter set when initializing with LayerType.DECODE or LayerType.ACCURACY_ENCODING;
List< string > bottom
Specifies the active bottom connections (in the bottom, out the top).
LayerType
Specifies the layer type.
Specifies the parameters use to create a Net
List< LayerParameter > layer
The layers that make up the net. Each of their configurations, including connectivity and behavior,...
Specifies a NetStateRule used to determine whether a Net falls within a given include or exclude patt...
Specifies training parameters (multipliers on global learning constants, and the name of other settin...
List< uint > slice_point
Specifies optional slice points which indicate the indexes in the selected dimensions (the number of ...
int axis
Specifies the axis along wich to slice – may be negative to index from the end (e....
int axis
The axis along which to perform the softmax – may be negative to index from the end (e....
The SolverParameter is a parameter for the solver, specifying the train and test networks.
int max_iter
The maximum number of iterations.
List< int > test_iter
The number of iterations for each test.
bool debug_info
If true, print information about the state of the net that may help with debugging learning problems.
LearningRatePolicyType
Defines the learning rate policy to use.
SolverType
Defines the type of solver.
LearningRatePolicyType LearningRatePolicy
The learning rate decay policy.
int device_id
The device id that will be used when run on the GPU.
int average_loss
Display the loss averaged over the last average_loss iterations.
int test_interval
The number of iterations between two testing phases.
int iter_size
Accumulate gradients over 'iter_size' x 'batch_size' instances.
EvaluationType
Defines the evaluation method used in the SSD algorithm.
double gamma
Specifies the 'gamma' parameter to compute the 'step', 'exp', 'inv', and 'sigmoid' learning policy (d...
bool snapshot_after_train
If false, don't save a snapshot after training finishes.
EvaluationType eval_type
Specifies the evaluation type to use when using Single-Shot Detection (SSD) - (default = NONE,...
bool test_initialization
If true, run an initial test pass before the first iteration, ensuring memory availability and printi...
int display
The number of iterations between displaying info. If display = 0, no info will be displayed.
double weight_decay
Specifies the weight decay (default = 0.0005).
List< int > stepvalue
The step values for learning rate policy 'multistep'.
double momentum
Specifies the momentum value - used by all solvers EXCEPT the 'AdaGrad' and 'RMSProp' solvers....
int snapshot
Specifies the snapshot interval.
double base_lr
The base learning rate (default = 0.01).
SolverType type
Specifies the solver type.
double clip_gradients
Set clip_gradients to >= 0 to clip parameter gradients to that L2 norm, whenever their actual L2 norm...
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Phase
Defines the Phase under which to run a Net.
The MyCaffe.model namespace contains all classes used to programically create new model scripts.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
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-...