MCPcopy Create free account
hub / github.com/Xilinx/CHaiDNN / ExtractBatchNormParameters

Function ExtractBatchNormParameters

software/xtract/caffe_network_parser.cpp:2656–2733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2654}
2655
2656void ExtractBatchNormParameters(const caffe::LayerParameter& src, XGraph& graph)
2657{
2658 // Map the Caffe layer type to anonymoX layer type
2659 caffe::BatchNormParameter src_parameter = src.batch_norm_param();
2660 mapStrStr::const_iterator type_it = CaffeLayerMap.find(src.type());
2661 string xlayerType = type_it->second;
2662
2663 // Create new XLayer
2664 XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0));
2665
2666 // Parse the input/output connections
2667 checkNumberOfTopAndBottom(src, 1, 1);
2668
2669 // Check if it is inPlace.
2670 dst->batchnorm_params->inPlace = src.bottom(0) == src.top(0) ? true : false;
2671 dst->inPlace = src.bottom(0) == src.top(0) ? true : false;
2672
2673 // Get use_global_stats [Optional : default : true]
2674 dst->batchnorm_params->global_stats = src_parameter.has_use_global_stats() ? src_parameter.use_global_stats() : true;
2675 ASSERT( dst->batchnorm_params->global_stats == true, EP163,
2676 "use_global_stats should be true for the batch_norm layer: " << src.name())
2677
2678 // Get eps [default: 1e-5]
2679 dst->batchnorm_params->eps = src_parameter.has_eps() ? src_parameter.eps() : 0.00001;
2680
2681
2682 // Finally add the XLayer to graph
2683 graph.layers[src.name()] = dst;
2684
2685 // ----------------------------- Setup Blobs and Connections ----------------------- //
2686
2687
2688 // Check bottom first. Make sure it is already registered in the Graph.blobs
2689 map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false);
2690
2691 // Execution here reached means, bottom blob exists in graph. So update its fields
2692 XBlob* tmpBottom = it->second;
2693 dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom
2694 tmpBottom->consumers.push_back(dst->name); // Add layer to bottom consumers
2695 tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data.
2696 dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also
2697
2698 // Here, things are a little different because of the inplace operation
2699 if(dst->batchnorm_params->inPlace == false)
2700 {
2701 // Check top. Make sure it is not registered in the Graph.blobs
2702 it = graph.checkIfBlobExists(src.top(0), true, true);
2703
2704 // Execution reached here means, top blob doesn't exist, so create.
2705 XBlob* tmpTop = new XBlob(src.top(0));
2706 dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list
2707
2708 // Update layer "top" info with top name and shape
2709 tmpTop->producers.push_back(dst->name); // Add current layer to top Producers list
2710 dst->computeOutputDim(); // Calculate the output blob shape
2711 tmpTop->producerDim.push_back(tmpTop->shape); // Add output blob shape to producerDim
2712 dst->topShape.push_back(tmpTop->shape); // Replicate bottom shape in Layer also
2713

Callers 1

ExtractParametersFunction · 0.85

Calls 12

nameIndexClass · 0.85
has_use_global_statsMethod · 0.80
use_global_statsMethod · 0.80
has_epsMethod · 0.80
epsMethod · 0.80
checkIfBlobExistsMethod · 0.80
findMethod · 0.45
typeMethod · 0.45
push_backMethod · 0.45
computeOutputDimMethod · 0.45

Tested by

no test coverage detected