MCPcopy Create free account
hub / github.com/Xilinx/CHaiDNN / ExtractReshapeParameters

Function ExtractReshapeParameters

software/xtract/caffe_network_parser.cpp:2398–2469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2396
2397
2398void ExtractReshapeParameters(const caffe::LayerParameter& src, XGraph& graph)
2399{
2400 // Map the Caffe layer type to anonymoX layer type
2401 caffe::ReshapeParameter src_parameter = src.reshape_param();
2402 mapStrStr::const_iterator it_type = CaffeLayerMap.find(src.type());
2403 string xlayerType = it_type->second;
2404
2405 // Parse the input/output connections
2406 checkNumberOfTopAndBottom(src, 1, 1);
2407
2408 // Create new XLayer
2409 XLayer* dst = new XLayer(src.name(), xlayerType, src.top(0));
2410
2411 // shape [MANDATORY]
2412 if(src_parameter.shape().dim_size() == 0)
2413 {
2414 cerr << "[EP047] Shape is not mentioned for Reshape Layer : " << src.name() << endl;
2415 exit(-1);
2416 }
2417 else
2418 {
2419 caffe::BlobShape shape = src_parameter.shape();
2420 std::copy(shape.dim().begin(), shape.dim().end(), std::back_inserter(dst->reshape_params->shape));
2421 }
2422
2423 // TODO : @ARK : Current version support only number_axes = -1
2424 if(src_parameter.has_num_axes() && src_parameter.num_axes() != -1)
2425 {
2426 cerr << "[EP048] Current version supports only num_axes = -1 in Reshape Layer : " << src.name() << endl;
2427 exit(-1);
2428 }
2429
2430 dst->reshape_params->axis = src_parameter.has_axis() ? src_parameter.axis() : 0;
2431 dst->reshape_params->num_axes = src_parameter.has_num_axes() ? src_parameter.num_axes() : -1;
2432
2433 // Finally add the XLayer to graph
2434 graph.layers[src.name()] = dst;
2435
2436 // ----------------------------- Setup Blobs and Connections ----------------------- //
2437
2438 // Check bottom first. Make sure it is already registered in the Graph.blobs
2439 map<string, XBlob*>::iterator it = graph.checkIfBlobExists(src.bottom(0), true, false);
2440
2441 // Execution here reached means, bottom blob exists in graph. So update its fields
2442 XBlob* tmpBottom = it->second;
2443 dst->bottom.push_back(nameIndex(tmpBottom)); // Add bottom to XLayer.bottom
2444 dst->bottomShape.push_back(tmpBottom->shape); // Replicate bottom shape in Layer also
2445
2446 tmpBottom->consumers.push_back(dst->name); // Add convolution layer to bottom consumers
2447 tmpBottom->consumerDim.push_back(tmpBottom->shape); // and consumer uses the full bottom data.
2448
2449 // Check top. Make sure it is not registered in the Graph.blobs
2450 it = graph.checkIfBlobExists(src.top(0), true, true);
2451
2452 // Execution reached here means, top blob doesn't exist, so create.
2453 XBlob* tmpTop = new XBlob(src.top(0));
2454 dst->top.push_back(nameIndex(tmpTop)); // Add top blob to current layer top list
2455

Callers 1

ExtractParametersFunction · 0.85

Calls 15

nameIndexClass · 0.85
dim_sizeMethod · 0.80
shapeMethod · 0.80
dimMethod · 0.80
has_num_axesMethod · 0.80
num_axesMethod · 0.80
has_axisMethod · 0.80
axisMethod · 0.80
checkIfBlobExistsMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected