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

Method TestSecondDim8Bit

tensorflow/core/kernels/quantized_concat_op_test.cc:192–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192void QuantizedConcatTest::TestSecondDim8Bit(float first_min, float first_max,
193 float second_min,
194 float second_max) {
195 TF_ASSERT_OK(NodeDefBuilder("quantized_concat_op", "QuantizedConcat")
196 .Input(FakeInput(DT_INT32))
197 .Input(FakeInput(2, DT_QUINT8))
198 .Input(FakeInput(2, DT_FLOAT))
199 .Input(FakeInput(2, DT_FLOAT))
200 .Attr("N", 2)
201 .Attr("T", DataTypeToEnum<quint8>::v())
202 .Finalize(node_def()));
203 TF_ASSERT_OK(InitOp());
204 const int first_batch = 2;
205 const int first_height = 2;
206 const int first_width = 3;
207 Tensor first_float(DT_FLOAT, {first_batch, first_height, first_width});
208 test::FillValues<float>(&first_float,
209 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
210 Tensor first_quantized =
211 FloatTensorToQuantized<quint8>(first_float, first_min, first_max);
212
213 const int second_batch = 2;
214 const int second_height = 2;
215 const int second_width = 3;
216 Tensor second_float(DT_FLOAT, {second_batch, second_height, second_width});
217 test::FillValues<float>(&second_float,
218 {13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
219 Tensor second_quantized =
220 FloatTensorToQuantized<quint8>(second_float, second_min, second_max);
221
222 const int expected_height = first_height + second_height;
223 Tensor expected_float(DT_FLOAT, {first_batch, expected_height, first_width});
224 test::FillValues<float>(&expected_float,
225 {1, 2, 3, 4, 5, 6, 13, 14, 15, 16, 17, 18,
226 7, 8, 9, 10, 11, 12, 19, 20, 21, 22, 23, 24});
227
228 AddInputFromArray<int32>(TensorShape({}), {1});
229 AddInputFromArray<quint8>(first_quantized.shape(),
230 first_quantized.flat<quint8>());
231 AddInputFromArray<quint8>(second_quantized.shape(),
232 second_quantized.flat<quint8>());
233 AddInputFromArray<float>(TensorShape({}), {first_min});
234 AddInputFromArray<float>(TensorShape({}), {second_min});
235 AddInputFromArray<float>(TensorShape({}), {first_max});
236 AddInputFromArray<float>(TensorShape({}), {second_max});
237 TF_ASSERT_OK(RunOpKernel());
238 const Tensor& output_quantized = *GetOutput(0);
239 const float output_min = GetOutput(1)->flat<float>()(0);
240 const float output_max = GetOutput(2)->flat<float>()(0);
241 Tensor output_float =
242 QuantizedTensorToFloat<quint8>(output_quantized, output_min, output_max);
243 test::ExpectTensorNear<float>(expected_float, output_float, 1.0);
244}
245
246// For the benchmark, we set up two 2-dimensional tensors, each kDim1 x 'dim'
247// in size, and concat them together along "concat_dimension".

Callers

nothing calls this directly

Calls 8

NodeDefBuilderClass · 0.85
GetOutputFunction · 0.85
FakeInputFunction · 0.50
TensorShapeClass · 0.50
FinalizeMethod · 0.45
AttrMethod · 0.45
InputMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected