@@ -45,8 +45,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
4545
4646 for (const auto & layer_data : model_data) {
4747 std::string layer_type = layer_data[" type" ];
48- if (comments)
48+ if (comments) {
4949 std::cout << " Processing layer of type: " << layer_type << std::endl;
50+ }
5051
5152 it_lab_ai::Tensor tensor =
5253 it_lab_ai::create_tensor_from_json (layer_data, it_lab_ai::Type::kFloat );
@@ -93,8 +94,9 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
9394 layer_ptrs.push_back (ew_layer.get ());
9495 layers.push_back (std::move (ew_layer));
9596 layerpostop.push_back (true );
96- if (comments)
97+ if (comments) {
9798 std::cout << " Element wise (relu) added to layers" << std::endl;
99+ }
98100 }
99101 if (layer_type.find (" Dense" ) != std::string::npos) {
100102 it_lab_ai::Tensor tmp_bias = it_lab_ai::make_tensor (tensor.get_bias ());
@@ -113,9 +115,10 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
113115 } else {
114116 pooltype = " average" ;
115117 }
116- if (comments)
118+ if (comments) {
117119 std::cout << " PoolingLayer shape: " << shape[0 ] << " x" << shape[1 ]
118120 << std::endl;
121+ }
119122 auto pool_layer =
120123 std::make_unique<it_lab_ai::PoolingLayer>(shape, pooltype, kDefault );
121124 layer_ptrs.push_back (pool_layer.get ());
@@ -138,15 +141,17 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
138141 layer_ptrs.push_back (dropout_layer.get ());
139142 layers.push_back (std::move (dropout_layer));
140143 layerpostop.push_back (false );
141- if (comments)
144+ if (comments) {
142145 std::cout
143146 << " DropOutLayer added to layers with probability 0.4 (turned "
144147 " off for inference)."
145148 << std::endl;
149+ }
146150 }
147151 }
148- if (comments)
152+ if (comments) {
149153 std::cout << " number of layers - " << layers.size () + 1 << std::endl;
154+ }
150155 auto a1 = std::make_unique<it_lab_ai::InputLayer>(it_lab_ai::kNchw ,
151156 it_lab_ai::kNchw );
152157 Layer* a1_ptr = a1.get ();
@@ -157,17 +162,19 @@ void build_graph_linear(it_lab_ai::Graph& graph, it_lab_ai::Tensor& input,
157162 if (comments) std::cout << " Input set in graph." << std::endl;
158163
159164 graph.makeConnection (a1_ptr, layer_ptrs[0 ]);
160- if (comments)
165+ if (comments) {
161166 std::cout << " Connection made between InputLayer and first layer."
162167 << std::endl;
168+ }
163169
164170 for (size_t i = 0 ; i < layers.size () - 1 ; ++i) {
165171 if (layerpostop[i]) {
166172 layer_ptrs[i - 1 ]->postops .layers .push_back (layer_ptrs[i]);
167173 layer_ptrs[i - 1 ]->postops .count ++;
168174 graph.makeConnection (layer_ptrs[i - 1 ], layer_ptrs[i + 1 ]);
169- } else if (!layerpostop[i + 1 ])
175+ } else if (!layerpostop[i + 1 ]) {
170176 graph.makeConnection (layer_ptrs[i], layer_ptrs[i + 1 ]);
177+ }
171178 }
172179
173180 graph.setOutput (layer_ptrs.back (), output);
@@ -469,11 +476,12 @@ ParseResult parse_json_model(const std::string& json_path, bool comments) {
469476 } else if (layer_type.find (" Dropout" ) != std::string::npos) {
470477 auto dropout_layer = std::make_unique<it_lab_ai::DropOutLayer>(0.0 );
471478 layer = std::move (dropout_layer);
472- if (comments)
479+ if (comments) {
473480 std::cout
474481 << " DropOutLayer added to layers with probability 0.4 (turned "
475482 " off for inference)."
476483 << std::endl;
484+ }
477485 } else if (layer_type == " GlobalAveragePool" ) {
478486 auto pool_layer = std::make_unique<it_lab_ai::PoolingLayer>(
479487 it_lab_ai::Shape ({0 , 0 }), " average" , kDefault );
@@ -676,17 +684,24 @@ ParseResult parse_json_model(const std::string& json_path, bool comments) {
676684 continue ;
677685 }
678686 } else {
679- it_lab_ai::BinaryOpLayer::Operation op;
680- if (layer_type == " Add" )
687+ it_lab_ai::BinaryOpLayer::Operation op =
688+ it_lab_ai::BinaryOpLayer::Operation::kAdd ;
689+ bool supported_type = true ;
690+
691+ if (layer_type == " Add" ) {
681692 op = it_lab_ai::BinaryOpLayer::Operation::kAdd ;
682- else if (layer_type == " Sub" )
693+ } else if (layer_type == " Sub" ) {
683694 op = it_lab_ai::BinaryOpLayer::Operation::kSub ;
684- else if (layer_type == " Mul" )
695+ } else if (layer_type == " Mul" ) {
685696 op = it_lab_ai::BinaryOpLayer::Operation::kMul ;
686- else if (layer_type == " Div" )
697+ } else if (layer_type == " Div" ) {
687698 op = it_lab_ai::BinaryOpLayer::Operation::kDiv ;
688- else {
689- op = it_lab_ai::BinaryOpLayer::Operation::kAdd ;
699+ } else {
700+ supported_type = false ;
701+ }
702+
703+ if (!supported_type) {
704+ continue ;
690705 }
691706
692707 auto bin_layer = std::make_unique<it_lab_ai::BinaryOpLayer>(op);
@@ -1232,4 +1247,4 @@ void print_time_stats(Graph& graph) {
12321247#else
12331248 (void )graph;
12341249#endif
1235- }
1250+ }
0 commit comments