Skip to content

Commit

Permalink
update documentation (#972)
Browse files Browse the repository at this point in the history
Signed-off-by: xadupre <xadupre@microsoft.com>
  • Loading branch information
xadupre authored Mar 7, 2023
1 parent 631c91d commit fbea019
Show file tree
Hide file tree
Showing 471 changed files with 105,599 additions and 126,492 deletions.
8 changes: 4 additions & 4 deletions .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 62f8ee6a3f6aefe7ce3ae4611d664fc1
tags: 645f666f9bcd5a90fca523b33c5a78b7
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: ee4940ae2593c690ef5ae868e708b4af
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file added .doctrees/api_summary.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/index.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_backend.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_black_op.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_custom_model.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_gpr.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_logging.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_metadata.doctree
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_nmf.doctree
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_examples/plot_pipeline.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_tutorial/index.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_tutorial/plot_gbegin_cst.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_tutorial/plot_gconverting.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/auto_tutorial/plot_ngrams.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .doctrees/environment.pickle
Binary file not shown.
Binary file added .doctrees/index.doctree
Binary file not shown.
Binary file added .doctrees/index_tutorial.doctree
Binary file not shown.
Binary file added .doctrees/introduction.doctree
Binary file not shown.
Binary file added .doctrees/parameterized.doctree
Binary file not shown.
Binary file added .doctrees/pipeline.doctree
Binary file not shown.
Binary file added .doctrees/supported.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_1-5_external.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_1_simple.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_2-5_extlib.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_2_new_converter.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_3_new_operator.doctree
Binary file not shown.
Binary file added .doctrees/tutorial_4_advanced.doctree
Binary file not shown.
286 changes: 143 additions & 143 deletions _downloads/01727087b155e5345657ebbe183f11e3/plot_gbegin_cst.ipynb
Original file line number Diff line number Diff line change
@@ -1,144 +1,144 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Store arrays in one onnx graph\n\nOnce a model is converted it can be useful to store an\narray as a constant in the graph an retrieve it through\nan output. This allows the user to store training parameters\nor other informations like a vocabulary.\nLast sections shows how to remove an output or to promote\nan intermediate result to an output.\n\n## Train and convert a model\n\nWe download one model from the :epkg:`ONNX Zoo` but the model\ncould be trained and produced by another converter library.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pprint\nimport numpy\nfrom onnx import load\nfrom onnxruntime import InferenceSession\nfrom sklearn.datasets import load_iris\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split\nfrom skl2onnx import to_onnx\nfrom skl2onnx.helpers.onnx_helper import (\n add_output_initializer, select_model_inputs_outputs)\n\n\ndata = load_iris()\nX, y = data.data.astype(numpy.float32), data.target\nX_train, X_test, y_train, y_test = train_test_split(X, y)\nmodel = LogisticRegression(penalty='elasticnet', C=2.,\n solver='saga', l1_ratio=0.5)\nmodel.fit(X_train, y_train)\n\nonx = to_onnx(model, X_train[:1], target_opset=12,\n options={'zipmap': False})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add training parameter\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"new_onx = add_output_initializer(\n onx,\n ['C', 'l1_ratio'],\n [numpy.array([model.C]), numpy.array([model.l1_ratio])])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Inference\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sess = InferenceSession(new_onx.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The major draw back of this solution is increase the prediction\ntime as onnxruntime copies the constants for every prediction.\nIt is possible either to store those constant in a separate ONNX graph\nor to removes them.\n\n## Select outputs\n\nNext function removes unneeded outputs from a model,\nnot only the constants. Next model only keeps the probabilities.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"simple_onx = select_model_inputs_outputs(new_onx, ['probabilities'])\n\nsess = InferenceSession(simple_onx.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)\n\n# Function *select_model_inputs_outputs* add also promote an intermediate\n# result to an output.\n#"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example only uses ONNX graph in memory and never saves or loads a\nmodel. This can be done by using the following snippets of code.\n\n## Save a model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with open(\"simplified_model.onnx\", \"wb\") as f:\n f.write(simple_onx.SerializeToString())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load a model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"model = load(\"simplified_model.onnx\", \"wb\")\n\nsess = InferenceSession(model.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 0
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Store arrays in one onnx graph\n\nOnce a model is converted it can be useful to store an\narray as a constant in the graph an retrieve it through\nan output. This allows the user to store training parameters\nor other informations like a vocabulary.\nLast sections shows how to remove an output or to promote\nan intermediate result to an output.\n\n## Train and convert a model\n\nWe download one model from the :epkg:`ONNX Zoo` but the model\ncould be trained and produced by another converter library.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import pprint\nimport numpy\nfrom onnx import load\nfrom onnxruntime import InferenceSession\nfrom sklearn.datasets import load_iris\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split\nfrom skl2onnx import to_onnx\nfrom skl2onnx.helpers.onnx_helper import (\n add_output_initializer, select_model_inputs_outputs)\n\n\ndata = load_iris()\nX, y = data.data.astype(numpy.float32), data.target\nX_train, X_test, y_train, y_test = train_test_split(X, y)\nmodel = LogisticRegression(penalty='elasticnet', C=2.,\n solver='saga', l1_ratio=0.5)\nmodel.fit(X_train, y_train)\n\nonx = to_onnx(model, X_train[:1], target_opset=12,\n options={'zipmap': False})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Add training parameter\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"new_onx = add_output_initializer(\n onx,\n ['C', 'l1_ratio'],\n [numpy.array([model.C]), numpy.array([model.l1_ratio])])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Inference\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sess = InferenceSession(new_onx.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The major draw back of this solution is increase the prediction\ntime as onnxruntime copies the constants for every prediction.\nIt is possible either to store those constant in a separate ONNX graph\nor to removes them.\n\n## Select outputs\n\nNext function removes unneeded outputs from a model,\nnot only the constants. Next model only keeps the probabilities.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"simple_onx = select_model_inputs_outputs(new_onx, ['probabilities'])\n\nsess = InferenceSession(simple_onx.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)\n\n# Function *select_model_inputs_outputs* add also promote an intermediate\n# result to an output.\n#"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example only uses ONNX graph in memory and never saves or loads a\nmodel. This can be done by using the following snippets of code.\n\n## Save a model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with open(\"simplified_model.onnx\", \"wb\") as f:\n f.write(simple_onx.SerializeToString())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load a model\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"model = load(\"simplified_model.onnx\", \"wb\")\n\nsess = InferenceSession(model.SerializeToString())\nprint(\"output names:\", [o.name for o in sess.get_outputs()])\nres = sess.run(None, {'X': X_test[:2]})\nprint(\"outputs\")\npprint.pprint(res)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit fbea019

Please sign in to comment.