Skip to content

Commit 16a2a94

Browse files
authored
cpp/precommit: fix device to improve reproducibility (#87)
1 parent f661f84 commit 16a2a94

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

.github/workflows/test_precommit.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ jobs:
138138
# .\w_openvino_toolkit_windows_2023.0.0.10926.b4452d56304_x86_64\setupvars.bat exits with 0 code without moving to a next command. Set PATH manually
139139
run: |
140140
set PATH=opencv\opencv\build\x64\vc16\bin;w_openvino_toolkit_windows_2023.0.0.10926.b4452d56304_x86_64\runtime\bin\intel64\Release;w_openvino_toolkit_windows_2023.0.0.10926.b4452d56304_x86_64\runtime\3rdparty\tbb\bin;%PATH%
141-
.\build\Release\test_sanity.exe -d data -p tests\cpp\precommit\public_scope.json && .\build\Release\test_model_config -d data
141+
.\build\Release\test_sanity.exe -d data -p tests\cpp\precommit\public_scope.json
142+
.\build\Release\test_model_config -d data
142143
serving_api:
143144
strategy:
144145
fail-fast: false

tests/cpp/precommit/test_model_config.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class MockAdapter : public OpenVINOInferenceAdapter {
4242
: OpenVINOInferenceAdapter() {
4343
auto core = ov::Core();
4444
auto model = core.read_model(modelPath);
45-
loadModel(model, core, "AUTO");
45+
loadModel(model, core, "CPU");
4646
}
4747
};
4848

@@ -76,7 +76,8 @@ std::string string_format(const std::string &fmt, Args... args) {
7676

7777
TEST_P(ClassificationModelParameterizedTest, TestClassificationDefaultConfig) {
7878
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
79-
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path);
79+
bool preload = true;
80+
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, {}, preload, "CPU");
8081

8182
auto ov_model = model->getModel();
8283

@@ -98,7 +99,8 @@ TEST_P(ClassificationModelParameterizedTest, TestClassificationCustomConfig) {
9899
{"resize_type", "fit_to_window"},
99100
{"labels", mock_labels}
100101
};
101-
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, configuration);
102+
bool preload = true;
103+
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, configuration, preload, "CPU");
102104

103105
auto ov_model = model->getModel();
104106

@@ -121,14 +123,15 @@ TEST_P(ClassificationModelParameterizedTestSaveLoad, TestClassificationCorrectne
121123
}
122124

123125
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
124-
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path);
126+
bool preload = true;
127+
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, {}, preload, "CPU");
125128

126129
auto ov_model = model->getModel();
127130
ov::serialize(ov_model, TMP_MODEL_FILE);
128131

129132
auto result = model->infer(image)->topLabels;
130133

131-
auto model_restored = ClassificationModel::create_model(TMP_MODEL_FILE);
134+
auto model_restored = ClassificationModel::create_model(TMP_MODEL_FILE, {}, preload, "CPU");
132135
auto result_data = model_restored->infer(image);
133136
auto result_restored = result_data->topLabels;
134137

@@ -143,7 +146,8 @@ TEST_P(ClassificationModelParameterizedTestSaveLoad, TestClassificationCorrectne
143146
}
144147

145148
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
146-
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path);
149+
bool preload = true;
150+
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, {}, preload, "CPU");
147151
auto ov_model = model->getModel();
148152
ov::serialize(ov_model, TMP_MODEL_FILE);
149153
auto result = model->infer(image)->topLabels;
@@ -159,7 +163,8 @@ TEST_P(ClassificationModelParameterizedTestSaveLoad, TestClassificationCorrectne
159163

160164
TEST_P(SSDModelParameterizedTest, TestDetectionDefaultConfig) {
161165
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
162-
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path);
166+
bool preload = true;
167+
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, {}, "", preload, "CPU");
163168

164169
auto ov_model = model->getModel();
165170

@@ -181,7 +186,8 @@ TEST_P(SSDModelParameterizedTest, TestDetectionCustomConfig) {
181186
{"resize_type", "fit_to_window"},
182187
{"labels", mock_labels}
183188
};
184-
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, configuration);
189+
bool preload = true;
190+
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, configuration, "", preload, "CPU");
185191

186192
auto ov_model = model->getModel();
187193

@@ -204,7 +210,8 @@ TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSave
204210
}
205211

206212
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
207-
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path);
213+
bool preload = true;
214+
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, {}, "", preload, "CPU");
208215

209216
auto ov_model = model->getModel();
210217
ov::serialize(ov_model, TMP_MODEL_FILE);
@@ -215,7 +222,7 @@ TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSave
215222
if (!image.data) {
216223
throw std::runtime_error{"Failed to read the image"};
217224
}
218-
auto model_restored = DetectionModel::create_model(TMP_MODEL_FILE);
225+
auto model_restored = DetectionModel::create_model(TMP_MODEL_FILE, {}, "", preload, "CPU");
219226
auto result_data = model_restored->infer(image);
220227
auto result_restored = result_data->objects;
221228

@@ -227,8 +234,6 @@ TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSave
227234
ASSERT_EQ(result[i].width, result_restored[i].width);
228235
ASSERT_EQ(result[i].height, result_restored[i].height);
229236
}
230-
231-
SUCCEED();
232237
}
233238

234239
TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSaveLoadWithAdapter) {
@@ -238,7 +243,8 @@ TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSave
238243
}
239244

240245
auto model_path = string_format(MODEL_PATH_TEMPLATE, GetParam().name.c_str(), GetParam().name.c_str());
241-
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path);
246+
bool preload = true;
247+
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, {}, "", preload, "CPU");
242248
auto ov_model = model->getModel();
243249
ov::serialize(ov_model, TMP_MODEL_FILE);
244250
auto result = model->infer(image)->objects;
@@ -261,8 +267,6 @@ TEST_P(DetectionModelParameterizedTestSaveLoad, TestDetctionCorrectnessAfterSave
261267
ASSERT_EQ(result[i].width, result_restored[i].width);
262268
ASSERT_EQ(result[i].height, result_restored[i].height);
263269
}
264-
265-
SUCCEED();
266270
}
267271

268272

tests/cpp/precommit/test_sanity.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,19 @@ TEST_P(ModelParameterizedTest, SynchronousInference)
7575
}
7676

7777
if ("DetectionModel" == GetParam().type) {
78-
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path);
78+
bool preload = true;
79+
auto model = DetectionModel::create_model(DATA_DIR + "/" + model_path, {}, "", preload, "CPU");
7980
auto result = model->infer(image);
8081
EXPECT_GT(result->objects.size(), 0);
8182
} else if ("ClassificationModel" == GetParam().type) {
82-
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path);
83+
bool preload = true;
84+
auto model = ClassificationModel::create_model(DATA_DIR + "/" + model_path, {}, preload, "CPU");
8385
std::unique_ptr<ClassificationResult> result = model->infer(image);
8486
ASSERT_GT(result->topLabels.size(), 0);
8587
EXPECT_GT(result->topLabels.front().score, 0.0f);
8688
} else if ("SegmentationModel" == GetParam().type) {
87-
auto model = SegmentationModel::create_model(DATA_DIR + "/" + model_path);
89+
bool preload = true;
90+
auto model = SegmentationModel::create_model(DATA_DIR + "/" + model_path, {}, preload, "CPU");
8891
auto result = model->infer(image)->asRef<ImageResultWithSoftPrediction>();
8992
ASSERT_GT(model->getContours(result).size(), 0);
9093
}

0 commit comments

Comments
 (0)