Update the documentation, run all examples during the generation of the documentation (replace #89) (#103)

* Minor update in the documentation

* Run examples during the generation of the documentation.
This commit is contained in:
Xavier Dupré 2018-12-05 19:12:25 +01:00 committed by Pranav Sharma
parent eeb862ab1a
commit 0573952499
7 changed files with 152 additions and 16 deletions

2
.gitignore vendored
View file

@ -31,3 +31,5 @@ onnxruntime_profile*.json
/docs/python/*_LICENSE
/csharp/**/obj/
/csharp/**/bin/
docs/python/*.onnx
*.onnx

View file

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{title|striptags|e}}{{titlesuffix}}</title>
<link rel="stylesheet" href="{{ pathto('_static/' + style, 1) }}" type="text/css"/>
<link rel="stylesheet" href="{{ pathto('_static/pygments.css', 1) }}" type="text/css" />
<link rel="stylesheet" href="{{ pathto('_static/gallery.css', 1) }}" type="text/css" />
</head>
<body>
<div class="container">
<div class="row" style="margin-top: 1rem;">
<div id="sidebar" class="col-xs-12 col-sm-3">
<a href="{{pathto(master_doc)}}">
<img style="margin-bottom: 0.5rem;" class="img-fluid" src="{{ pathto('_static/' + logo, 1) }}"/>
</a>
{%- if pagename != "search" and builder != "singlehtml" %}
<div id="searchbox" style="display: none" role="search">
<form class="form-inline" action="{{ pathto('search') }}" method="get">
<div class="form-group">
<label class="sr-only" for="searchInput">Search</label>
<input type="text" class="form-control" name="q" id="searchInput" placeholder="Search">
</div>
<button type="submit" class="btn btn-secondary" style="display:none">Go</button>
<input type="hidden" name="check_keywords" value="yes"/>
<input type="hidden" name="area" value="default"/>
</form>
</div>
{%- endif %}
<hr>
{%- if pagename != "intro" %}
<div id="toc">
{{ toctree(maxdepth=2, collapse=False, includehidden=True) }}
</div>
{%- else %}
<div id="toc">
{{ toctree(maxdepth=2, collapse=False, includehidden=True).split("<p class=")[0] }}
</div>
{%- endif %}
{%- if theme_versions_url %}
<hr>
<div id="versions" class="card">
<div class="card-block">
<h6 class="card-title" style="display:inline;">Version {{release}}</h6>
<a class="btn btn-secondary btn-sm pull-xs-right" data-toggle="collapse"
href="#other-versions" aria-expanded="false">&#9660;</a>
<ul id="other-versions" class="collapse list-inline">
<li id="other-versions-text" class="list-inline-item">Other versions</li>
<!-- Add <li class="list-inline-item">'s here -->
</ul>
</div>
</div>
<script>var versions_json_url = '{{theme_versions_url}}'</script>
{% endif %}
</div>
<div class="col-xs-12 col-sm-9">
{{ body }}
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"
integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js"
integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/js/bootstrap.min.js"
integrity="sha384-ux8v3A6CPtOTqOzMKiuo3d/DomGaaClxFYdCu2HPMBEkf6x2xiDyJ7gkXU0MWwaD"
crossorigin="anonymous"></script>
<script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/0.6.0/lunr.min.js"></script>
<script src="{{ pathto('_static/searchtools.js', 1) }}"></script>
{%- if theme_versions_url %}
<script src="{{ pathto('_static/versions.js', 1) }}"></script>
{% endif %}
<script>$('#searchbox').show(0)</script>
</body>
</html>

View file

@ -15,6 +15,7 @@ import onnxruntime
# The documentation requires two extensions available at:
# https://github.com/xadupre/sphinx-docfx-yaml
# https://github.com/xadupre/sphinx-docfx-markdown
import sphinx_modern_theme
# -- Project information -----------------------------------------------------
@ -33,10 +34,12 @@ extensions = [
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
'sphinx.ext.githubpages',
"sphinx_gallery.gen_gallery",
'sphinx.ext.autodoc',
"docfx_yaml.extension",
"docfx_markdown",
"pyquickhelper.sphinxext.sphinx_runpython_extension",
]
templates_path = ['_templates']
@ -54,16 +57,10 @@ pygments_style = 'sphinx'
# -- Options for HTML output -------------------------------------------------
html_theme = "sphinx_rtd_theme"
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
html_theme = "sphinx_modern_theme"
html_theme_path = [sphinx_modern_theme.get_html_theme_path()]
html_logo = "../MSFT-Onnx-Runtime-11282019-Logo.png"
html_static_path = ['_static']
# html_sidebars = {}
# -- Options for intersphinx extension ---------------------------------------
@ -89,5 +86,18 @@ md_link_replace = {
def setup(app):
# Placeholder to initialize the folder before
# generating the documentation.
app.add_stylesheet('_static/gallery.css')
# download examples for the documentation
this = os.path.abspath(os.path.dirname(__file__))
dest = os.path.join(this, "model.onnx")
if not os.path.exists(dest):
import urllib.request
url = 'https://raw.githubusercontent.com/onnx/onnx/master/onnx/backend/test/data/node/test_sigmoid/model.onnx'
urllib.request.urlretrieve(url, dest)
loc = os.path.split(dest)[-1]
if not os.path.exists(loc):
import shutil
shutil.copy(dest, loc)
return app

View file

@ -2,7 +2,7 @@
# Licensed under the MIT License.
"""
.. _l-example-simple-usage:
.. _l-example-common-error:
Common errors with onnxruntime
==============================

View file

@ -41,11 +41,13 @@ This example demonstrates a simple prediction for an
model. The following file ``model.onnx`` is taken from
github `onnx...test_sigmoid <https://github.com/onnx/onnx/tree/master/onnx/backend/test/data/node/test_sigmoid>`_.
::
.. runpython::
:showcode:
import numpy
import onnxruntime as rt
sess = rt.InferenceSession("model.onnx")
input_name = sess.get_inputs()[0].name
X = numpy.random.random((3,4,5)).astype(numpy.float32)
res = sess.run([output_name], {input_name: x})
pred_onnx = sess.run(None, {input_name: X})
print(pred_onnx)

View file

@ -26,7 +26,10 @@ Step 1: Train a model using your favorite framework
We'll use the famous iris datasets.
::
.. runpython::
:showcode:
:store:
:warningout: ImportWarning FutureWarning
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
@ -37,6 +40,7 @@ We'll use the famous iris datasets.
from sklearn.linear_model import LogisticRegression
clr = LogisticRegression()
clr.fit(X_train, y_train)
print(clr)
Step 2: Convert or export the model into ONNX format
++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -48,7 +52,11 @@ There are `tools <https://github.com/onnx/tutorials>`_
to convert other model formats into ONNX. Here we will use
`ONNXMLTools <https://github.com/onnx/onnxmltools>`_.
::
.. runpython::
:showcode:
:restore:
:store:
:warningout: ImportWarning FutureWarning
from onnxmltools import convert_sklearn
from onnxmltools.utils import save_model
@ -64,10 +72,33 @@ Step 3: Load and run the model using ONNX Runtime
We will use *ONNX Runtime* to compute the predictions
for this machine learning model.
::
.. runpython::
:showcode:
:restore:
:store:
import numpy
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx")
input_name = sess.get_inputs()[0].name
pred_onx = sess.run(None, {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)
The code can be changed to get one specific output
by specifying its name into a list.
.. runpython::
:showcode:
:restore:
import numpy
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx")
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)

3
requirements-doc.txt Normal file
View file

@ -0,0 +1,3 @@
sphinx
sphinx_gallery
sphinx_modern_theme