-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new examples and Update docs (#109)
* move graph ops to runtime * add/move graph ops tests * fix onnx helper imports * add `parse` to requirements & update gitignore * update graph ops init * update onnx exporter * add runtime wrapper * add vortex metric base * add metric registry * add lightning profiler * add metric base to init * update onnx-based runtime * add classification metric with plotting support * add mnasnet example * update example * add validation_epoch_end for mnasnet example * remove old examples * move mnasnet example * add export and inference example * move helper function to runtime * update onnxruntime requirements * add detr model dataset and utility * add detr module using vortex model base * add helper script to download voc dataset * add training config for detr example * update onnx exporter * add runtime wrapper * add vortex metric base * add metric registry * add lightning profiler * add metric base to init * update onnx-based runtime * add classification metric with plotting support * add mnasnet example * update example * add validation_epoch_end for mnasnet example * remove old examples * move mnasnet example * move metric compute at val epoch end only * rename export example * move dataset, model, and utils to separate dir for detection example * update docs for examples * remove old examples * update docstring for onnx exporter & runtime helper * remove old factory and pipelines * update docs for exporter, runtime, and graph_ops * update gitignore * remove docs for init method * remove unused test for old example * remove unused classification metrics * update api toc order * add more docstring for model base * update formatting to rst * add metadata documentation * add colab link for detection example * update docs front page * add alias function for common embed metadata * remove test metrics * remove modules doc that is no longer relevant * remove user guides that is no longer relevant * minor formatting fix * reorder toc * update formatting * update README * restore icon for readme * manually reorder exporter method * remove broken import for metrics * update model docstring * fix typo in predict docs
- Loading branch information
Showing
67 changed files
with
4,932 additions
and
4,648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,4 +284,8 @@ experiments/outputs/**/reports | |
!tests/test_dataset/* | ||
lightning_logs | ||
checkpoints | ||
logs | ||
logs | ||
|
||
*.xml | ||
*.tar | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.. py:module:: vortex.development.exporter.onnx | ||
.. py:currentmodule:: vortex.development.exporter.onnx | ||
Exporter | ||
======== | ||
|
||
Vortex includes onnx exporter to ease exporting model and embedding model properties. | ||
|
||
.. autoclass:: vortex.development.exporter.onnx.ONNXExporter | ||
|
||
.. automethod:: __call__ | ||
.. automethod:: export | ||
.. automethod:: embed_properties | ||
.. automethod:: finalize_export |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. py:module:: vortex.runtime.onnx.graph_ops | ||
.. py:currentmodule:: vortex.runtime.onnx.graph_ops | ||
ONNX graph ops utility | ||
====================== | ||
|
||
Collections of utilty to manipulate onnx graph. | ||
|
||
.. autofunction:: vortex.runtime.onnx.graph_ops.embed_model_property.embed_model_property | ||
|
||
.. autofunction:: vortex.runtime.onnx.graph_ops.embed_class_names_metadata.embed_class_names_metadata | ||
|
||
.. autofunction:: vortex.runtime.onnx.graph_ops.embed_output_format_metadata.embed_output_format_metadata | ||
|
||
.. autofunction:: vortex.runtime.onnx.graph_ops.embed_metadata.embed_metadata | ||
|
||
.. autoclass:: vortex.runtime.onnx.graph_ops.embed_metadata.EmbedMetadata | ||
:members: | ||
|
||
.. automethod:: __call__ | ||
|
||
.. autoclass:: vortex.runtime.onnx.graph_ops.embed_model_property.EmbedModelProperty | ||
:members: | ||
|
||
.. automethod:: __call__ | ||
|
||
.. autoclass:: vortex.runtime.onnx.graph_ops.embed_class_names_metadata.EmbedClassNamesMetadata | ||
:members: | ||
|
||
.. automethod:: __call__ | ||
|
||
.. autoclass:: vortex.runtime.onnx.graph_ops.embed_output_format_metadata.EmbedOutputFormatMetadata | ||
:members: | ||
|
||
.. automethod:: __call__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ References | |
:maxdepth: 2 | ||
|
||
models | ||
factory | ||
pipelines | ||
exporter | ||
graph_ops | ||
runtime |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.. py:module:: vortex.runtime.helper | ||
.. py:currentmodule:: vortex.runtime.helper | ||
Runtime Helper | ||
============== | ||
|
||
.. autoclass:: vortex.runtime.helper.InferenceHelper | ||
:members: | ||
|
||
.. automethod:: __call__ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Define MNASNet model using :py:mod:`~vortex.development.networks.models.ModelBase`, then export using :py:mod:`~vortex.development.exporter.onnx.ONNXExporter`. | ||
|
||
.. raw:: html | ||
|
||
<a href="https://colab.research.google.com/drive/184aKWgYAChwyWa9x348ep4734wj8SiUn"> | ||
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | ||
</a> | ||
|
||
.. include:: ../_build/examples/classification/mnasnet.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. raw:: html | ||
|
||
<a href="https://colab.research.google.com/drive/1XsiShhLTR6-rt-GmQsfOXLRnrt1lW1Sa?usp"> | ||
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | ||
</a> | ||
|
||
.. include:: ../_build/examples/detection/detr.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Export pretrained DETR to onnx, and inference using vortex runtime. | ||
The exporting part use default export from pytorch, ``torch.onnx.export``, | ||
then additional metadata is embedded to model using vortex' utility :py:mod:`~vortex.runtime.onnx.graph_ops.EmbedModelProperty`. | ||
Vortex provides inference and visualization helper via :py:mod:`~vortex.runtime.helper.InferenceHelper`. | ||
|
||
.. raw:: html | ||
|
||
<a href="https://colab.research.google.com/drive/1VO2NvjcM7HIpY0SryTc3gmr64XJg05fq"> | ||
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | ||
</a> | ||
|
||
.. include:: ../_build/examples/export/export.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Examples | ||
=============== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
export | ||
classification | ||
detection |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
Vortex Metadata | ||
=============== | ||
|
||
Here we describe metadata format used by vortex. | ||
|
||
1. Output Format | ||
---------------- | ||
Output format **defines the slices** for each output for **single batch**. | ||
Our interface relies on numpy's take_ operation to extract the output | ||
from possibly-batched prediction tensor. Numpy take is utilized to | ||
take elements from an array along an axis. Arguments to numpy take | ||
that we use for extracting the output can be summarized in the | ||
following table: | ||
|
||
+-----------+---------------------------------------+ | ||
| Argument | Description | | ||
+===========+=======================================+ | ||
| `indices` | The indices of values to extract | | ||
+-----------+---------------------------------------+ | ||
| `axis` | The axis over which values to extract | | ||
+-----------+---------------------------------------+ | ||
|
||
We also assume that the output tensor is batched, hence if the model | ||
is defined for single batch, one may need to unsqueeze or expand the dimension | ||
at the first axis. | ||
|
||
The number of output that can be defined from the output tensor is not limited. | ||
The output format is expected to be nested dictionary, with outer dictionary | ||
defines what the output is and the inner dictionary defines the arguments to | ||
numpy take. | ||
|
||
For example, assume we have classification model with the prediction tensor consists | ||
of class labels and class confidences, as follow: | ||
|
||
.. code-block:: python | ||
array([[3 , 0.71518937], | ||
[1, 0.54488318], | ||
[2, 0.64589411], | ||
[2, 0.891773 ]]) | ||
where the array is 2-dimensional array, with shape of :code:`(4,2)`, with first axis is the batch index, | ||
and the second axis represents class labels and class confidences for the corresponding batch index. | ||
For instance, the prediction of the first batch is :code:`[3 , 0.71518937]`, where the predicted class | ||
is :code:`3` and the confidence is :code:`0.71518937`. | ||
|
||
Let's :code:`'class_label'` and :code:`'class_confidence'` represent the predicted class labels and class_confidence, | ||
the output format should be: | ||
|
||
.. code-block:: python | ||
output_format = dict( | ||
class_label=dict( | ||
indices=[0], | ||
axis=0, | ||
), | ||
class_confidence=dict( | ||
indices=[1], | ||
axis=0, | ||
) | ||
) | ||
Note that the output format is defined to extract output of single batch. | ||
|
||
|
||
.. _take: https://numpy.org/doc/stable/reference/generated/numpy.take.html | ||
|
||
2. Class Names | ||
-------------- | ||
Class Names is simply a mapping from integer to string representing a class name. | ||
This can be described using dictionary, for example: | ||
|
||
.. code-block:: python | ||
class_names = dict( | ||
0='cat', | ||
1='dog', | ||
) | ||
3. Embedding Model Metadata | ||
--------------------------- | ||
To embed the described metadata above, one may use utility function | ||
:py:mod:`~vortex.runtime.onnx.graph_ops.embed_model_property.embed_model_property` | ||
which takes onnx model and model property defined as nested dictionary, for example: | ||
|
||
.. code-block:: python | ||
output_format = dict( | ||
class_label=dict( | ||
indices=[0], | ||
axis=0, | ||
), | ||
class_confidence=dict( | ||
indices=[1], | ||
axis=0, | ||
) | ||
) | ||
class_names = dict( | ||
0='cat', | ||
1='dog', | ||
) | ||
model_props = dict( | ||
class_names=class_names, | ||
output_format=output_format, | ||
) | ||
model : onnx.ModelProto = embed_model_property(model,model_props) | ||
Note that the model above is already an onnx model, and | ||
:py:mod:`~vortex.runtime.onnx.graph_ops.embed_model_property.embed_model_property` also | ||
expects onnx model. This may be useful when one wants to use model defined on other framework. | ||
since most deep learning also support exporting to onnx. |
Oops, something went wrong.