Skip to content

Commit

Permalink
[bug] Add out of the box support for deployment_directories (#1131)
Browse files Browse the repository at this point in the history
* Add out of the box support for deployment_directories

* Remove dir --> model_path translation as model_to_path handles it now

* use model_to_path in openpif pipeline
  • Loading branch information
rahul-tuli committed Jul 20, 2023
1 parent 550aeaa commit 3e44bdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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

0 comments on commit 3e44bdd

Please sign in to comment.