| 1674 | } |
| 1675 | |
| 1676 | void ExtractArgmaxParameters(const caffe::LayerParameter& src, XGraph& graph) |
| 1677 | { |
| 1678 | // Map the Caffe layer type to anonymoX layer type |
| 1679 | caffe::ArgMaxParameter src_parameter = src.argmax_param(); |
| 1680 | mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type()); |
| 1681 | string xlayerType = it_type->second; |
| 1682 | |
| 1683 | // Parse the input/output connections |
| 1684 | checkNumberOfTopAndBottom(src, 1, 1); |
| 1685 | |
| 1686 | // Create new XLayer |
| 1687 | XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0)); |
| 1688 | |
| 1689 | // get TOP_K [OPTIONAL : default = 1] |
| 1690 | dst->argmax_params->top_k = src_parameter.has_top_k() ? src_parameter.top_k() : 1; |
| 1691 | |
| 1692 | // get AXIS [OPTIONAL : default = 1] |
| 1693 | dst->argmax_params->axis = src_parameter.has_axis() ? src_parameter.axis() : 1; |
| 1694 | |
| 1695 | // Extract Precision Parameters |
| 1696 | bool success = ExtractPrecisionParameters(src, *dst); |
| 1697 | if(!success) |
| 1698 | graph.precMissLayers.push_back(src.name()); |
| 1699 | |
| 1700 | |
| 1701 | // Finally add the XLayer to graph |
| 1702 | graph.layers[src.name()] = dst; |
| 1703 | |
| 1704 | // ----------------------------- Setup Blobs and Connections ----------------------- // |
| 1705 | |
| 1706 | // Check bottom first. Make sure it is already registered in the Graph.blobs |
| 1707 | map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false); |
| 1708 | |
| 1709 | // Execution here reached means, bottom blob exists in graph. So update its fields |
| 1710 | XBlob* tmpBottom = it->second; |
| 1711 | dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom |
| 1712 | dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also |
| 1713 | |
| 1714 | tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers |
| 1715 | tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data. |
| 1716 | |
| 1717 | // Fill out nclasses & nboxes |
| 1718 | // nboxes is the dimension along the axis. nclasses is the rest. |
| 1719 | dst->argmax_params->nclasses = tmpBottom->shape.at(dst->argmax_params->axis); |
| 1720 | dst->argmax_params->nboxes = getSize(tmpBottom->shape)/tmpBottom->shape.at(dst->argmax_params->axis); |
| 1721 | |
| 1722 | // Check top. Make sure it is not registered in the Graph.blobs |
| 1723 | it = graph.checkIfBlobExists(src.top(0), true, true); |
| 1724 | |
| 1725 | // Execution reached here means, top blob doesn't exist, so create. |
| 1726 | XBlob* tmpTop = new XBlob(src.top(0)); |
| 1727 | dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list |
| 1728 | |
| 1729 | // Update layer "top" info with top name and shape |
| 1730 | tmpTop->producers.push_back(dst->name); // Add current layer to top Producers list |
| 1731 | dst->computeOutputDim(); // Calculate the output blob shape |
| 1732 | tmpTop->producerDim.push_back(tmpTop->shape); // Add output blob shape to producerDim |
| 1733 | dst->topShape.push_back(tmpTop->shape); // Replicate bottom shape in Layer also |
no test coverage detected