| 1796 | } |
| 1797 | |
| 1798 | void ExtractCropParameters(const caffe::LayerParameter& src, XGraph& graph) |
| 1799 | { |
| 1800 | // Map the Caffe layer type to anonymoX layer type |
| 1801 | caffe::CropParameter src_parameter = src.crop_param(); |
| 1802 | mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type()); |
| 1803 | string xlayerType = it_type->second; |
| 1804 | |
| 1805 | // Parse the input/output connections |
| 1806 | checkNumberOfTopAndBottom(src, 2, 1); |
| 1807 | |
| 1808 | // Create new XLayer |
| 1809 | XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0)); |
| 1810 | |
| 1811 | // Get AXIS [OPTIONAL, DEFAULT=2] |
| 1812 | // TODO : @ARK : Right now only axis=2 is supported |
| 1813 | if(src_parameter.has_axis() && src_parameter.axis() != 2) |
| 1814 | { |
| 1815 | cerr << "[EP019] In crop layer, only axis = 2 is supported currently" << endl; |
| 1816 | exit(-1); |
| 1817 | } |
| 1818 | |
| 1819 | dst->crop_params->axis = src_parameter.has_axis() ? src_parameter.axis() : 2; |
| 1820 | |
| 1821 | // Get OFFSET [MANDATORY] |
| 1822 | // TODO : @ARK : Only spatial cropping with same offset in both X & Y direction is supported now. |
| 1823 | if(src_parameter.offset_size() == 0) |
| 1824 | { |
| 1825 | cerr << "[EP020] In crop layer, offset should be mentioned" << endl; |
| 1826 | exit(-1); |
| 1827 | } |
| 1828 | |
| 1829 | dst->crop_params->offset = src_parameter.offset(0); |
| 1830 | |
| 1831 | // Extract Precision Parameters |
| 1832 | bool success = ExtractPrecisionParameters(src, *dst); |
| 1833 | if(!success) |
| 1834 | graph.precMissLayers.push_back(src.name()); |
| 1835 | |
| 1836 | // Finally add the XLayer to graph |
| 1837 | graph.layers[src.name()] = dst; |
| 1838 | |
| 1839 | // ----------------------------- Setup Blobs and Connections ----------------------- // |
| 1840 | |
| 1841 | // Crop has two bottom, so iterate through them |
| 1842 | |
| 1843 | for(int i = 0; i<src.bottom_size(); i++) |
| 1844 | { |
| 1845 | // Check bottom first. Make sure it is already registered in the Graph.blobs |
| 1846 | map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(i), true, false); |
| 1847 | |
| 1848 | // Execution here reached means, bottom blob exists in graph. So update its fields |
| 1849 | XBlob* tmpBottom = it->second; |
| 1850 | dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom |
| 1851 | dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also |
| 1852 | tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers |
| 1853 | tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data. |
| 1854 | } |
| 1855 |
no test coverage detected