Skip to content

Commit

Permalink
Merge pull request #47 from nodefluxio/refactor-vortex-runtime
Browse files Browse the repository at this point in the history
Refactor vortex runtime and namespace package
  • Loading branch information
alphinside authored Aug 16, 2020
2 parents 4449f77 + ad23015 commit 2f13bb7
Show file tree
Hide file tree
Showing 242 changed files with 1,049 additions and 709 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- change `scheduler` to `lr_scheduler` in `config.trainer`.
- change field `validation` to `validator` and move it from `config.trainer` to main `config`.
- Refactor `DatasetWrapper` into `BasicDatasetWrapper` and `DefaultDatasetWrapper`
- Change output type of BaseRuntime `__call__` method to list of orderedDict
- It is now possible to override image auto padding in dataset object by adding and set `self.disable_image_auto_pad = True` attribute on the `collate_fn` object provided by the `model_components`

- Refactor package into 2 namespace packages : `vortex.runtime` and `vortex.development`. In which case `vortex.development` is depend on `vortex.runtime`, but `vortex.runtime` can be installed as a standalone package for minimal requirement inferencing library

## v0.1.0

Expand Down
23 changes: 0 additions & 23 deletions dockerfile

This file was deleted.

19 changes: 19 additions & 0 deletions dockerfiles/vortex.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y git

WORKDIR /app/vortex

COPY ./src /app/vortex/src

## install system requirements
RUN apt update && xargs apt install -y < src/development/requirements.sys

## install python requirements
RUN pip3 install -U pip setuptools

RUN pip3 install 'src/runtime[all]' 'src/development[optuna_vis]'

WORKDIR /app
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# vortex.core.factory
# vortex.development.core.factory

---

Expand Down Expand Up @@ -60,7 +60,7 @@ The dictionary returned will contain several keys :
- `collate_fn` : if provided, module to be embedded to dataloader's `collate_fn` function to modify dataset label's format into desirable format that can be accepted by `loss` components

```python
from vortex.core.factory import create_model
from vortex.development.core.factory import create_model
from easydict import EasyDict

model_config = EasyDict({
Expand Down Expand Up @@ -91,91 +91,6 @@ print(model_components.keys())



---

---

### create_runtime_model



Functions to create runtime model, currently the usage of this created object must be used together



```python
def create_runtime_model(
model_path : typing.Union[str, pathlib.Path],
runtime : str,
output_name = ['output'],
*args,
**kwargs,
)
```



**Arguments**:

- `model_path` _Union[str, Path]_ - Path to Intermediate Representation (IR) model file
- `runtime` _str_ - Backend runtime to be used, e.g. : 'cpu' or 'cuda' (Depends on available runtime options)
- `output_name` _list, optional_ - Runtime output(s) variable name. Defaults to ["output"].


**Returns**:

- `Type[BaseRuntime]` - Runtime model objects based on IR file model's type and selected `runtime`


**Raises**:

- `RuntimeError` - Raises if selected `runtime` is not available


**Examples**:



```python
from vortex.core.factory import create_runtime_model
import numpy as np
import cv2

model_path = 'tests/output_test/test_classification_pipelines/test_classification_pipelines.onnx'

runtime_model = create_runtime_model(
model_path = model_path,
runtime = 'cpu'
)

print(type(runtime_model))

## Get model's input specifications and additional inferencing parameters

print(runtime_model.input_specs)

# Inferencing example

input_shape = runtime_model.input_specs['input']['shape']
batch_imgs = np.array([cv2.resize(cv2.imread('tests/images/cat.jpg'),(input_shape[2],input_shape[1]))])

## Make sure the shape of input data is equal to input specifications
assert batch_imgs.shape == tuple(input_shape)

from vortex.core.pipelines import IRPredictionPipeline

## Additional parameters can be inspected from input_specs,
## E.g. `score_threshold` or `iou_threshold` for object detection
additional_input_parameters = {}

prediction_results = IRPredictionPipeline._runtime_predict(model=runtime_model,
image=batch_imgs,
**additional_input_parameters)
print(prediction_results)
```



---

---
Expand Down Expand Up @@ -225,7 +140,7 @@ def create_dataloader(


```python
from vortex.core.factory import create_dataloader
from vortex.development.core.factory import create_dataloader
from easydict import EasyDict

