| 1941 | } |
| 1942 | |
| 1943 | void ExtractFlattenParameters(const caffe::LayerParameter& src, XGraph& graph) |
| 1944 | { |
| 1945 | // Map the Caffe layer type to anonymoX layer type |
| 1946 | caffe::FlattenParameter src_parameter = src.flatten_param(); |
| 1947 | mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type()); |
| 1948 | string xlayerType = it_type->second; |
| 1949 | |
| 1950 | // Parse the input/output connections |
| 1951 | checkNumberOfTopAndBottom(src, 1, 1); |
| 1952 | |
| 1953 | // Create new XLayer |
| 1954 | XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0)); |
| 1955 | |
| 1956 | // TODO : @ARK : Currently we support flatten with end_axis = -1, but any axis (for support in SSD) |
| 1957 | // And flatten layer will be removed from the graph by BE. |
| 1958 | // We need to see possible varieties of Flatten. Until then we support only end_axis=-1 |
| 1959 | if((src_parameter.has_end_axis() && (src_parameter.end_axis() != -1)) ) |
| 1960 | { |
| 1961 | cerr << "[EP040] Current version supports flatten layer with end_axis=-1 only" << endl; |
| 1962 | exit(-1); |
| 1963 | } |
| 1964 | |
| 1965 | dst->flatten_params->axis = src_parameter.has_axis() ? src_parameter.axis() : 1; |
| 1966 | dst->flatten_params->end_axis = src_parameter.has_end_axis() ? src_parameter.end_axis() : -1; |
| 1967 | |
| 1968 | // Extract Precision Parameters |
| 1969 | bool success = ExtractPrecisionParameters(src, *dst, false); |
| 1970 | if(!success) |
| 1971 | graph.precMissLayers.push_back(src.name()); |
| 1972 | |
| 1973 | // Finally add the XLayer to graph |
| 1974 | graph.layers[src.name()] = dst; |
| 1975 | |
| 1976 | // ----------------------------- Setup Blobs and Connections ----------------------- // |
| 1977 | |
| 1978 | // Check bottom first. Make sure it is already registered in the Graph.blobs |
| 1979 | map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false); |
| 1980 | |
| 1981 | // Execution here reached means, bottom blob exists in graph. So update its fields |
| 1982 | XBlob* tmpBottom = it->second; |
| 1983 | dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom |
| 1984 | dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also |
| 1985 | |
| 1986 | tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers |
| 1987 | tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data. |
| 1988 | |
| 1989 | // Check top. Make sure it is not registered in the Graph.blobs |
| 1990 | it = graph.checkIfBlobExists(src.top(0), true, true); |
| 1991 | |
| 1992 | // Execution reached here means, top blob doesn't exist, so create. |
| 1993 | XBlob* tmpTop = new XBlob(src.top(0)); |
| 1994 | dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list |
| 1995 | |
| 1996 | // Update layer "top" info with top name and shape |
| 1997 | tmpTop->producers.push_back(dst->name); // Add current layer to top Producers list |
| 1998 | dst->computeOutputDim(); // Calculate the output blob shape |
| 1999 | tmpTop->producerDim.push_back(tmpTop->shape); // Add output blob shape to producerDim |
| 2000 | dst->topShape.push_back(tmpTop->shape); // Replicate bottom shape in Layer also |
no test coverage detected