Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
  • Loading branch information
xadupre committed Aug 1, 2023
1 parent e197ae6 commit 8275f83
Show file tree
Hide file tree
Showing 239 changed files with 10,648 additions and 5,198 deletions.
38 changes: 18 additions & 20 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,38 @@
import sphinx_gallery.gen_gallery




# -- Project information -----------------------------------------------------

project = 'onnxmltools'
copyright = '2018-2020, Microsoft'
author = 'Microsoft'
project = "onnxmltools"
copyright = "2018-2020, Microsoft"
author = "Microsoft"
version = onnxmltools.__version__
release = version

# -- General configuration ---------------------------------------------------

extensions = [
'sphinx.ext.intersphinx',
'sphinx.ext.imgmath',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
"sphinx.ext.intersphinx",
"sphinx.ext.imgmath",
"sphinx.ext.ifconfig",
"sphinx.ext.viewcode",
"sphinx.ext.autodoc",
'sphinx.ext.githubpages',
"sphinx.ext.githubpages",
"sphinx_gallery.gen_gallery",
'sphinx.ext.autodoc',
"sphinx.ext.autodoc",
]

templates_path = ['_templates']
source_suffix = ['.rst']
templates_path = ["_templates"]
source_suffix = [".rst"]

master_doc = 'index'
master_doc = "index"
language = "en"
exclude_patterns = []
pygments_style = 'default'
pygments_style = "default"

# -- Options for HTML output -------------------------------------------------

html_static_path = ['_static']
html_static_path = ["_static"]
html_theme = "readable"
html_theme_path = [sphinx_readable_theme.get_html_theme_path()]
html_logo = "ONNXMLTools_logo_main.png"
Expand All @@ -58,19 +56,19 @@
# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}

# -- Options for Sphinx Gallery ----------------------------------------------

sphinx_gallery_conf = {
'examples_dirs': 'examples',
'gallery_dirs': 'auto_examples',
"examples_dirs": "examples",
"gallery_dirs": "auto_examples",
}

# -- Setup actions -----------------------------------------------------------


def setup(app):
# Placeholder to initialize the folder before
# generating the documentation.
return app

17 changes: 10 additions & 7 deletions docs/examples/plot_convert_h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# Convert a model into ONNX
# +++++++++++++++++++++++++

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_h2o(pth, initial_types=initial_type)

h2o.cluster().shutdown()
Expand All @@ -68,8 +68,7 @@
sess = rt.InferenceSession(onx.SerializeToString())
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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)

##################################
Expand All @@ -82,17 +81,21 @@
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer

pydot_graph = GetPydotGraph(
onx.graph, name=onx.graph.name, rankdir="TB",
onx.graph,
name=onx.graph.name,
rankdir="TB",
node_producer=GetOpNodeProducer(
"docstring", color="yellow", fillcolor="yellow", style="filled"))
"docstring", color="yellow", fillcolor="yellow", style="filled"
),
)
pydot_graph.write_dot("model.dot")

os.system('dot -O -Gdpi=300 -Tpng model.dot')
os.system("dot -O -Gdpi=300 -Tpng model.dot")

image = plt.imread("model.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
ax.axis("off")


#################################
Expand Down
25 changes: 13 additions & 12 deletions docs/examples/plot_convert_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@
X_train, X_test, y_train, y_test = train_test_split(X, y_multi)

model = Sequential()
model.add(Dense(units=10, activation='relu', input_dim=4))
model.add(Dense(units=3, activation='softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy'])
model.add(Dense(units=10, activation="relu", input_dim=4))
model.add(Dense(units=3, activation="softmax"))
model.compile(loss="categorical_crossentropy", optimizer="sgd", metrics=["accuracy"])
model.fit(X_train, y_train, epochs=5, batch_size=16)
print("keras prediction")
print(model.predict(X_test.astype(numpy.float32)))
Expand All @@ -55,7 +53,7 @@
# Convert a model into ONNX
# +++++++++++++++++++++++++

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_keras(model, initial_types=initial_type)

###################################
Expand All @@ -65,8 +63,7 @@
sess = rt.InferenceSession(onx.SerializeToString())
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
pred_onx = sess.run(
[output_name], {input_name: X_test.astype(numpy.float32)})[0]
pred_onx = sess.run([output_name], {input_name: X_test.astype(numpy.float32)})[0]
print("ONNX prediction")
print(pred_onx)

Expand All @@ -80,17 +77,21 @@
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer

pydot_graph = GetPydotGraph(
onx.graph, name=onx.graph.name, rankdir="TB",
onx.graph,
name=onx.graph.name,
rankdir="TB",
node_producer=GetOpNodeProducer(
"docstring", color="yellow", fillcolor="yellow", style="filled"))
"docstring", color="yellow", fillcolor="yellow", style="filled"
),
)
pydot_graph.write_dot("model.dot")

