MCPcopy Create free account
hub / github.com/OAID/Tengine / create_batch_norm_node

Function create_batch_norm_node

internal/tests/executor/tests/test_batch_norm.cpp:52–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50float op_fops;
51
52Node* create_batch_norm_node(int n, int c, int h, int w)
53{
54 Operator* op = OpManager::CreateOp("BatchNormalization");
55 BatchNorm* bn_op = dynamic_cast<BatchNorm*>(op);
56
57 BatchNormParam* param = bn_op->GetParam();
58 param->caffe_flavor = 1;
59 param->rescale_factor = 1.2;
60 param->eps = 1e-5;
61
62 /* input shape */
63 int input_h = h;
64 int input_w = w;
65 int input_c = c;
66 int input_n = n;
67
68 std::vector<int> input_dims = {input_n, input_c, input_h, input_w};
69 std::vector<int> channel_dims = {input_c};
70
71 op_fops = 1.0 * input_n * input_c * input_h * input_w * 2;
72
73 Node* node = new Node("test_convolution");
74
75 node->SetOp(bn_op);
76
77 // prepare tensor: input/gmma/beta/mean/vars
78 Tensor* tensor;
79 int mem_size;
80 void* addr;
81
82 tensor = new Tensor("input");
83
84 tensor->SetDataType("float32");
85 tensor->SetType(kVarTensor);
86
87 TShape* shape = &tensor->GetShape();
88
89 shape->SetDataLayout("NCHW");
90 shape->SetDim(input_dims);
91
92 node->SetInputPort(0, tensor);
93
94 mem_size = tensor->GetTotalSize();
95 addr = std::malloc(mem_size);
96 init_tensor_data(( float* )addr, mem_size / sizeof(float), -1);
97
98 set_tensor_mem(tensor, addr, mem_size, std::free);
99
100 tensor = new Tensor("gamma");
101
102 tensor->SetDataType("float32");
103 tensor->SetType(kVarTensor);
104
105 shape = &tensor->GetShape();
106
107 shape->SetDataLayout("W");
108 shape->SetDim(channel_dims);
109

Callers 2

test_batch_normFunction · 0.85
test_new_operatorFunction · 0.85

Calls 11

set_tensor_memFunction · 0.85
GetParamMethod · 0.80
SetOpMethod · 0.80
SetDataTypeMethod · 0.80
SetTypeMethod · 0.80
SetDataLayoutMethod · 0.80
SetDimMethod · 0.80
SetInputPortMethod · 0.80
GetTotalSizeMethod · 0.80
SetOutputPortMethod · 0.80
init_tensor_dataFunction · 0.70

Tested by

no test coverage detected