dataloader_config = EasyDict({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# vortex.core.pipelines
# vortex.development.core.pipelines

---

Expand Down Expand Up @@ -42,8 +42,8 @@ def __init__(


```python
from vortex.utils.parser import load_config
from vortex.core.pipelines import GraphExportPipeline
from vortex.development.utils.parser import load_config
from vortex.development.core.pipelines import GraphExportPipeline

# Parse config
config = load_config('experiments/config/example.yml')
Expand Down Expand Up @@ -131,8 +131,8 @@ def __init__(


```python
from vortex.core.pipelines import HypOptPipeline
from vortex.utils.parser.loader import Loader
from vortex.development.core.pipelines import HypOptPipeline
from vortex.development.utils.parser.loader import Loader
import yaml

# Parse config
Expand Down Expand Up @@ -224,8 +224,8 @@ def __init__(


```python
from vortex.core.pipelines import PytorchPredictionPipeline
from vortex.utils.parser import load_config
from vortex.development.core.pipelines import PytorchPredictionPipeline
from vortex.development.utils.parser import load_config

# Parse config
config_path = 'experiments/config/example.yml'
Expand Down Expand Up @@ -368,8 +368,8 @@ def __init__(


```python
from vortex.core.pipelines import IRPredictionPipeline
from vortex.utils.parser import load_config
from vortex.development.core.pipelines import IRPredictionPipeline
from vortex.development.utils.parser import load_config

# Parse config
model_file = 'experiments/outputs/example/example.pt' # Model file with extension '.onnx' or '.pt'
Expand Down Expand Up @@ -522,8 +522,8 @@ Defaults to False.


```python
from vortex.utils.parser import load_config
from vortex.core.pipelines import TrainingPipeline
from vortex.development.utils.parser import load_config
from vortex.development.core.pipelines import TrainingPipeline

# Parse config
config_path = 'experiments/config/example.yml'
Expand Down Expand Up @@ -615,8 +615,8 @@ def __init__(


```python
from vortex.utils.parser import load_config
from vortex.core.pipelines import PytorchValidationPipeline
from vortex.development.utils.parser import load_config
from vortex.development.core.pipelines import PytorchValidationPipeline

# Parse config
config_path = 'experiments/config/example.yml'
Expand Down Expand Up @@ -732,8 +732,8 @@ def __init__(


```python
from vortex.utils.parser import load_config
from vortex.core.pipelines import IRValidationPipeline
from vortex.development.utils.parser import load_config
from vortex.development.core.pipelines import IRValidationPipeline

# Parse config
config_path = 'experiments/config/example.yml'
Expand Down
135 changes: 135 additions & 0 deletions docs/api/vortex.runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# vortex.runtime

---

---



## Functions

---

---

### create_runtime_model



Functions to create runtime model



```python
def create_runtime_model(
model_path : typing.Union[str, pathlib.Path],
runtime : str,
output_name = ['output'],
*args,
**kwargs,
)
```



**Arguments**:

- `model_path` _Union[str, Path]_ - Path to Intermediate Representation (IR) model file
- `runtime` _str_ - Backend runtime to be used, e.g. : 'cpu' or 'cuda' (Depends on available runtime options)
- `output_name` _list, optional_ - Runtime output(s) variable name. Defaults to ["output"].


**Returns**:

- `Type[BaseRuntime]` - Runtime model objects based on IR file model's type and selected `runtime`


**Raises**:

- `RuntimeError` - Raises if selected `runtime` is not available


**Examples**:



```python
from vortex.runtime import create_runtime_model
import numpy as np
import cv2

model_path = 'tests/output_test/test_classification_pipelines/test_classification_pipelines.onnx'

runtime_model = create_runtime_model(
model_path = model_path,
runtime = 'cpu'
)

print(type(runtime_model))

## Get model's input specifications and additional inferencing parameters

print(runtime_model.input_specs)

# Inferencing example

input_shape = runtime_model.input_specs['input']['shape']
batch_imgs = np.array([cv2.resize(cv2.imread('tests/images/cat.jpg'),(input_shape[2],input_shape[1]))])

## Make sure the shape of input data is equal to input specifications
assert batch_imgs.shape == tuple(input_shape)

## Additional parameters can be inspected from input_specs,
## E.g. `score_threshold` or `iou_threshold` for object detection
additional_input_parameters = {}

## Inference is done by utilizing __call__ method
prediction_results = runtime_model(batch_imgs,
**additional_input_parameters)

print(prediction_results)
```



---

---

### check_available_runtime



Function to check current environment's available runtime



```python
def check_available_runtime(
)
```



**Returns**:

- `dict` - Dictionary containing status of available runtime


**Examples**:



```python
from vortex.runtime import check_available_runtime

available_runtime = check_available_runtime()
print(available_runtime)
```



---



Loading

0 comments on commit 2f13bb7

Please sign in to comment.