@@ -13,7 +13,7 @@ std::unordered_map<std::string, std::string> model_paths = {
1313
1414void build_graph_linear (it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
1515 it_lab_ai::Tensor& output, RuntimeOptions options,
16- bool comments) {
16+ bool comments, bool enable_postops ) {
1717 if (comments) {
1818 for (size_t i = 0 ; i < input.get_shape ().dims (); i++) {
1919 std::cout << input.get_shape ()[i] << ' ' ;
@@ -25,7 +25,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
2525 std::string json_file = MODEL_PATH_H5 ;
2626 it_lab_ai::json model_data = it_lab_ai::read_json (json_file);
2727
28- if (comments) std::cout << " Loaded model data from JSON." << ' \n ' ;
28+ if (comments) {
29+ std::cout << " Loaded model data from JSON." << ' \n ' ;
30+ }
2931
3032 for (const auto & layer_data : model_data) {
3133 std::string layer_type = layer_data[" type" ];
@@ -70,12 +72,14 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
7072 options, 1 , pads, 1 , tmp_values, tmp_bias, 1 , true );
7173 layers.push_back (conv_layer);
7274 layerpostop.push_back (false );
73- if (comments) std::cout << " ConvLayer added to layers." << ' \n ' ;
75+ if (comments) {
76+ std::cout << " ConvLayer added to layers." << ' \n ' ;
77+ }
7478 }
7579 if (layer_type.find (" relu" ) != std::string::npos) {
7680 auto ew_layer = LayerFactory::createEwLayer (" relu" , options);
7781 layers.push_back (ew_layer);
78- layerpostop.push_back (true );
82+ layerpostop.push_back (enable_postops );
7983 if (comments) {
8084 std::cout << " Element wise (relu) added to layers" << ' \n ' ;
8185 }
@@ -85,7 +89,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
8589 auto fc_layer = std::make_shared<it_lab_ai::FCLayer>(tensor, tmp_bias);
8690 layers.push_back (fc_layer);
8791 layerpostop.push_back (false );
88- if (comments) std::cout << " DenseLayer added to layers." << ' \n ' ;
92+ if (comments) {
93+ std::cout << " DenseLayer added to layers." << ' \n ' ;
94+ }
8995 }
9096
9197 if (layer_type.find (" Pool" ) != std::string::npos) {
@@ -105,15 +111,19 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
105111
106112 layers.push_back (pool_layer);
107113 layerpostop.push_back (false );
108- if (comments) std::cout << " PoolingLayer added to layers." << ' \n ' ;
114+ if (comments) {
115+ std::cout << " PoolingLayer added to layers." << ' \n ' ;
116+ }
109117 }
110118
111119 if (layer_type.find (" Flatten" ) != std::string::npos) {
112120 auto flatten_layer = std::make_shared<it_lab_ai::FlattenLayer>(
113121 std::vector<size_t >({0 , 3 , 2 , 1 }));
114122 layers.push_back (flatten_layer);
115123 layerpostop.push_back (false );
116- if (comments) std::cout << " FlattenLayer added to layers." << ' \n ' ;
124+ if (comments) {
125+ std::cout << " FlattenLayer added to layers." << ' \n ' ;
126+ }
117127 }
118128
119129 if (layer_type.find (" Dropout" ) != std::string::npos) {
@@ -128,26 +138,34 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
128138 }
129139 }
130140 }
131- if (comments) std::cout << " number of layers - " << layers.size () + 1 << ' \n ' ;
141+ if (comments) {
142+ std::cout << " number of layers - " << layers.size () + 1 << ' \n ' ;
143+ }
132144 auto a1 = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw ,
133145 it_lab_ai::kNchw );
134146
135- if (comments) std::cout << " InputLayer created." << ' \n ' ;
147+ if (comments) {
148+ std::cout << " InputLayer created." << ' \n ' ;
149+ }
136150
137151 graph.setInput (a1, input);
138- if (comments) std::cout << " Input set in graph." << ' \n ' ;
152+ if (comments) {
153+ std::cout << " Input set in graph." << ' \n ' ;
154+ }
139155
140156 graph.makeConnection (a1, layers[0 ]);
141- if (comments)
157+ if (comments) {
142158 std::cout << " Connection made between InputLayer and first layer." << ' \n ' ;
159+ }
143160
144161 for (size_t i = 0 ; i < layers.size () - 1 ; ++i) {
145162 if (layerpostop[i]) {
146163 layers[i - 1 ]->postops .layers .push_back (layers[i]);
147164 layers[i - 1 ]->postops .count ++;
148165 graph.makeConnection (layers[i - 1 ], layers[i + 1 ]);
149- } else if (!layerpostop[i + 1 ])
166+ } else if (!layerpostop[i + 1 ]) {
150167 graph.makeConnection (layers[i], layers[i + 1 ]);
168+ }
151169 }
152170
153171 graph.setOutput (layers.back (), output);
@@ -197,13 +215,12 @@ void build_graph(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
197215 try {
198216 std::sort (connection_list.begin (), connection_list.end (),
199217 [&](const auto & a, const auto & b) {
200- if (!name_to_layer.contains (a.first ) ||
201- !name_to_layer.contains (b.first )) {
202- return false ;
203- }
204- return name_to_layer[a.first ]->getID () <
205- name_to_layer[b.first ]->getID ();
206- });
218+ if (!name_to_layer.contains (a.first ) ||
219+ !name_to_layer.contains (b.first )) {
220+ return false ;
221+ }
222+ return name_to_layer[a.first ]->getID () < name_to_layer[b.first ]->getID ();
223+ });
207224
208225 } catch (const std::exception& e) {
209226 std::cerr << " ERROR during sorting: " << e.what () << ' \n ' ;
@@ -296,7 +313,9 @@ ParseResult parse_json_model(RuntimeOptions options,
296313 }
297314 }
298315
299- if (comments) std::cout << " Loaded model data from JSON." << ' \n ' ;
316+ if (comments) {
317+ std::cout << " Loaded model data from JSON." << ' \n ' ;
318+ }
300319
301320 auto input_layer = std::make_shared<it_lab_ai::InputLayer>(it_lab_ai::kNchw ,
302321 it_lab_ai::kNchw );
@@ -309,7 +328,9 @@ ParseResult parse_json_model(RuntimeOptions options,
309328 try {
310329 std::string layer_type = layer_data[" type" ];
311330
312- if (layer_type == " InputLayer" ) continue ;
331+ if (layer_type == " InputLayer" ) {
332+ continue ;
333+ }
313334 std::string layer_name = layer_data[" name" ];
314335 int layer_index = layer_data[" index" ];
315336 if (comments) {
@@ -703,7 +724,9 @@ ParseResult parse_json_model(RuntimeOptions options,
703724 std::cout << " TransposeLayer added with perm: [" ;
704725 for (size_t i = 0 ; i < perm.size (); ++i) {
705726 std::cout << perm[i];
706- if (i < perm.size () - 1 ) std::cout << " , " ;
727+ if (i < perm.size () - 1 ) {
728+ std::cout << " , " ;
729+ }
707730 }
708731 std::cout << " ]" << ' \n ' ;
709732 }
0 commit comments