Skip to content

Commit b9c43d0

Browse files
authoredDec 27, 2023
Add support of models converted by OVC (#148)
* Support unnamed outputs in OV adapter * Add a test to load a model with unnamed output * Don't try to print a name of unnamed outputs * Update load test * Fix black * Update precommit public scope * Add data preparation for python precommit
1 parent af58962 commit b9c43d0

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed
 

‎.github/workflows/test_precommit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
source venv/bin/activate
5353
python -m pip install --upgrade pip
5454
pip install model_api/python/[tests] --extra-index-url https://download.pytorch.org/whl/cpu
55+
- name: Prepare test data
56+
run: |
57+
source venv/bin/activate
58+
python tests/cpp/precommit/prepare_data.py -d data -p tests/cpp/precommit/public_scope.json
5559
- name: Run test
5660
run: |
5761
source venv/bin/activate

‎model_api/cpp/utils/include/utils/common.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static inline void logBasicModelInfo(const std::shared_ptr<ov::Model>& model) {
4646

4747
slog::info << "\tOutputs: " << slog::endl;
4848
for (const ov::Output<ov::Node>& output : outputs) {
49-
const std::string name = output.get_any_name();
49+
const std::string name = output.get_names().size() ? output.get_any_name() : "";
5050
const ov::element::Type type = output.get_element_type();
5151
const ov::PartialShape shape = output.get_partial_shape();
5252
const ov::Layout layout = ov::layout::get_layout(output);

‎model_api/python/openvino/model_api/adapters/openvino_adapter.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ def get_layout_for_input(self, input, shape=None) -> str:
271271

272272
def get_output_layers(self):
273273
outputs = {}
274-
for output in self.model.outputs:
274+
for i, output in enumerate(self.model.outputs):
275275
output_shape = (
276276
output.partial_shape.get_min_shape()
277277
if self.model.is_dynamic()
278278
else output.shape
279279
)
280-
outputs[output.get_any_name()] = Metadata(
280+
281+
output_name = output.get_any_name() if output.get_names() else i
282+
outputs[output_name] = Metadata(
281283
output.get_names(),
282284
list(output_shape),
283285
precision=output.get_element_type().get_type_name(),

‎tests/cpp/precommit/prepare_data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def retrieve_otx_model(data_dir, model_name):
1818
)
1919

2020

21-
def parepare_model(
21+
def prepare_model(
2222
data_dir="./data",
2323
public_scope=Path(__file__).resolve().parent / "public_scope.json",
2424
):
@@ -70,6 +70,7 @@ def prepare_data(data_dir="./data"):
7070

7171
args = parser.parse_args()
7272

73-
parepare_model(args.data_dir, args.public_scope)
73+
prepare_model(args.data_dir, args.public_scope)
7474
prepare_data(args.data_dir)
7575
retrieve_otx_model(args.data_dir, "mlc_mobilenetv3_large_voc")
76+
retrieve_otx_model(args.data_dir, "tinynet_imagenet")

‎tests/cpp/precommit/public_scope.json

+4
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
{
2323
"name": "hrnet-v2-c1-segmentation",
2424
"type": "SegmentationModel"
25+
},
26+
{
27+
"name": "otx_models/tinynet_imagenet.xml",
28+
"type": "ClassificationModel"
2529
}
2630
]

‎tests/python/precommit/test_load.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from openvino.model_api.models import Model
2+
3+
4+
def test_model_with_unnamed_output_load():
5+
# the model's output doesn't have a name
6+
_ = Model.create_model(
7+
"data/otx_models/tinynet_imagenet.xml",
8+
model_type="Classification",
9+
preload=True,
10+
)

0 commit comments

Comments
 (0)