diff --git a/.gitignore b/.gitignore
index dd44eb6d84..76e76e8600 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,3 +31,5 @@ onnxruntime_profile*.json
/docs/python/*_LICENSE
/csharp/**/obj/
/csharp/**/bin/
+docs/python/*.onnx
+*.onnx
diff --git a/docs/python/_templates/page.html b/docs/python/_templates/page.html
new file mode 100644
index 0000000000..122b3a8b66
--- /dev/null
+++ b/docs/python/_templates/page.html
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+ {{title|striptags|e}}{{titlesuffix}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{%- if theme_versions_url %}
+
+{% endif %}
+
+
+
diff --git a/docs/python/conf.py b/docs/python/conf.py
index 330d468cda..db4c9fb7ae 100644
--- a/docs/python/conf.py
+++ b/docs/python/conf.py
@@ -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
diff --git a/docs/python/examples/plot_common_errors.py b/docs/python/examples/plot_common_errors.py
index 7ba5c66180..ab50e4f942 100644
--- a/docs/python/examples/plot_common_errors.py
+++ b/docs/python/examples/plot_common_errors.py
@@ -2,7 +2,7 @@
# Licensed under the MIT License.
"""
-.. _l-example-simple-usage:
+.. _l-example-common-error:
Common errors with onnxruntime
==============================
diff --git a/docs/python/intro.rst b/docs/python/intro.rst
index d2d6b62f2d..401742833e 100644
--- a/docs/python/intro.rst
+++ b/docs/python/intro.rst
@@ -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 `_.
-::
+.. 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)
diff --git a/docs/python/tutorial.rst b/docs/python/tutorial.rst
index 50d65196b3..8f3efc574d 100644
--- a/docs/python/tutorial.rst
+++ b/docs/python/tutorial.rst
@@ -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 `_
to convert other model formats into ONNX. Here we will use
`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)
+
+
diff --git a/requirements-doc.txt b/requirements-doc.txt
new file mode 100644
index 0000000000..aa7e5ea5e0
--- /dev/null
+++ b/requirements-doc.txt
@@ -0,0 +1,3 @@
+sphinx
+sphinx_gallery
+sphinx_modern_theme