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

Function extractDeconvolutionTrainedData

software/xtract/caffe_network_parser.cpp:447–528  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447void extractDeconvolutionTrainedData(XGraph* graph, const string& layerName, const caffe::NetParameter* Net,
448 const map<string, int>* layerIndex)
449{
450 map<string, int>::const_iterator modelLayer_it = layerIndex->find(layerName);
451 if(modelLayer_it == layerIndex->end())
452 {
453 cerr << "[EP032] Layer " << layerName << " is not found in the caffemodel file. " << endl;
454 exit(-1);
455 }
456
457 // Get the layer from caffemodel
458 int loc = modelLayer_it->second;
459 const caffe::LayerParameter& binLayer = Net->layer(loc);
460 XLayer* tmpXlayer = graph->layers[layerName];
461 string txtFileName;
462
463 // Extract the weights
464 cerr << "[IG001] Extracting " << tmpXlayer->name << " weights ... " << endl;
465 vector<int> weightsShape = getBlobDim(binLayer.blobs(0));
466 ELOG( ((weightsShape.at(0) != tmpXlayer->deconv_params->M) ||
467 (weightsShape.at(1) != (tmpXlayer->deconv_params->N/tmpXlayer->deconv_params->group)) ||
468 (weightsShape.at(2) != tmpXlayer->deconv_params->filter_h) ||
469 (weightsShape.at(3) != tmpXlayer->deconv_params->filter_w)),
470 EP057,
471 "Deconvolution Layer: " << tmpXlayer->name << " - mismatch in filter shape. "
472 << TensorDimToString(weightsShape) << " v/s " << tmpXlayer->deconv_params->filterDimToString()
473 )
474
475 vector<float> weights = extractBlobToVector(binLayer.blobs(0));
476 tmpXlayer->deconv_params->weights.push_back(weights);
477 tmpXlayer->deconv_params->weightsDim.push_back(weightsShape);
478
479#if DEBUG_WEIGHT_EXTRACTION
480 string tmpName(tmpXlayer->name);
481 replace(tmpName.begin(), tmpName.end(), '/', '_');
482 txtFileName = graph->saveDir + tmpName + "_weights";
483 tmpXlayer->deconv_params->weightsPath.push_back(txtFileName);
484 int sizeInBytes = getSize(weightsShape) * sizeof(float);
485 cerr << "[IG001] Saving " << txtFileName << " (" << humanReadableSize(sizeInBytes) << ")" << "\t";
486 if(sizeInBytes > (14*1024*1024))
487 {
488 cerr << "Parsing large data, this may take a while ...";
489 }
490 cerr << endl;
491 SAVEDATA(weights, txtFileName);
492#endif
493
494 // Extract the bias if bias is present, else save a vector filled with zeros
495 cerr << "[IG001] Extracting " << tmpXlayer->name << " weights ... " << endl;
496 vector<float> bias;
497 vector<int> biasShape;
498
499 if(tmpXlayer->deconv_params->has_bias)
500 {
501 biasShape = getBlobDim(binLayer.blobs(1));
502 ELOG( (biasShape.at(0) != tmpXlayer->deconv_params->M) , EP034,
503 "Deconv Layer: " << tmpXlayer->name << " - mismatch in bias shape. "
504 << TensorDimToString(biasShape) << " v/s " << tmpXlayer->deconv_params->M )

Callers 1

ExtractTrainedParametersFunction · 0.85

Calls 12

getBlobDimFunction · 0.85
TensorDimToStringFunction · 0.85
extractBlobToVectorFunction · 0.85
getSizeFunction · 0.85
humanReadableSizeFunction · 0.85
findMethod · 0.45
endMethod · 0.45
atMethod · 0.45
filterDimToStringMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected