Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Add out of the box support for deployment_directories #1131

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/deepsparse/image_classification/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Image classification pipeline
"""
import json
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Type, Union

import numpy
Expand Down Expand Up @@ -135,11 +134,6 @@ class properties into an inference ready onnx file to be compiled by the

:return: file path to the ONNX file for the engine to compile
"""

model_path_: Path = Path(self.model_path)
if model_path_.is_dir():
return model_to_path(str(model_path_ / "model.onnx"))

return model_to_path(self.model_path)

def process_inputs(self, inputs: ImageClassificationInput) -> List[numpy.ndarray]:
Expand Down
3 changes: 2 additions & 1 deletion src/deepsparse/open_pif_paf/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
OpenPifPafOutput,
)
from deepsparse.pipeline import Pipeline
from deepsparse.utils import model_to_path
from deepsparse.yolact.utils import preprocess_array
from openpifpaf import decoder, network

Expand Down Expand Up @@ -100,7 +101,7 @@ class properties into an inference ready onnx file to be compiled by the

:return: file path to the ONNX file for the engine to compile
"""
return self.model_path
return model_to_path(self.model_path)

def process_inputs(self, inputs: OpenPifPafInput) -> List[numpy.ndarray]:

Expand Down
12 changes: 9 additions & 3 deletions src/deepsparse/utils/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import os
import tempfile
from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import List, Optional, Tuple, Union

Expand Down Expand Up @@ -96,9 +97,10 @@ def translate_onnx_type_to_numpy(tensor_type: int):
def model_to_path(model: Union[str, Model, File]) -> str:
"""
Deals with the various forms a model can take. Either an ONNX file,
a SparseZoo model stub prefixed by 'zoo:', a SparseZoo Model object,
or a SparseZoo ONNX File object that defines the neural network. Noting
the model will be downloaded automatically if a SparseZoo stub is passed
a directory containing model.onnx, a SparseZoo model stub prefixed by
'zoo:', a SparseZoo Model object, or a SparseZoo ONNX File object that
defines the neural network. Noting the model will be downloaded automatically
if a SparseZoo stub is passed

:param model: Either a local str path or SparseZoo stub to the model. Can
also be a sparsezoo.Model or sparsezoo.File object
Expand Down Expand Up @@ -126,6 +128,10 @@ def model_to_path(model: Union[str, Model, File]) -> str:
if not os.path.exists(model):
raise ValueError("model path must exist: given {}".format(model))

model_path = Path(model)
if model_path.is_dir():
return str(model_path / "model.onnx")

return model


Expand Down
Loading