Skip to content

Commit

Permalink
Apply black and ruff.
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
  • Loading branch information
xadupre committed Jul 28, 2023
1 parent e28140d commit a859095
Show file tree
Hide file tree
Showing 272 changed files with 12,721 additions and 6,318 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/black-ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Black Format Checker
on: [push, pull_request]
jobs:
black-format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
options: "--diff --check"
src: "."
ruff-format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
43 changes: 18 additions & 25 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,42 @@

# Configuration file for the Sphinx documentation builder.

import os
import sys
import shutil
import onnxmltools
import sphinx_readable_theme
import tabulate
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 +51,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

27 changes: 14 additions & 13 deletions docs/examples/plot_convert_h2o.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
import os
import numpy
import onnx
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer
import matplotlib.pyplot as plt
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import onnxruntime as rt
import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator
import skl2onnx
import onnxmltools
from onnxconverter_common.data_types import FloatTensorType
import onnxmltools
from onnxmltools.convert import convert_h2o


iris = load_iris()
X, y = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y)
Expand All @@ -56,7 +57,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,31 +69,31 @@
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)

##################################
# Display the ONNX graph
# ++++++++++++++++++++++
#
# Finally, let's see the graph converted with *onnxmltools*.
import os
import matplotlib.pyplot as plt
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
34 changes: 17 additions & 17 deletions docs/examples/plot_convert_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@
"""

import os
import matplotlib.pyplot as plt
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer
import numpy
import onnx
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import keras
from keras.models import Sequential
from keras.layers import Dense
import onnxruntime as rt

import skl2onnx
import onnxmltools
from onnxconverter_common.data_types import FloatTensorType
from onnxmltools.convert import convert_keras


iris = load_iris()
X, y = iris.data, iris.target
y_multi = numpy.zeros((y.shape[0], 3), dtype=numpy.int64)
y_multi[:, y] = 1
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 +55,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 +65,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 @@ -75,22 +74,23 @@
# ++++++++++++++++++++++
#
# Finally, let's see the graph converted with *onnxmltools*.
import os
import matplotlib.pyplot as plt
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
26 changes: 13 additions & 13 deletions docs/examples/plot_convert_libsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
+++++++++++++
"""

import os
import matplotlib.pyplot as plt
from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer
import numpy
import onnx
import sklearn
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from svm import C_SVC as SVC
import svmutil
import onnxruntime as rt

import skl2onnx
import onnxmltools
from onnxconverter_common.data_types import FloatTensorType
from onnxmltools.convert import convert_libsvm
Expand All @@ -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,31 +64,31 @@
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)

##################################
# Display the ONNX graph
# ++++++++++++++++++++++
#
# Finally, let's see the graph converted with *onnxmltools*.
import os
import matplotlib.pyplot as plt
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 a859095

Please sign in to comment.