| 2075 | |
| 2076 | |
| 2077 | void ExtractLRNParameters(const caffe::LayerParameter& src, XGraph& graph) |
| 2078 | { |
| 2079 | // Map the Caffe layer type to anonymoX layer type |
| 2080 | caffe::LRNParameter src_parameter = src.lrn_param(); |
| 2081 | mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type()); |
| 2082 | string xlayerType = it_type->second; |
| 2083 | |
| 2084 | // Parse the input/output connections |
| 2085 | checkNumberOfTopAndBottom(src, 1, 1); |
| 2086 | |
| 2087 | // Create new XLayer |
| 2088 | XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0)); |
| 2089 | |
| 2090 | dst->lrn_params->lsize = src_parameter.has_local_size()? src_parameter.local_size(): 5; |
| 2091 | dst->lrn_params->alpha = src_parameter.has_alpha() ? src_parameter.alpha() : 1.0; |
| 2092 | dst->lrn_params->beta = src_parameter.has_beta() ? src_parameter.beta() : 0.75; |
| 2093 | dst->lrn_params->k = src_parameter.has_k() ? src_parameter.k() : 1.0; |
| 2094 | dst->lrn_params->type = src_parameter.has_norm_region()? LRNType(src_parameter.norm_region()): ACROSS_CHANNELS; |
| 2095 | |
| 2096 | // Extract Precision Parameters |
| 2097 | bool success = ExtractPrecisionParameters(src, *dst, false); |
| 2098 | if(!success) |
| 2099 | graph.precMissLayers.push_back(src.name()); |
| 2100 | |
| 2101 | // Finally add the XLayer to graph |
| 2102 | graph.layers[src.name()] = dst; |
| 2103 | |
| 2104 | // ----------------------------- Setup Blobs and Connections ----------------------- // |
| 2105 | |
| 2106 | // Check bottom first. Make sure it is already registered in the Graph.blobs |
| 2107 | map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false); |
| 2108 | |
| 2109 | // Execution here reached means, bottom blob exists in graph. So update its fields |
| 2110 | XBlob* tmpBottom = it->second; |
| 2111 | dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom |
| 2112 | dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also |
| 2113 | |
| 2114 | tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers |
| 2115 | tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data. |
| 2116 | |
| 2117 | // Check top. Make sure it is not registered in the Graph.blobs |
| 2118 | it = graph.checkIfBlobExists(src.top(0), true, true); |
| 2119 | |
| 2120 | // Execution reached here means, top blob doesn't exist, so create. |
| 2121 | XBlob* tmpTop = new XBlob(src.top(0)); |
| 2122 | dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list |
| 2123 | |
| 2124 | // Update layer "top" info with top name and shape |
| 2125 | tmpTop->producers.push_back(dst->name); // Add current layer to top Producers list |
| 2126 | dst->computeOutputDim(); // Calculate the output blob shape |
| 2127 | tmpTop->producerDim.push_back(tmpTop->shape); // Add output blob shape to producerDim |
| 2128 | dst->topShape.push_back(tmpTop->shape); // Replicate bottom shape in Layer also |
| 2129 | |
| 2130 | // Finally Register the top blob to graph |
| 2131 | graph.blobs[tmpTop->name] = tmpTop; |
| 2132 | } |
| 2133 | |
| 2134 |
no test coverage detected