MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Expect

Function Expect

tensorflow/core/kernels/quantized_instance_norm_test.cc:83–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void Expect(const Tensor& input, float x_min, float x_max,
84 bool output_range_given, float give_y_min, float given_y_max) {
85 Scope root = Scope::NewRootScope();
86
87 auto input_ph = Placeholder(root, DT_QUINT8);
88
89 const float variance_eps = 1e-5;
90 auto instance_norm = QuantizedInstanceNorm(
91 root, input_ph, x_min, x_max,
92 QuantizedInstanceNorm::Attrs().VarianceEpsilon(variance_eps));
93
94 Status s = root.status();
95 EXPECT_TRUE(s.ok());
96
97 ClientSession session(root);
98 std::vector<Tensor> outputs;
99
100 s = session.Run({{input_ph, input}},
101 {instance_norm.y, instance_norm.y_min, instance_norm.y_max},
102 &outputs);
103
104 EXPECT_TRUE(s.ok());
105 Tensor expected(DT_FLOAT, input.shape());
106
107 ReferenceImpl(input.flat<quint8>().data(), x_min, x_max, input.shape(),
108 variance_eps, expected.flat<float>().data());
109
110 auto out = outputs[0].flat<quint8>();
111
112 float out_min = outputs[1].flat<float>()(0);
113 float out_max = outputs[2].flat<float>()(0);
114 float out_scale = (out_max - out_min) / 255.0f;
115
116 Eigen::Tensor<float, 0, Eigen::RowMajor> max_diff =
117 (expected.flat<float>() - (out_min + out_scale * out.cast<float>()))
118 .abs()
119 .maximum();
120 EXPECT_LE(max_diff(), 0.1);
121 LOG(INFO) << "max diff " << max_diff();
122}
123
124void TestBasic() {
125 Tensor input_tensor(DT_QUINT8, {1, 4, 4, 32});

Callers 5

TestBasicFunction · 0.70
TestZeroInputFunction · 0.70
TestMaxInputFunction · 0.70
TestOutputRangeGivenFunction · 0.70
TestClampFunction · 0.70

Calls 10

ReferenceImplFunction · 0.85
maximumMethod · 0.80
PlaceholderFunction · 0.50
AttrsClass · 0.50
statusMethod · 0.45
okMethod · 0.45
RunMethod · 0.45
shapeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected