| 163 | } |
| 164 | |
| 165 | NodeID GraphBuilder::add_batch_normalization_node(Graph &g, |
| 166 | NodeParams params, |
| 167 | NodeIdxPair input, |
| 168 | float epsilon, |
| 169 | ITensorAccessorUPtr mean_accessor, |
| 170 | ITensorAccessorUPtr var_accessor, |
| 171 | ITensorAccessorUPtr beta_accessor, |
| 172 | ITensorAccessorUPtr gamma_accessor) |
| 173 | { |
| 174 | check_nodeidx_pair(input, g); |
| 175 | |
| 176 | bool has_beta = (beta_accessor != nullptr); |
| 177 | bool has_gamma = (gamma_accessor != nullptr); |
| 178 | |
| 179 | // Get input tensor descriptor |
| 180 | const TensorDescriptor input_tensor_desc = get_tensor_descriptor(g, g.node(input.node_id)->outputs()[0]); |
| 181 | |
| 182 | // Calculate Common Descriptor |
| 183 | TensorDescriptor common_desc = input_tensor_desc; |
| 184 | common_desc.shape = TensorShape(get_dimension_size(input_tensor_desc, DataLayoutDimension::CHANNEL)); |
| 185 | |
| 186 | // Create mean and var nodes |
| 187 | auto mean_nid = add_const_node_with_name(g, params, "Mean", common_desc, std::move(mean_accessor)); |
| 188 | auto var_nid = add_const_node_with_name(g, params, "Variance", common_desc, std::move(var_accessor)); |
| 189 | |
| 190 | // Create beta node |
| 191 | NodeID beta_nid = EmptyNodeID; |
| 192 | if (has_beta) |
| 193 | { |
| 194 | beta_nid = add_const_node_with_name(g, params, "Beta", common_desc, std::move(beta_accessor)); |
| 195 | } |
| 196 | |
| 197 | // Create gamma node |
| 198 | NodeID gamma_nid = EmptyNodeID; |
| 199 | if (has_gamma) |
| 200 | { |
| 201 | gamma_nid = add_const_node_with_name(g, params, "Gamma", common_desc, std::move(gamma_accessor)); |
| 202 | } |
| 203 | |
| 204 | // Create batch normalization node and add connections |
| 205 | NodeID batch_norm_nid = g.add_node<BatchNormalizationLayerNode>(epsilon); |
| 206 | g.add_connection(input.node_id, input.index, batch_norm_nid, 0); |
| 207 | g.add_connection(mean_nid, 0, batch_norm_nid, 1); |
| 208 | g.add_connection(var_nid, 0, batch_norm_nid, 2); |
| 209 | if (has_beta) |
| 210 | { |
| 211 | g.add_connection(beta_nid, 0, batch_norm_nid, 3); |
| 212 | } |
| 213 | if (has_gamma) |
| 214 | { |
| 215 | g.add_connection(gamma_nid, 0, batch_norm_nid, 4); |
| 216 | } |
| 217 | set_node_params(g, batch_norm_nid, params); |
| 218 | |
| 219 | return batch_norm_nid; |
| 220 | } |
| 221 | |
| 222 | NodeID GraphBuilder::add_bounding_box_transform_node( |
nothing calls this directly
no test coverage detected