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

Function ParseCaffeNetwork

software/xtract/caffe_network_parser.cpp:38–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36//-------------------------------------------------------------------------------------------------------------//
37
38XGraph* ParseCaffeNetwork(const string& deployFile, const string& caffemodelFile, const string& start_layer, const string& end_layer,
39 const string& rootFolder, const string& caffeMeanFile, FileMode file_mode)
40{
41
42 // ------------------------ GET CAFFE LAYER MAP ---------------------------- //
43 fillCaffeLayerMap();
44 fillSWLayerSet();
45
46 // ------------------------ LOAD DEPLOY FILE ------------------------------- //
47
48 // Create the Net for prototxt and load the deploy file to it
49 caffe::NetParameter *Net = new caffe::NetParameter;
50 readDeployFile(deployFile, Net);
51
52 // #. Check if atleast one layer is there in the prototxt
53 ASSERT( Net->layer_size() > 0, EP106,
54 "Network should contain atleast one layer. No layer is found in " << deployFile )
55
56 // ------------------------ START EXTRACTING TO XGRAPH ------------------------- //
57
58 // Create a XGraph
59 XGraph* graph = new XGraph();
60 string uniqname, username;
61
62 // Setting up the location to save data
63 if(rootFolder.empty())
64 graph->saveDir = "data/";
65 else
66 {
67 bool ends_with_slash = *(rootFolder.end()-1) == '/';
68 string tmp_saveDir = ends_with_slash ? rootFolder + "data/" : rootFolder + "/data/";
69 graph->saveDir = tmp_saveDir;
70 }
71
72 // Handle the input layer separately as it can be initialized multiple ways
73 // TODO : @ARK : Move this input parsing to a separate function for cleaner look
74 graph->name = Net->has_name() ? Net->name(): "";
75 int layer_start_index = 0;
76
77 if(Net->layer(0).type() != "Input") // If first layer is not Input Data Layer
78 { // that means no input layer defined.
79 if(Net->input_size() != 1)
80 {
81 cerr << "[EP003] Current version supports one & only-one top blob" << endl;
82 exit(-1);
83 }
84
85 if((Net->input_dim_size() > 0) && (Net->input_shape_size() > 0))
86 {
87 cerr << "[EP026] Both input_dim and input_shape can't be specified together. Use only one of them" << endl;
88 exit(-1);
89 }
90
91 vector<int> tmpShape;
92 if((Net->input_dim_size() > 0) &&
93 ((Net->input_dim_size() != 4) || (Net->input_dim(0) != 1)))
94 {
95 cerr << "[EP004] Current version requires batch size = 1 & input dimension to be in the form (1 x Channels x Height x Width)" << endl;

Callers 1

xiInitFunction · 0.85

Calls 15

fillCaffeLayerMapFunction · 0.85
fillSWLayerSetFunction · 0.85
readDeployFileFunction · 0.85
nameIndexClass · 0.85
ExtractParametersFunction · 0.85
readMeanBinaryFileFunction · 0.85
ExtractCaffeMeanDataFunction · 0.85
readtxtFunction · 0.85
readModelFileFunction · 0.85
ExtractTrainedParametersFunction · 0.85
layer_sizeMethod · 0.80
input_sizeMethod · 0.80

Tested by

no test coverage detected