Function that extract all the trained parameters from CaffeModel file
| 313 | |
| 314 | // Function that extract all the trained parameters from CaffeModel file |
| 315 | void ExtractTrainedParameters(const caffe::NetParameter* Net, XGraph* graph) |
| 316 | { |
| 317 | // Create a map of layer_names -> index in caffemodel file for faster lookup |
| 318 | map<string, int>* modelLayerIndex = new map<string, int>(); |
| 319 | for(int i=0; i<Net->layer_size(); i++) |
| 320 | { |
| 321 | const caffe::LayerParameter& cLayer = Net->layer(i); |
| 322 | (*modelLayerIndex)[cLayer.name()] = i; |
| 323 | } |
| 324 | |
| 325 | // Now iterate through each layer searching for layers with params |
| 326 | for(map<string, XLayer*>::iterator xlayer_it = graph->layers.begin(); xlayer_it != graph->layers.end(); xlayer_it++) |
| 327 | { |
| 328 | if(xlayer_it->second->type == "Convolution") |
| 329 | { |
| 330 | extractConvolutionTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 331 | } |
| 332 | else if(xlayer_it->second->type == "Deconvolution") |
| 333 | { |
| 334 | extractDeconvolutionTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 335 | } |
| 336 | else if(xlayer_it->second->type == "InnerProduct") |
| 337 | { |
| 338 | extractFCTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 339 | } |
| 340 | else if(xlayer_it->second->type == "L2Normalize") |
| 341 | { |
| 342 | extractL2NormalizeTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 343 | } |
| 344 | else if(xlayer_it->second->type == "BatchNorm") |
| 345 | { |
| 346 | extractBatchNormTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 347 | } |
| 348 | else if(xlayer_it->second->type == "Scale") |
| 349 | { |
| 350 | extractScaleTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 351 | } |
| 352 | else if(xlayer_it->second->type == "XCustom") |
| 353 | { |
| 354 | extractXCustomTrainedData(graph, xlayer_it->second->name, Net, modelLayerIndex); |
| 355 | } |
| 356 | |
| 357 | } |
| 358 | |
| 359 | // Free the map memory |
| 360 | delete modelLayerIndex; |
| 361 | } |
| 362 | |
| 363 | void extractConvolutionTrainedData(XGraph* graph, const string& layerName, const caffe::NetParameter* Net, |
| 364 | const map<string, int>* layerIndex) |
no test coverage detected