| 2133 | |
| 2134 | |
| 2135 | void ExtractL2NormalizeParameters(const caffe::LayerParameter& src, XGraph& graph) |
| 2136 | { |
| 2137 | // Map the Caffe layer type to anonymoX layer type |
| 2138 | caffe::NormalizeParameter src_parameter = src.norm_param(); |
| 2139 | mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type()); |
| 2140 | string xlayerType = it_type->second; |
| 2141 | |
| 2142 | // Parse the input/output connections |
| 2143 | checkNumberOfTopAndBottom(src, 1, 1); |
| 2144 | |
| 2145 | // Create new XLayer |
| 2146 | XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0)); |
| 2147 | |
| 2148 | // TODO : @ARK : Currently, we support only across_spatial=false right now. |
| 2149 | if(src_parameter.has_across_spatial() && (src_parameter.across_spatial() == true)) |
| 2150 | { |
| 2151 | cerr << "[EP042] Current version supports only L2-Normalization with across_spatial = false" << endl; |
| 2152 | exit(-1); |
| 2153 | } |
| 2154 | |
| 2155 | dst->l2norm_params->across_spatial = src_parameter.has_across_spatial() ? src_parameter.across_spatial() : true; |
| 2156 | dst->l2norm_params->channel_shared = src_parameter.has_channel_shared() ? src_parameter.channel_shared() : true; |
| 2157 | dst->l2norm_params->eps = src_parameter.has_eps() ? src_parameter.eps() : 1e-10; |
| 2158 | |
| 2159 | // Finally add the XLayer to graph |
| 2160 | graph.layers[src.name()] = dst; |
| 2161 | |
| 2162 | // ----------------------------- Setup Blobs and Connections ----------------------- // |
| 2163 | |
| 2164 | // Check bottom first. Make sure it is already registered in the Graph.blobs |
| 2165 | map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false); |
| 2166 | |
| 2167 | // Execution here reached means, bottom blob exists in graph. So update its fields |
| 2168 | XBlob* tmpBottom = it->second; |
| 2169 | dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom |
| 2170 | dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also |
| 2171 | |
| 2172 | tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers |
| 2173 | tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data. |
| 2174 | |
| 2175 | // Check top. Make sure it is not registered in the Graph.blobs |
| 2176 | it = graph.checkIfBlobExists(src.top(0), true, true); |
| 2177 | |
| 2178 | // Execution reached here means, top blob doesn't exist, so create. |
| 2179 | XBlob* tmpTop = new XBlob(src.top(0)); |
| 2180 | dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list |
| 2181 | |
| 2182 | // Update layer "top" info with top name and shape |
| 2183 | tmpTop->producers.push_back(dst->name); // Add current layer to top Producers list |
| 2184 | dst->computeOutputDim(); // Calculate the output blob shape |
| 2185 | tmpTop->producerDim.push_back(tmpTop->shape); // Add output blob shape to producerDim |
| 2186 | dst->topShape.push_back(tmpTop->shape); // Replicate bottom shape in Layer also |
| 2187 | |
| 2188 | // Finally Register the top blob to graph |
| 2189 | graph.blobs[tmpTop->name] = tmpTop; |
| 2190 | |
| 2191 | // Extract Precision Parameters |
| 2192 | bool success = ExtractPrecisionParameters(src, *dst, false); |
no test coverage detected