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

Method TestSmall8Bit

tensorflow/core/kernels/quantized_concat_op_test.cc:65–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65void QuantizedConcatTest::TestSmall8Bit(float first_min, float first_max,
66 float second_min, float second_max) {
67 TF_ASSERT_OK(NodeDefBuilder("quantized_concat_op", "QuantizedConcat")
68 .Input(FakeInput(DT_INT32))
69 .Input(FakeInput(2, DT_QUINT8))
70 .Input(FakeInput(2, DT_FLOAT))
71 .Input(FakeInput(2, DT_FLOAT))
72 .Attr("N", 2)
73 .Attr("T", DataTypeToEnum<quint8>::v())
74 .Finalize(node_def()));
75 TF_ASSERT_OK(InitOp());
76 const int first_batch = 2;
77 const int first_height = 2;
78 const int first_width = 3;
79 Tensor first_float(DT_FLOAT, {first_batch, first_height, first_width});
80 test::FillValues<float>(&first_float,
81 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
82 Tensor first_quantized =
83 FloatTensorToQuantized<quint8>(first_float, first_min, first_max);
84
85 const int second_batch = 2;
86 const int second_height = 2;
87 const int second_width = 3;
88 Tensor second_float(DT_FLOAT, {second_batch, second_height, second_width});
89 test::FillValues<float>(&second_float,
90 {13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
91 Tensor second_quantized =
92 FloatTensorToQuantized<quint8>(second_float, second_min, second_max);
93
94 const int expected_batch = first_batch + second_batch;
95 Tensor expected_float(DT_FLOAT, {expected_batch, first_height, first_width});
96 test::FillValues<float>(&expected_float,
97 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
98 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
99
100 AddInputFromArray<int32>(TensorShape({}), {0});
101 AddInputFromArray<quint8>(first_quantized.shape(),
102 first_quantized.flat<quint8>());
103 AddInputFromArray<quint8>(second_quantized.shape(),
104 second_quantized.flat<quint8>());
105 AddInputFromArray<float>(TensorShape({}), {first_min});
106 AddInputFromArray<float>(TensorShape({}), {second_min});
107 AddInputFromArray<float>(TensorShape({}), {first_max});
108 AddInputFromArray<float>(TensorShape({}), {second_max});
109 TF_ASSERT_OK(RunOpKernel());
110 const Tensor& output_quantized = *GetOutput(0);
111 const float output_min = GetOutput(1)->flat<float>()(0);
112 const float output_max = GetOutput(2)->flat<float>()(0);
113 Tensor output_float =
114 QuantizedTensorToFloat<quint8>(output_quantized, output_min, output_max);
115 test::ExpectTensorNear<float>(expected_float, output_float, 0.2);
116}
117
118TEST_F(QuantizedConcatTest, Small32Bit) {
119 TestSmall32Bit(0.0f, 1200.0f, 0.0f, 2400.0f);

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