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

Function TEST

tensorflow/lite/tools/optimize/calibration/calibrator_test.cc:44–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44TEST(CalibratorTest, CalibrationStatsAreCollected) {
45 auto model = ReadModel();
46 ASSERT_TRUE(model);
47 std::unique_ptr<Interpreter> interpreter;
48 std::unique_ptr<CalibrationReader> reader;
49 auto status = BuildLoggingInterpreter(
50 *model, ops::builtin::BuiltinOpResolver{}, &interpreter, &reader);
51 EXPECT_EQ(kTfLiteOk, status);
52
53 ASSERT_TRUE(interpreter);
54 ASSERT_TRUE(reader);
55 std::unordered_map<int, CalibrationReader::CalibrationStats> stats;
56 status = reader->GetTensorStatsAsMap(&stats);
57 EXPECT_EQ(kTfLiteOk, status);
58 EXPECT_TRUE(stats.empty());
59
60 status = interpreter->AllocateTensors();
61 ASSERT_EQ(kTfLiteOk, status);
62 // Model does the following:
63 // 0 1 2 3
64 // | |__ ____| |
65 // | | |
66 // | Add(tensor:4) |
67 // |____ ______|______ ______|
68 // | |
69 // Add Add
70 // | |
71 // Output:5 Output:6
72
73 const size_t tensor_size = 1 * 8 * 8 * 3;
74
75 std::vector<float> ones(tensor_size, 1.0f);
76 // Fill input tensor i with i+1, i.e. input[0] = 1.0f, input[1] = 2.0f,
77 // input[2] = 3.0f
78
79 for (size_t i = 0; i < interpreter->inputs().size(); i++) {
80 int input_tensor_idx = interpreter->inputs()[i];
81 TfLiteTensor* tensor = interpreter->tensor(input_tensor_idx);
82 ASSERT_EQ(tensor->bytes, tensor_size * sizeof(float));
83 for (size_t j = 0; j < tensor_size; j++) {
84 tensor->data.f[j] = i + 1;
85 }
86 }
87 status = interpreter->Invoke();
88 ASSERT_EQ(kTfLiteOk, status);
89 const float eps = 1e-6f;
90 // Verify that tensor 5: is 6
91 // Verify that tensor 6: is 9
92 TfLiteTensor* tensor = interpreter->tensor(interpreter->outputs()[0]);
93 for (size_t i = 0; i < tensor_size; i++) {
94 EXPECT_NEAR(tensor->data.f[i], 6.0f, eps);
95 }
96 tensor = interpreter->tensor(interpreter->outputs()[1]);
97 for (size_t i = 0; i < tensor_size; i++) {
98 EXPECT_NEAR(tensor->data.f[i], 9.0f, eps);
99 }
100
101 // Verify that min max of tensors.

Callers

nothing calls this directly

Calls 15

BuildLoggingInterpreterFunction · 0.85
GetTensorStatsAsMapMethod · 0.80
UnPackToMethod · 0.80
AddCalibrationToModelMethod · 0.80
ReadModelFunction · 0.70
emptyMethod · 0.45
AllocateTensorsMethod · 0.45
sizeMethod · 0.45
inputsMethod · 0.45
tensorMethod · 0.45
InvokeMethod · 0.45
outputsMethod · 0.45

Tested by

no test coverage detected