os.system('dot -O -Gdpi=300 -Tpng model.dot')
os.system("dot -O -Gdpi=300 -Tpng model.dot")

image = plt.imread("model.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
ax.axis("off")


#################################
Expand Down
17 changes: 10 additions & 7 deletions docs/examples/plot_convert_libsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
# Convert a model into ONNX
# +++++++++++++++++++++++++

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_libsvm(clr, initial_types=initial_type)

###################################
Expand All @@ -64,8 +64,7 @@
sess = rt.InferenceSession(onx.SerializeToString())
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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)

##################################
Expand All @@ -78,17 +77,21 @@
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer

pydot_graph = GetPydotGraph(
onx.graph, name=onx.graph.name, rankdir="TB",
onx.graph,
name=onx.graph.name,
rankdir="TB",
node_producer=GetOpNodeProducer(
"docstring", color="yellow", fillcolor="yellow", style="filled"))
"docstring", color="yellow", fillcolor="yellow", style="filled"
),
)
pydot_graph.write_dot("model.dot")

os.system('dot -O -Gdpi=300 -Tpng model.dot')
os.system("dot -O -Gdpi=300 -Tpng model.dot")

image = plt.imread("model.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
ax.axis("off")


#################################
Expand Down
24 changes: 13 additions & 11 deletions docs/examples/plot_convert_lightgbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Convert a model into ONNX
# +++++++++++++++++++++++++

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_lightgbm(clr, initial_types=initial_type)

###################################
Expand All @@ -54,8 +54,7 @@
sess = rt.InferenceSession(onx.SerializeToString())
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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)

###############################################
Expand All @@ -68,17 +67,16 @@

dtrain = Dataset(X_train, label=y_train)

param = {'objective': 'multiclass', 'num_class': 3}
param = {"objective": "multiclass", "num_class": 3}
bst = train_lgbm(param, dtrain, 10)

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_lightgbm(bst, initial_types=initial_type)

sess = rt.InferenceSession(onx.SerializeToString())
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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)


Expand All @@ -92,17 +90,21 @@
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer

pydot_graph = GetPydotGraph(
onx.graph, name=onx.graph.name, rankdir="TB",
onx.graph,
name=onx.graph.name,
rankdir="TB",
node_producer=GetOpNodeProducer(
"docstring", color="yellow", fillcolor="yellow", style="filled"))
"docstring", color="yellow", fillcolor="yellow", style="filled"
),
)
pydot_graph.write_dot("model.dot")

os.system('dot -O -Gdpi=300 -Tpng model.dot')
os.system("dot -O -Gdpi=300 -Tpng model.dot")

image = plt.imread("model.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
ax.axis("off")


#################################
Expand Down
22 changes: 12 additions & 10 deletions docs/examples/plot_convert_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# Convert a model into ONNX
# +++++++++++++++++++++++++

initial_type = [('float_input', FloatTensorType([None, 4]))]
initial_type = [("float_input", FloatTensorType([None, 4]))]
onx = convert_sklearn(clr, initial_types=initial_type)

with open("rf_iris.onnx", "wb") as f:
Expand All @@ -68,25 +68,23 @@
sess = rt.InferenceSession("rf_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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)

#######################################
# Full example with a logistic regression

clr = LogisticRegression()
clr.fit(X_train, y_train)
initial_type = [('float_input', FloatTensorType([None, X_train.shape[1]]))]
initial_type = [("float_input", FloatTensorType([None, X_train.shape[1]]))]
onx = convert_sklearn(clr, initial_types=initial_type)
with open("logreg_iris.onnx", "wb") as f:
f.write(onx.SerializeToString())

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]
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)


Expand All @@ -100,17 +98,21 @@
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer

pydot_graph = GetPydotGraph(
onx.graph, name=onx.graph.name, rankdir="TB",
onx.graph,
name=onx.graph.name,
rankdir="TB",
node_producer=GetOpNodeProducer(
"docstring", color="yellow", fillcolor="yellow", style="filled"))
"docstring", color="yellow", fillcolor="yellow", style="filled"
),
)
pydot_graph.write_dot("model.dot")

os.system('dot -O -Gdpi=300 -Tpng model.dot')
os.system("dot -O -Gdpi=300 -Tpng model.dot")

image = plt.imread("model.dot.png")
fig, ax = plt.subplots(figsize=(40, 20))
ax.imshow(image)
ax.axis('off')
ax.axis("off")


#################################
Expand Down
Loading

0 comments on commit 8275f83

Please sign in to comment.