diff --git a/docs/api/python/.buildinfo b/docs/api/python/.buildinfo index 78bf8190f3dd3..edb6d7ef139e4 100644 --- a/docs/api/python/.buildinfo +++ b/docs/api/python/.buildinfo @@ -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: b6aa838178686f9785018d78eb6169ef +config: 36e772eb12f6d489cf39825d3e063ad4 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/api/python/README.html b/docs/api/python/README.html deleted file mode 100644 index 3dd33a2be1fa1..0000000000000 --- a/docs/api/python/README.html +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - ONNX Runtime — ONNX Runtime 1.7.0 documentation - - - - - - - - - - - - - - - - - - - - - - -
-
-
- - -
- -
-

ONNX Runtime

-

ONNX Runtime is a performance-focused scoring engine for Open Neural Network Exchange (ONNX) models. -For more information on ONNX Runtime, please see aka.ms/onnxruntime or the Github project.

- -
- - -
- -
-
- -
-
- - - - - - - \ No newline at end of file diff --git a/docs/api/python/api_summary.html b/docs/api/python/api_summary.html index dcdbb4979f48e..81645aeb66670 100644 --- a/docs/api/python/api_summary.html +++ b/docs/api/python/api_summary.html @@ -4,16 +4,17 @@ - - API Summary — ONNX Runtime 1.7.0 documentation - - + + + API Summary — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -37,22 +38,50 @@
-
+

API Summary

Summary of public functions and classes exposed in ONNX Runtime.

-
-

OrtValue

+
+

OrtValue

ONNX Runtime works with native Python data structures which are mapped into ONNX data formats : Numpy arrays (tensors), dictionaries (maps), and a list of Numpy arrays (sequences). The data backing these are on CPU.

@@ -62,7 +91,7 @@

OrtValue -

+
+

IOBinding

By default, ONNX Runtime always places input(s) and output(s) on CPU, which is not optimal if the input or output is consumed and produced on a device other than CPU because it introduces data copy between CPU and the device. @@ -89,7 +118,7 @@

IOBinding

+
+

Device

The package is compiled for a specific device, GPU or CPU. The CPU implementation includes optimizations such as MKL (Math Kernel Libary). The following function indicates the chosen option:

-
-onnxruntime.get_device()str
+
+onnxruntime.get_device() str

Return the device used to compute the prediction (CPU, MKL, …)

-
-
+
+

Examples and datasets

The package contains a few models stored in ONNX format used in the documentation. These don’t need to be downloaded as they are installed with the package.

-
-onnxruntime.datasets.get_example(name)[source]
+
+onnxruntime.datasets.get_example(name)[source]

Retrieves the absolute file name of an example.

-
-
-

Load and run a model

+ +
+

Load and run a model

ONNX Runtime reads a model saved in ONNX format. The main class InferenceSession wraps these functionalities in a single place.

+
+

Main class

-
-class onnxruntime.ModelMetadata
-

Pre-defined and custom metadata about the model. -It is usually used to identify the model used to run the prediction and -facilitate the comparison.

+
+class onnxruntime.InferenceSession(path_or_bytes, sess_options=None, providers=None, provider_options=None, **kwargs)[source]
+

This is the main class used to run a model.

+
+
Parameters
+
    +
  • path_or_bytes – filename or serialized ONNX or ORT format model in a byte string

  • +
  • sess_options – session options

  • +
  • providers – Optional sequence of providers in order of decreasing +precedence. Values can either be provider names or tuples of +(provider name, options dict). If not provided, then all available +providers are used with the default precedence.

  • +
  • provider_options – Optional sequence of options dicts corresponding +to the providers listed in ‘providers’.

  • +
+
+
+

The model type will be inferred unless explicitly set in the SessionOptions. +To explicitly set:

+
so = onnxruntime.SessionOptions()
+# so.add_session_config_entry('session.load_model_format', 'ONNX') or
+so.add_session_config_entry('session.load_model_format', 'ORT')
+
+
+

A file extension of ‘.ort’ will be inferred as an ORT format model. +All other filenames are assumed to be ONNX format models.

+

‘providers’ can contain either names or names and options. When any options +are given in ‘providers’, ‘provider_options’ should not be used.

+

The list of providers is ordered by precedence. For example +[‘CUDAExecutionProvider’, ‘CPUExecutionProvider’] +means execute a node using CUDAExecutionProvider +if capable, otherwise execute using CPUExecutionProvider.

-
-property custom_metadata_map
-

additional metadata

+
+disable_fallback()
+

Disable session.run() fallback mechanism.

-
-property description
-

description of the model

+
+enable_fallback()
+

Enable session.Run() fallback mechanism. If session.Run() fails due to an internal Execution Provider failure, +reset the Execution Providers enabled for this session. +If GPU is enabled, fall back to CUDAExecutionProvider. +otherwise fall back to CPUExecutionProvider.

-
-property domain
-

ONNX domain

+
+end_profiling()
+

End profiling and return results in a file.

+

The results are stored in a filename if the option +onnxruntime.SessionOptions.enable_profiling().

-
-property graph_description
-

description of the graph hosted in the model

+
+get_inputs()
+

Return the inputs metadata as a list of onnxruntime.NodeArg.

-
-property graph_name
-

graph name

+
+get_modelmeta()
+

Return the metadata. See onnxruntime.ModelMetadata.

-
-property producer_name
-

producer name

+
+get_outputs()
+

Return the outputs metadata as a list of onnxruntime.NodeArg.

-
-property version
-

version of the model

+
+get_overridable_initializers()
+

Return the inputs (including initializers) metadata as a list of onnxruntime.NodeArg.

+
+
+get_profiling_start_time_ns()
+

Return the nanoseconds of profiling’s start time +Comparable to time.monotonic_ns() after Python 3.3 +On some platforms, this timer may not be as precise as nanoseconds +For instance, on Windows and MacOS, the precision will be ~100ns

-
-
-class onnxruntime.InferenceSession(path_or_bytes, sess_options=None, providers=None, provider_options=None)[source]
-

This is the main class used to run a model. The next release (ORT 1.10) will require explicitly setting the providers parameter if you want to use execution providers other than the default CPU provider (as opposed to the current behavior of providers getting set/registered by default based on the build flags) when instantiating InferenceSession.

+
+
+get_provider_options()
+

Return registered execution providers’ configurations.

-
-
-class onnxruntime.NodeArg
-

Node argument definition, for both input and output, -including arg name, arg type (contains both type and shape).

-
-property name
-

node name

+
+get_providers()
+

Return list of registered execution providers.

-
-property shape
-

node shape (assuming the node holds a tensor)

+
+get_session_options()
+

Return the session options. See onnxruntime.SessionOptions.

-
-property type
-

node type

+
+io_binding()
+

Return an onnxruntime.IOBinding object`.

+
+
+run(output_names, input_feed, run_options=None)
+

Compute the predictions.

+
+
Parameters
+
    +
  • output_names – name of the outputs

  • +
  • input_feed – dictionary { input_name: input_value }

  • +
  • run_options – See onnxruntime.RunOptions.

  • +
+
+
+
sess.run([output_name], {input_name: x})
+
+
+
+
+run_with_iobinding(iobinding, run_options=None)
+

Compute the predictions.

+
+
Parameters
+
    +
  • iobinding – the iobinding object that has graph inputs/outputs bind.

  • +
  • run_options – See onnxruntime.RunOptions.

  • +
+
+
+
+ +
+
+run_with_ort_values(output_names, input_dict_ort_values, run_options=None)
+

Compute the predictions.

+
+
Parameters
+
    +
  • output_names – name of the outputs

  • +
  • input_feed – dictionary { input_name: input_ort_value } +See OrtValue class how to create OrtValue +from numpy array or SparseTensor

  • +
  • run_options – See onnxruntime.RunOptions.

  • +
+
+
Returns
+

an array of OrtValue

+
+
+
sess.run([output_name], {input_name: x})
+
+
+
+ +
+
+set_providers(providers=None, provider_options=None)
+

Register the input list of execution providers. The underlying session is re-created.

+
+
Parameters
+
    +
  • providers – Optional sequence of providers in order of decreasing +precedence. Values can either be provider names or tuples of +(provider name, options dict). If not provided, then all available +providers are used with the default precedence.

  • +
  • provider_options – Optional sequence of options dicts corresponding +to the providers listed in ‘providers’.

  • +
+
+
+

‘providers’ can contain either names or names and options. When any options +are given in ‘providers’, ‘provider_options’ should not be used.

+

The list of providers is ordered by precedence. For example +[‘CUDAExecutionProvider’, ‘CPUExecutionProvider’] +means execute a node using CUDAExecutionProvider if capable, +otherwise execute using CPUExecutionProvider.

+
+ +
+ +
+
+

Options

+
+

RunOptions

-
-class onnxruntime.RunOptions
+
+class onnxruntime.RunOptions(self: onnxruntime.capi.onnxruntime_pybind11_state.RunOptions) None

Configuration information for a single Run.

-
-
-property log_severity_level
+
+
+property log_severity_level

Log severity level for a particular Run() invocation. 0:Verbose, 1:Info, 2:Warning. 3:Error, 4:Fatal. Default is 2.

-
-
-property log_verbosity_level
+
+
+property log_verbosity_level

VLOG level if DEBUG build and run_log_severity_level is 0. Applies to a particular Run() invocation. Default is 0.

-
-
-property logid
+
+
+property logid

To identify logs generated by a particular Run() invocation.

-
-
-property only_execute_path_to_fetches
+
+
+property only_execute_path_to_fetches

Only execute the nodes needed by fetch list

-
-
-property terminate
+
+
+property terminate

Set to True to terminate any currently executing calls that are using this RunOptions instance. The individual calls will exit gracefully and return an error status.

+
+
+

SessionOptions

-
-class onnxruntime.SessionOptions
+
+class onnxruntime.SessionOptions(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions) None

Configuration information for a session.

-
-add_free_dimension_override_by_denotation(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: int)None
+
+add_free_dimension_override_by_denotation(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: int) None

Specify the dimension size for each denotation associated with an input’s free dimension.

-
-add_free_dimension_override_by_name(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: int)None
+
+add_free_dimension_override_by_name(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: int) None

Specify values of named dimensions within model inputs.

-
-add_initializer(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: object)None
+
+add_initializer(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: object) None
-
-add_session_config_entry(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: str)None
+
+add_session_config_entry(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str, arg1: str) None

Set a single session configuration entry as a pair of strings.

-
-
-property enable_cpu_mem_arena
+
+
+property enable_cpu_mem_arena

Enables the memory arena on CPU. Arena may pre-allocate memory for future usage. Set this option to false if you don’t want it. Default is True.

-
-
-property enable_mem_pattern
+
+
+property enable_mem_pattern

Enable the memory pattern optimization. Default is true.

-
-
-property enable_profiling
+
+
+property enable_mem_reuse
+

Enable the memory reuse optimization. Default is true.

+
+ +
+
+property enable_profiling

Enable profiling for this session. Default is false.

-
-
-property execution_mode
+
+
+property execution_mode

Sets the execution mode. Default is sequential.

-
-
-property execution_order
+
+
+property execution_order

Sets the execution order. Default is basic topological order.

-
-get_session_config_entry(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str)str
+
+get_session_config_entry(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str) str

Get a single session configuration value using the given configuration key.

-
-
-property graph_optimization_level
+
+
+property graph_optimization_level

Graph optimization level for this session.

-
-
-property inter_op_num_threads
+
+
+property inter_op_num_threads

Sets the number of threads used to parallelize the execution of the graph (across nodes). Default is 0 to let onnxruntime choose.

-
-
-property intra_op_num_threads
+
+
+property intra_op_num_threads

Sets the number of threads used to parallelize the execution within nodes. Default is 0 to let onnxruntime choose.

-
-
-property log_severity_level
+
+
+property log_severity_level

Log severity level. Applies to session load, initialization, etc. 0:Verbose, 1:Info, 2:Warning. 3:Error, 4:Fatal. Default is 2.

-
-
-property log_verbosity_level
+
+
+property log_verbosity_level

VLOG level if DEBUG build and session_log_severity_level is 0. Applies to session load, initialization, etc. Default is 0.

-
-
-property logid
+
+
+property logid

Logger id to use for session output.

-
-
-property optimized_model_filepath
-

File path to serialize optimized model to. +

+
+property optimized_model_filepath
+

File path to serialize optimized model to. Optimized model is not serialized unless optimized_model_filepath is set. -Serialized model format will default to ONNX unless:

-
-
    -
  • add_session_config_entry is used to set ‘session.save_model_format’ to ‘ORT’, or

  • -
  • there is no ‘session.save_model_format’ config entry and optimized_model_filepath ends in ‘.ort’ (case insensitive)

  • -
-
+Serialized model format will default to ONNX unless: +- add_session_config_entry is used to set ‘session.save_model_format’ to ‘ORT’, or +- there is no ‘session.save_model_format’ config entry and optimized_model_filepath ends in ‘.ort’ (case insensitive)

-
-
-property profile_file_prefix
+
+
+property profile_file_prefix

The prefix of the profile file. The current time will be appended to the file name.

-
-register_custom_ops_library(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str)None
+
+register_custom_ops_library(self: onnxruntime.capi.onnxruntime_pybind11_state.SessionOptions, arg0: str) None

Specify the path to the shared library containing the custom op kernels required to run a model.

-
-
-property use_deterministic_compute
+
+
+property use_deterministic_compute

Whether to use deterministic compute. Default is false.

+
+
+
+

Data

+
+

OrtValue

+
+
+class onnxruntime.OrtValue(ortvalue, numpy_obj=None)[source]
+

A data structure that supports all ONNX data formats (tensors and non-tensors) that allows users +to place the data backing these on a device, for example, on a CUDA supported device. +This class provides APIs to construct and deal with OrtValues.

+
+
+as_sparse_tensor()[source]
+

The function will return SparseTensor contained in this OrtValue

+
+ +
+
+data_ptr()[source]
+

Returns the address of the first element in the OrtValue’s data buffer

+
+ +
+
+data_type()[source]
+

Returns the data type of the data in the OrtValue

+
+ +
+
+device_name()[source]
+

Returns the name of the device where the OrtValue’s data buffer resides e.g. cpu, cuda

+
+ +
+
+has_value()[source]
+

Returns True if the OrtValue corresponding to an +optional type contains data, else returns False

+
+ +
+
+is_sparse_tensor()[source]
+

Returns True if the OrtValue contains a SparseTensor, else returns False

+
+ +
+
+is_tensor()[source]
+

Returns True if the OrtValue contains a Tensor, else returns False

+
+ +
+
+is_tensor_sequence()[source]
+

Returns True if the OrtValue contains a Tensor Sequence, else returns False

+
+ +
+
+numpy()[source]
+

Returns a Numpy object from the OrtValue. +Valid only for OrtValues holding Tensors. Throws for OrtValues holding non-Tensors. +Use accessors to gain a reference to non-Tensor objects such as SparseTensor

+
+ +
+
+static ort_value_from_sparse_tensor(sparse_tensor)[source]
+

The function will construct an OrtValue instance from a valid SparseTensor +The new instance of OrtValue will assume the ownership of sparse_tensor

+
+ +
+
+static ortvalue_from_numpy(numpy_obj, device_type='cpu', device_id=0)[source]
+

Factory method to construct an OrtValue (which holds a Tensor) from a given Numpy object +A copy of the data in the Numpy object is held by the OrtValue only if the device is NOT cpu

+
+
Parameters
+
    +
  • numpy_obj – The Numpy object to construct the OrtValue from

  • +
  • device_type – e.g. cpu, cuda, cpu by default

  • +
  • device_id – device id, e.g. 0

  • +
+
+
+
+ +
+
+static ortvalue_from_shape_and_type(shape=None, element_type=None, device_type='cpu', device_id=0)[source]
+

Factory method to construct an OrtValue (which holds a Tensor) from given shape and element_type

+
+
Parameters
+
    +
  • shape – List of integers indicating the shape of the OrtValue

  • +
  • element_type – The data type of the elements in the OrtValue (numpy type)

  • +
  • device_type – e.g. cpu, cuda, cpu by default

  • +
  • device_id – device id, e.g. 0

  • +
+
+
+
+ +
+
+shape()[source]
+

Returns the shape of the data in the OrtValue

+
+ +
+ +
+
+

SparseTensor

+
+
+class onnxruntime.SparseTensor(sparse_tensor)[source]
+

A data structure that project the C++ SparseTensor object +The class provides API to work with the object. +Depending on the format, the class will hold more than one buffer +depending on the format

+

Internal constructor

+
+
+as_blocksparse_view()[source]
+

The method will return coo representation of the sparse tensor which will enable +querying BlockSparse indices. If the instance did not contain BlockSparse format, it would throw. +You can query coo indices as:

+
block_sparse_indices = sparse_tensor.as_blocksparse_view().indices()
+
+
+

which will return a numpy array that is backed by the native memory

+
+ +
+
+as_coo_view()[source]
+

The method will return coo representation of the sparse tensor which will enable +querying COO indices. If the instance did not contain COO format, it would throw. +You can query coo indices as:

+
coo_indices = sparse_tensor.as_coo_view().indices()
+
+
+

which will return a numpy array that is backed by the native memory.

+
+ +
+
+as_csrc_view()[source]
+

The method will return CSR(C) representation of the sparse tensor which will enable +querying CRS(C) indices. If the instance dit not contain CSR(C) format, it would throw. +You can query indices as:

+
inner_ndices = sparse_tensor.as_csrc_view().inner()
+outer_ndices = sparse_tensor.as_csrc_view().outer()
+
-
-

Backend

+

returning numpy arrays backed by the native memory.

+
+ +
+
+data_type()[source]
+

Returns a string data type of the data in the OrtValue

+
+ +
+
+dense_shape()[source]
+

Returns a numpy array(int64) containing a dense shape of a sparse tensor

+
+ +
+
+device_name()[source]
+

Returns the name of the device where the SparseTensor data buffers reside e.g. cpu, cuda

+
+ +
+
+format()[source]
+

Returns a OrtSparseFormat enumeration

+
+ +
+
+static sparse_coo_from_numpy(dense_shape, values, coo_indices, ort_device)[source]
+

Factory method to construct a SparseTensor in COO format from given arguments

+
+
Parameters
+
    +
  • dense_shape – 1-D numpy array(int64) or a python list that contains a dense_shape of the sparse tensor +must be on cpu memory

  • +
  • values – a homogeneous, contiguous 1-D numpy array that contains non-zero elements of the tensor +of a type.

  • +
  • coo_indices – contiguous numpy array(int64) that contains COO indices for the tensor. coo_indices may +have a 1-D shape when it contains a linear index of non-zero values and its length must be equal to +that of the values. It can also be of 2-D shape, in which has it contains pairs of coordinates for +each of the nnz values and its length must be exactly twice of the values length.

  • +
  • ort_device

      +
    • describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is

    • +
    +

    suppored for non-numeric data types.

    +

  • +
+
+
+

For primitive types, the method will map values and coo_indices arrays into native memory and will use +them as backing storage. It will increment the reference count for numpy arrays and it will decrement it +on GC. The buffers may reside in any storage either CPU or GPU. +For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those +on other devices and their memory can not be mapped.

+
+ +
+
+static sparse_csr_from_numpy(dense_shape, values, inner_indices, outer_indices, ort_device)[source]
+

Factory method to construct a SparseTensor in CSR format from given arguments

+
+
Parameters
+
    +
  • dense_shape – 1-D numpy array(int64) or a python list that contains a dense_shape of the +sparse tensor (rows, cols) must be on cpu memory

  • +
  • values – a contiguous, homogeneous 1-D numpy array that contains non-zero elements of the tensor +of a type.

  • +
  • inner_indices – contiguous 1-D numpy array(int64) that contains CSR inner indices for the tensor. +Its length must be equal to that of the values.

  • +
  • outer_indices – contiguous 1-D numpy array(int64) that contains CSR outer indices for the tensor. +Its length must be equal to the number of rows + 1.

  • +
  • ort_device

      +
    • describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is

    • +
    +

    suppored for non-numeric data types.

    +

  • +
+
+
+

For primitive types, the method will map values and indices arrays into native memory and will use them as +backing storage. It will increment the reference count and it will decrement then count when it is GCed. +The buffers may reside in any storage either CPU or GPU. +For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those +on other devices and their memory can not be mapped.

+
+ +
+
+to_cuda(ort_device)[source]
+

Returns a copy of this instance on the specified cuda device

+
+
Parameters
+

ort_device – with name ‘cuda’ and valid gpu device id

+
+
+

The method will throw if:

+
    +
  • this instance contains strings

  • +
  • this instance is already on GPU. Cross GPU copy is not supported

  • +
  • CUDA is not present in this build

  • +
  • if the specified device is not valid

  • +
+
+ +
+
+values()[source]
+

The method returns a numpy array that is backed by the native memory +if the data type is numeric. Otherwise, the returned numpy array that contains +copies of the strings.

+
+ +
+ +
+
+
+

Devices

+
+

IOBinding

+
+
+class onnxruntime.IOBinding(session)[source]
+

This class provides API to bind input/output to a specified device, e.g. GPU.

+
+
+bind_cpu_input(name, arr_on_cpu)[source]
+

bind an input to array on CPU +:param name: input name +:param arr_on_cpu: input values as a python array on CPU

+
+ +
+
+bind_input(name, device_type, device_id, element_type, shape, buffer_ptr)[source]
+
+
Parameters
+
    +
  • name – input name

  • +
  • device_type – e.g. cpu, cuda

  • +
  • device_id – device id, e.g. 0

  • +
  • element_type – input element type

  • +
  • shape – input shape

  • +
  • buffer_ptr – memory pointer to input data

  • +
+
+
+
+ +
+
+bind_ortvalue_input(name, ortvalue)[source]
+
+
Parameters
+
    +
  • name – input name

  • +
  • ortvalue – OrtValue instance to bind

  • +
+
+
+
+ +
+
+bind_ortvalue_output(name, ortvalue)[source]
+
+
Parameters
+
    +
  • name – output name

  • +
  • ortvalue – OrtValue instance to bind

  • +
+
+
+
+ +
+
+bind_output(name, device_type='cpu', device_id=0, element_type=None, shape=None, buffer_ptr=None)[source]
+
+
Parameters
+
    +
  • name – output name

  • +
  • device_type – e.g. cpu, cuda, cpu by default

  • +
  • device_id – device id, e.g. 0

  • +
  • element_type – output element type

  • +
  • shape – output shape

  • +
  • buffer_ptr – memory pointer to output data

  • +
+
+
+
+ +
+
+copy_outputs_to_cpu()[source]
+

Copy output contents to CPU (if on another device). No-op if already on the CPU.

+
+ +
+
+get_outputs()[source]
+

Returns the output OrtValues from the Run() that preceded the call. +The data buffer of the obtained OrtValues may not reside on CPU memory

+
+ +
+ +
+
+

OrtDevice

+
+
+class onnxruntime.OrtDevice(c_ort_device)[source]
+

A data structure that exposes the underlying C++ OrtDevice

+

Internal constructor

+
+ +
+
+
+

Internal classes

+

These classes cannot be instantiated by users but they are returned +by methods or functions of this libary.

+
+

ModelMetadata

+
+
+class onnxruntime.ModelMetadata
+

Pre-defined and custom metadata about the model. +It is usually used to identify the model used to run the prediction and +facilitate the comparison.

+
+
+property custom_metadata_map
+

additional metadata

+
+ +
+
+property description
+

description of the model

+
+ +
+
+property domain
+

ONNX domain

+
+ +
+
+property graph_description
+

description of the graph hosted in the model

+
+ +
+
+property graph_name
+

graph name

+
+ +
+
+property producer_name
+

producer name

+
+ +
+
+property version
+

version of the model

+
+ +
+ +
+
+

NodeArg

+
+
+class onnxruntime.NodeArg
+

Node argument definition, for both input and output, +including arg name, arg type (contains both type and shape).

+
+
+property name
+

node name

+
+ +
+
+property shape
+

node shape (assuming the node holds a tensor)

+
+ +
+
+property type
+

node type

+
+ +
+ +
+
+
+
+

Backend

In addition to the regular API which is optimized for performance and usability, ONNX Runtime also implements the ONNX backend API for verification of ONNX specification conformance. The following functions are supported:

-
-onnxruntime.backend.is_compatible(model, device=None, **kwargs)
+
+onnxruntime.backend.is_compatible(model, device=None, **kwargs)

Return whether the model is compatible with the backend.

Parameters
@@ -464,8 +1085,8 @@

Backend -
-onnxruntime.backend.prepare(model, device=None, **kwargs)
+
+onnxruntime.backend.prepare(model, device=None, **kwargs)

Load the model and creates a onnxruntime.InferenceSession ready to be used as a backend.

@@ -486,8 +1107,8 @@

Backend -
-onnxruntime.backend.run(model, inputs, device=None, **kwargs)
+
+onnxruntime.backend.run(model, inputs, device=None, **kwargs)

Compute the prediction.

Parameters
@@ -508,26 +1129,77 @@

Backend -
-onnxruntime.backend.supports_device(device)
+
+onnxruntime.backend.supports_device(device)

Check whether the backend is compiled with particular device support. In particular it’s used in the testing suite.

-

-
+ + + +
+ @@ -255,7 +256,7 @@

Related Topics

Quick search

@@ -277,7 +278,7 @@

Quick search

©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_convert_pipeline_vectorizer.html b/docs/api/python/auto_examples/plot_convert_pipeline_vectorizer.html index 77501af9fcdca..063fe38ba0cb9 100644 --- a/docs/api/python/auto_examples/plot_convert_pipeline_vectorizer.html +++ b/docs/api/python/auto_examples/plot_convert_pipeline_vectorizer.html @@ -4,16 +4,17 @@ - - Train, convert and predict with ONNX Runtime — ONNX Runtime 1.7.0 documentation - - + + + Train, convert and predict with ONNX Runtime — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -42,7 +43,7 @@

Click here to download the full example code

-
+

Train, convert and predict with ONNX Runtime

This example demonstrates an end to end scenario starting with the training of a scikit-learn pipeline @@ -55,24 +56,63 @@

  • Conversion to ONNX format

  • -
    +

    Train a pipeline

    The first step consists in retrieving the boston datset.

    import pandas
    -from sklearn.datasets import load_boston
    +from sklearn.datasets import load_boston
     boston = load_boston()
     X, y = boston.data, boston.target
     
    -from sklearn.model_selection import train_test_split
    +from sklearn.model_selection import train_test_split
     X_train, X_test, y_train, y_test = train_test_split(X, y)
     X_train_dict = pandas.DataFrame(X_train[:,1:]).T.to_dict().values()
     X_test_dict = pandas.DataFrame(X_test[:,1:]).T.to_dict().values()
     
    +

    Out:

    +
    /home/runner/.local/lib/python3.8/site-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function load_boston is deprecated; `load_boston` is deprecated in 1.0 and will be removed in 1.2.
    +
    +    The Boston housing prices dataset has an ethical problem. You can refer to
    +    the documentation of this function for further details.
    +
    +    The scikit-learn maintainers therefore strongly discourage the use of this
    +    dataset unless the purpose of the code is to study and educate about
    +    ethical issues in data science and machine learning.
    +
    +    In this special case, you can fetch the dataset from the original
    +    source::
    +
    +        import pandas as pd
    +        import numpy as np
    +
    +
    +        data_url = "http://lib.stat.cmu.edu/datasets/boston"
    +        raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None)
    +        data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])
    +        target = raw_df.values[1::2, 2]
    +
    +    Alternative datasets include the California housing dataset (i.e.
    +    :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing
    +    dataset. You can load the datasets as follows::
    +
    +        from sklearn.datasets import fetch_california_housing
    +        housing = fetch_california_housing()
    +
    +    for the California housing dataset and::
    +
    +        from sklearn.datasets import fetch_openml
    +        housing = fetch_openml(name="house_prices", as_frame=True)
    +
    +    for the Ames housing dataset.
    +
    +  warnings.warn(msg, category=FutureWarning)
    +
    +

    We create a pipeline.

    -
    from sklearn.pipeline import make_pipeline
    -from sklearn.ensemble import GradientBoostingRegressor
    -from sklearn.feature_extraction import DictVectorizer
    +
    from sklearn.pipeline import make_pipeline
    +from sklearn.ensemble import GradientBoostingRegressor
    +from sklearn.feature_extraction import DictVectorizer
     pipe = make_pipeline(
                 DictVectorizer(sparse=False),
                 GradientBoostingRegressor())
    @@ -87,24 +127,24 @@ 

    Train a pipeline

    We compute the prediction on the test set and we show the confusion matrix.

    -
    from sklearn.metrics import r2_score
    +
    from sklearn.metrics import r2_score
     
     pred = pipe.predict(X_test_dict)
     print(r2_score(y_test, pred))
     

    Out:

    -
    0.848444978558249
    +
    0.9209977605173356
     
    -
    -
    +

    +

    Conversion to ONNX format

    We use module sklearn-onnx to convert the model into ONNX format.

    -
    +
    @@ -212,7 +252,7 @@

    Related Topics

    Quick search

    @@ -234,7 +274,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_dl_keras.html b/docs/api/python/auto_examples/plot_dl_keras.html deleted file mode 100644 index 6b91709778485..0000000000000 --- a/docs/api/python/auto_examples/plot_dl_keras.html +++ /dev/null @@ -1,216 +0,0 @@ - - - - - - - - ONNX Runtime for Keras — ONNX Runtime 1.6.0 documentation - - - - - - - - - - - - - - - - - - - - - - -
    -
    -
    - - -
    - - -
    -

    ONNX Runtime for Keras

    -

    The following demonstrates how to compute the predictions -of a pretrained deep learning model obtained from -keras -with onnxruntime. The conversion requires -keras, -tensorflow, -keras-onnx, -onnxmltools -but then only onnxruntime is required -to compute the predictions.

    -
    import os
    -if not os.path.exists('dense121.onnx'):
    -    from keras.applications.densenet import DenseNet121
    -    model = DenseNet121(include_top=True, weights='imagenet')
    -
    -    from keras2onnx import convert_keras
    -    onx = convert_keras(model, 'dense121.onnx')
    -    with open("dense121.onnx", "wb") as f:
    -        f.write(onx.SerializeToString())
    -
    -
    -
    Traceback (most recent call last):
    -  File "C:\xadupre\microsoft_xadupre\onnxruntime\docs\python\examples\plot_dl_keras.py", line 28, in <module>
    -    onx = convert_keras(model, 'dense121.onnx')
    -  File "C:\xadupre\microsoft_xadupre\keras-onnx\keras2onnx\main.py", line 82, in convert_keras
    -    tf_graph = build_layer_output_from_model(model, output_dict, input_names,
    -  File "C:\xadupre\microsoft_xadupre\keras-onnx\keras2onnx\_parser_tf.py", line 308, in build_layer_output_from_model
    -    graph = model.outputs[0].graph
    -AttributeError: 'KerasTensor' object has no attribute 'graph'
    -
    -
    -

    Let’s load an image (source: wikipedia).

    -
    from keras.preprocessing.image import array_to_img, img_to_array, load_img
    -img = load_img('Sannosawa1.jpg')
    -ximg = img_to_array(img)
    -
    -import matplotlib.pyplot as plt
    -plt.imshow(ximg / 255)
    -plt.axis('off')
    -
    -
    -

    Let’s load the model with onnxruntime.

    -
    import onnxruntime as rt
    -from onnxruntime.capi.onnxruntime_pybind11_state import InvalidGraph
    -
    -try:
    -    sess = rt.InferenceSession('dense121.onnx')
    -    ok = True
    -except (InvalidGraph, TypeError, RuntimeError) as e:
    -    # Probably a mismatch between onnxruntime and onnx version.
    -    print(e)
    -    ok = False
    -
    -if ok:
    -    print("The model expects input shape:", sess.get_inputs()[0].shape)
    -    print("image shape:", ximg.shape)
    -
    -
    -

    Let’s resize the image.

    -
    if ok:
    -    from skimage.transform import resize
    -    import numpy
    -
    -    ximg224 = resize(ximg / 255, (224, 224, 3), anti_aliasing=True)
    -    ximg = ximg224[numpy.newaxis, :, :, :]
    -    ximg = ximg.astype(numpy.float32)
    -
    -    print("new shape:", ximg.shape)
    -
    -
    -

    Let’s compute the output.

    -
    if ok:
    -    input_name = sess.get_inputs()[0].name
    -    res = sess.run(None, {input_name: ximg})
    -    prob = res[0]
    -    print(prob.ravel()[:10])  # Too big to be displayed.
    -
    -
    -

    Let’s get more comprehensive results.

    -
    if ok:
    -    from keras.applications.densenet import decode_predictions
    -    decoded = decode_predictions(prob)
    -
    -    import pandas
    -    df = pandas.DataFrame(decoded[0], columns=["class_id", "name", "P"])
    -    print(df)
    -
    -
    -

    Total running time of the script: ( 0 minutes 6.417 seconds)

    - -

    Gallery generated by Sphinx-Gallery

    -
    - - -
    - -
    -
    - -
    -
    - - - - - - - \ No newline at end of file diff --git a/docs/api/python/auto_examples/plot_load_and_predict.html b/docs/api/python/auto_examples/plot_load_and_predict.html index 0d04cc3019c55..4a088a2b907c4 100644 --- a/docs/api/python/auto_examples/plot_load_and_predict.html +++ b/docs/api/python/auto_examples/plot_load_and_predict.html @@ -4,16 +4,17 @@ - - Load and predict with ONNX Runtime and a very simple model — ONNX Runtime 1.7.0 documentation - - + + + Load and predict with ONNX Runtime and a very simple model — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -42,27 +43,20 @@

    Click here to download the full example code

    -
    +

    Load and predict with ONNX Runtime and a very simple model

    This example demonstrates how to load a model and compute the output for an input vector. It also shows how to retrieve the definition of its inputs and outputs.

    import onnxruntime as rt
     import numpy
    -from onnxruntime.datasets import get_example
    +from onnxruntime.datasets import get_example
     

    Let’s load a very simple model. -The model is available on github onnx…test_sigmoid. -Note: The next release (ORT 1.10) will require explicitly setting -the providers parameter if you want to use execution providers other -than the default CPU provider (as opposed to the current behavior of -providers getting set/registered by default based on the build flags) when -instantiating InferenceSession. Following code assumes NVIDIA GPU is available, -you can specify other execution providers or don't include providers parameter -to use default CPU provider.

    +The model is available on github onnx…test_sigmoid.

    example1 = get_example("sigmoid.onnx")
    -sess = rt.InferenceSession(example1, providers=["CUDAExecutionProvider"])
    +sess = rt.InferenceSession(example1, providers=rt.get_available_providers())
     

    Let’s see the input name and shape.

    @@ -104,24 +98,24 @@

    Out:

    -
    [array([[[0.56617785, 0.551158  , 0.57431483, 0.62868774, 0.5294609 ],
    -        [0.6545371 , 0.64250827, 0.6819708 , 0.5105157 , 0.5584753 ],
    -        [0.66830933, 0.7094791 , 0.70664704, 0.6744693 , 0.7030401 ],
    -        [0.5395019 , 0.7210481 , 0.5845876 , 0.59664494, 0.6563896 ]],
    -
    -       [[0.71235013, 0.6528918 , 0.5907483 , 0.66855776, 0.61100346],
    -        [0.51468205, 0.60125333, 0.5410304 , 0.57149607, 0.56778824],
    -        [0.5155948 , 0.54921585, 0.5138594 , 0.7051111 , 0.62632954],
    -        [0.5651827 , 0.55247986, 0.6941072 , 0.50415695, 0.7062323 ]],
    -
    -       [[0.51758766, 0.67160237, 0.59442437, 0.5007695 , 0.56175166],
    -        [0.72844744, 0.5150477 , 0.5052765 , 0.5447472 , 0.7088654 ],
    -        [0.596162  , 0.5197903 , 0.6099661 , 0.724396  , 0.5885481 ],
    -        [0.6910895 , 0.53817046, 0.596786  , 0.6119356 , 0.5707261 ]]],
    +
    [array([[[0.6423601 , 0.65232253, 0.6620137 , 0.708999  , 0.65169865],
    +        [0.548968  , 0.59544575, 0.7161434 , 0.525905  , 0.7210646 ],
    +        [0.5178277 , 0.5842683 , 0.5627599 , 0.6324704 , 0.5833795 ],
    +        [0.69634616, 0.60848683, 0.6746977 , 0.50677085, 0.5549751 ]],
    +
    +       [[0.5097179 , 0.59407187, 0.56360227, 0.7223234 , 0.5392329 ],
    +        [0.5398089 , 0.5622808 , 0.5369593 , 0.5819309 , 0.5735331 ],
    +        [0.5688669 , 0.71247685, 0.63964766, 0.63349843, 0.63380575],
    +        [0.64378905, 0.60552883, 0.5184905 , 0.6312441 , 0.5047166 ]],
    +
    +       [[0.63900065, 0.6108959 , 0.5249817 , 0.5055595 , 0.55390376],
    +        [0.62443805, 0.550723  , 0.5320551 , 0.5522731 , 0.68858314],
    +        [0.69650024, 0.54673976, 0.56964463, 0.58536506, 0.5743989 ],
    +        [0.6382853 , 0.5826889 , 0.53635114, 0.52279866, 0.7300966 ]]],
           dtype=float32)]
     
    -

    Total running time of the script: ( 0 minutes 0.012 seconds)

    +

    Total running time of the script: ( 0 minutes 0.013 seconds)

    Gallery generated by Sphinx-Gallery

    -
    +
    @@ -174,7 +168,7 @@

    Related Topics

    Quick search

    @@ -196,7 +190,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_metadata.html b/docs/api/python/auto_examples/plot_metadata.html index 7c6d669165569..c17fbe6318ce8 100644 --- a/docs/api/python/auto_examples/plot_metadata.html +++ b/docs/api/python/auto_examples/plot_metadata.html @@ -4,16 +4,17 @@ - - Metadata — ONNX Runtime 1.7.0 documentation - - + + + Metadata — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -42,7 +43,7 @@

    Click here to download the full example code

    -
    +

    Metadata

    ONNX format contains metadata related to how the model was produced. It is useful when the model @@ -51,7 +52,7 @@ Let’s see how to do that with a simple logistic regression model trained with scikit-learn and converted with sklearn-onnx.

    -
    from onnxruntime.datasets import get_example
    +
    from onnxruntime.datasets import get_example
     example = get_example("logreg_iris.onnx")
     
     import onnx
    @@ -77,8 +78,8 @@
     

    With ONNX Runtime:

    -
    from onnxruntime import InferenceSession
    -sess = InferenceSession(example)
    +
    import onnxruntime as rt
    +sess = rt.InferenceSession(example, providers=rt.get_available_providers())
     meta = sess.get_modelmeta()
     
     print("custom_metadata_map={}".format(meta.custom_metadata_map))
    @@ -98,7 +99,7 @@
     version=0
     
    -

    Total running time of the script: ( 0 minutes 0.006 seconds)

    +

    Total running time of the script: ( 0 minutes 0.005 seconds)

    Gallery generated by Sphinx-Gallery

    -
    +
    @@ -151,7 +152,7 @@

    Related Topics

    Quick search

    @@ -173,7 +174,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_pipeline.html b/docs/api/python/auto_examples/plot_pipeline.html index 801f6fe9ef37d..c8e8705dc666b 100644 --- a/docs/api/python/auto_examples/plot_pipeline.html +++ b/docs/api/python/auto_examples/plot_pipeline.html @@ -4,16 +4,17 @@ - - Draw a pipeline — ONNX Runtime 1.7.0 documentation - - + + + Draw a pipeline — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -42,7 +43,7 @@

    Click here to download the full example code

    -
    +

    Draw a pipeline

    There is no other way to look into one model stored in ONNX format than looking into its node with @@ -55,10 +56,10 @@

  • Draw a model with ONNX

  • -
    +

    Retrieve a model in JSON format

    That’s the most simple way.

    -
    from onnxruntime.datasets import get_example
    +
    from onnxruntime.datasets import get_example
     example1 = get_example("mul_1.onnx")
     
     import onnx
    @@ -130,14 +131,14 @@ 

    Retrieve a model in JSON format

    -
    -
    +
    +

    Draw a model with ONNX

    We use net_drawer.py included in onnx package. We use onnx to load the model in a different way than before.

    -
    +
    @@ -225,7 +225,7 @@

    Related Topics

    Quick search

    @@ -247,7 +247,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_profiling.html b/docs/api/python/auto_examples/plot_profiling.html index 058efa16252ea..e8c9aa4385043 100644 --- a/docs/api/python/auto_examples/plot_profiling.html +++ b/docs/api/python/auto_examples/plot_profiling.html @@ -4,16 +4,17 @@ - - Profile the execution of a simple model — ONNX Runtime 1.7.0 documentation - - + + + Profile the execution of a simple model — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -42,14 +43,14 @@

    Click here to download the full example code

    -
    +

    Profile the execution of a simple model

    ONNX Runtime can profile the execution of the model. This example shows how to interpret the results.

    import onnx
     import onnxruntime as rt
     import numpy
    -from onnxruntime.datasets import get_example
    +from onnxruntime.datasets import get_example
     
     
     def change_ir_version(filename, ir_version=6):
    @@ -66,7 +67,7 @@
     
    example1 = get_example("mul_1.onnx")
     onnx_model = change_ir_version(example1)
     onnx_model_str = onnx_model.SerializeToString()
    -sess = rt.InferenceSession(onnx_model_str)
    +sess = rt.InferenceSession(onnx_model_str, providers=rt.get_available_providers())
     input_name = sess.get_inputs()[0].name
     
     x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)
    @@ -84,7 +85,7 @@
     before running the predictions.

    options = rt.SessionOptions()
     options.enable_profiling = True
    -sess_profile = rt.InferenceSession(onnx_model_str, options)
    +sess_profile = rt.InferenceSession(onnx_model_str, options, providers=rt.get_available_providers())
     input_name = sess.get_inputs()[0].name
     
     x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)
    @@ -95,7 +96,7 @@
     

    Out:

    -
    onnxruntime_profile__2021-03-04_18-40-00.json
    +
    onnxruntime_profile__2022-01-04_17-09-55.json
     

    The results are stored un a file in JSON format. @@ -110,23 +111,23 @@

    Out:

    [{'args': {},
       'cat': 'Session',
    -  'dur': 101,
    +  'dur': 56,
       'name': 'model_loading_array',
       'ph': 'X',
    -  'pid': 77,
    -  'tid': 77,
    -  'ts': 3},
    +  'pid': 3089,
    +  'tid': 3089,
    +  'ts': 1},
      {'args': {},
       'cat': 'Session',
    -  'dur': 227,
    +  'dur': 240,
       'name': 'session_initialization',
       'ph': 'X',
    -  'pid': 77,
    -  'tid': 77,
    -  'ts': 134}]
    +  'pid': 3089,
    +  'tid': 3089,
    +  'ts': 71}]
     
    -

    Total running time of the script: ( 0 minutes 0.010 seconds)

    +

    Total running time of the script: ( 0 minutes 0.007 seconds)

    Gallery generated by Sphinx-Gallery

    -
    +
    @@ -179,7 +180,7 @@

    Related Topics

    Quick search

    @@ -201,7 +202,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/plot_train_convert_predict.html b/docs/api/python/auto_examples/plot_train_convert_predict.html index f5678cff23651..9b451dc80273b 100644 --- a/docs/api/python/auto_examples/plot_train_convert_predict.html +++ b/docs/api/python/auto_examples/plot_train_convert_predict.html @@ -4,16 +4,17 @@ - - Train, convert and predict with ONNX Runtime — ONNX Runtime 1.7.0 documentation - - + + + Train, convert and predict with ONNX Runtime — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -41,7 +42,7 @@

    Click here to download the full example code

    -
    +

    Train, convert and predict with ONNX Runtime

    This example demonstrates an end to end scenario starting with the training of a machine learned model @@ -54,58 +55,49 @@

  • Benchmark with RandomForest

  • -
    +

    Train a logistic regression

    The first step consists in retrieving the iris datset.

    -
    from sklearn.datasets import load_iris
    +
    from sklearn.datasets import load_iris
     iris = load_iris()
     X, y = iris.data, iris.target
     
    -from sklearn.model_selection import train_test_split
    +from sklearn.model_selection import train_test_split
     X_train, X_test, y_train, y_test = train_test_split(X, y)
     

    Then we fit a model.

    -
    from sklearn.linear_model import LogisticRegression
    +
    from sklearn.linear_model import LogisticRegression
     clr = LogisticRegression()
     clr.fit(X_train, y_train)
     

    Out:

    -
    /opt/miniconda/lib/python3.7/site-packages/sklearn/linear_model/_logistic.py:765: ConvergenceWarning: lbfgs failed to converge (status=1):
    -STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
    -
    -Increase the number of iterations (max_iter) or scale the data as shown in:
    -    https://scikit-learn.org/stable/modules/preprocessing.html
    -Please also refer to the documentation for alternative solver options:
    -    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
    -  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
    -
    -LogisticRegression()
    +
    LogisticRegression()
     

    We compute the prediction on the test set and we show the confusion matrix.

    -
    from sklearn.metrics import confusion_matrix
    +
    from sklearn.metrics import confusion_matrix
     
     pred = clr.predict(X_test)
     print(confusion_matrix(y_test, pred))
     

    Out:

    -
    [[10  0  0]
    - [ 0 14  0]
    - [ 0  1 13]]
    +
    [[13  0  0]
    + [ 0 10  1]
    + [ 0  0 14]]
     
    -
    -
    +
    +

    Conversion to ONNX format

    We use module sklearn-onnx to convert the model into ONNX format.

    -
    from skl2onnx import convert_sklearn
    -from skl2onnx.common.data_types import FloatTensorType
    +
    +

    Probabilities

    Probabilities are needed to compute other relevant metrics such as the ROC Curve. @@ -157,9 +149,9 @@

    Probabilities

    Out:

    -
    [[4.15987711e-03 8.54898335e-01 1.40941788e-01]
    - [9.44228260e-01 5.57707615e-02 9.78002823e-07]
    - [5.17324282e-02 8.88396143e-01 5.98714288e-02]]
    +
    [[2.95951945e-05 5.69800366e-02 9.42990368e-01]
    + [1.84923705e-05 3.93636566e-02 9.60617851e-01]
    + [1.30004554e-02 8.03678159e-01 1.83321386e-01]]
     

    And then with ONNX Runtime. @@ -172,13 +164,13 @@

    Probabilities

    Out:

    -
    [{0: 0.0041598789393901825, 1: 0.8548984527587891, 2: 0.14094172418117523},
    - {0: 0.9442282915115356, 1: 0.055770788341760635, 2: 9.78002844931325e-07},
    - {0: 0.05173242464661598, 1: 0.888396143913269, 2: 0.05987146869301796}]
    +
    [{0: 2.9595235901069827e-05, 1: 0.05698008090257645, 2: 0.9429903030395508},
    + {0: 1.8492364688427188e-05, 1: 0.03936365991830826, 2: 0.9606178402900696},
    + {0: 0.013000461272895336, 1: 0.8036782741546631, 2: 0.1833212822675705}]
     

    Let’s benchmark.

    -
    from timeit import Timer
    +
    -
    + +

    Benchmark with RandomForest

    We first train and save a model in ONNX format.

    -
    from sklearn.ensemble import RandomForestClassifier
    +
    from sklearn.ensemble import RandomForestClassifier
     rf = RandomForestClassifier()
     rf.fit(X_train, y_train)
     
    @@ -273,7 +265,7 @@ 

    Benchmark with RandomForest
    sess = rt.InferenceSession("rf_iris.onnx")
    +
    -Speed comparison between scikit-learn and ONNX Runtime For a random forest on Iris dataset
    -

    Out:

    +Speed comparison between scikit-learn and ONNX Runtime For a random forest on Iris dataset

    Out:

    5
    -Average 0.11 min=0.107 max=0.118
    -Average 0.00169 min=0.00161 max=0.00177
    +Average 0.0637 min=0.0636 max=0.0639
    +Average 0.000869 min=0.000857 max=0.000899
     10
    -Average 0.167 min=0.165 max=0.169
    -Average 0.0017 min=0.00165 max=0.00179
    +Average 0.0982 min=0.098 max=0.0987
    +Average 0.000884 min=0.000873 max=0.00091
     15
    -Average 0.228 min=0.227 max=0.231
    -Average 0.0017 min=0.00167 max=0.00172
    +Average 0.133 min=0.133 max=0.133
    +Average 0.000895 min=0.000885 max=0.000921
     20
    -Average 0.291 min=0.286 max=0.296
    -Average 0.00175 min=0.00173 max=0.00176
    +Average 0.168 min=0.167 max=0.168
    +Average 0.000915 min=0.000907 max=0.00094
     25
    -Average 0.346 min=0.342 max=0.35
    -Average 0.00174 min=0.00172 max=0.00181
    +Average 0.202 min=0.201 max=0.203
    +Average 0.000921 min=0.000913 max=0.000948
     30
    -Average 0.407 min=0.404 max=0.41
    -Average 0.0018 min=0.00174 max=0.0019
    +Average 0.236 min=0.236 max=0.237
    +Average 0.000922 min=0.000914 max=0.000948
     35
    -Average 0.463 min=0.459 max=0.467
    -Average 0.0018 min=0.00176 max=0.00187
    +Average 0.271 min=0.271 max=0.271
    +Average 0.000941 min=0.000928 max=0.000967
     40
    -Average 0.531 min=0.521 max=0.556
    -Average 0.0018 min=0.00179 max=0.00183
    +Average 0.305 min=0.305 max=0.305
    +Average 0.000948 min=0.000934 max=0.000977
     45
    -Average 0.582 min=0.577 max=0.597
    -Average 0.00187 min=0.00185 max=0.00189
    +Average 0.34 min=0.339 max=0.34
    +Average 0.000983 min=0.000972 max=0.00101
     50
    -Average 0.642 min=0.64 max=0.645
    -Average 0.00188 min=0.00185 max=0.00196
    +Average 0.375 min=0.374 max=0.375
    +Average 0.000972 min=0.000966 max=0.000992
     
    -<matplotlib.legend.Legend object at 0x7fca300dcda0>
    +<matplotlib.legend.Legend object at 0x7feaf2025c10>
     
    -

    Total running time of the script: ( 5 minutes 52.417 seconds)

    +

    Total running time of the script: ( 3 minutes 22.159 seconds)

    +

    +
    @@ -412,7 +403,7 @@

    Related Topics

    Quick search

    @@ -434,7 +425,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/auto_examples/sg_execution_times.html b/docs/api/python/auto_examples/sg_execution_times.html index 28af50a188cec..fbc71647b8669 100644 --- a/docs/api/python/auto_examples/sg_execution_times.html +++ b/docs/api/python/auto_examples/sg_execution_times.html @@ -4,16 +4,17 @@ - - Computation times — ONNX Runtime 1.7.0 documentation - - + + + Computation times — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -35,9 +36,9 @@
    -
    +

    Computation times

    -

    05:52.417 total execution time for auto_examples files:

    +

    03:23.370 total execution time for auto_examples files:

    @@ -46,40 +47,40 @@ - + - - + + - - + + - - + + - + - - + + - - + + - - + +

    Train, convert and predict with ONNX Runtime (plot_train_convert_predict.py)

    05:52.417

    03:22.159

    0.0 MB

    ONNX Runtime Backend for ONNX (plot_backend.py)

    00:00.000

    Train, convert and predict with ONNX Runtime (plot_convert_pipeline_vectorizer.py)

    00:00.966

    0.0 MB

    Common errors with onnxruntime (plot_common_errors.py)

    00:00.000

    Draw a pipeline (plot_pipeline.py)

    00:00.196

    0.0 MB

    Train, convert and predict with ONNX Runtime (plot_convert_pipeline_vectorizer.py)

    00:00.000

    ONNX Runtime Backend for ONNX (plot_backend.py)

    00:00.014

    0.0 MB

    Load and predict with ONNX Runtime and a very simple model (plot_load_and_predict.py)

    00:00.000

    00:00.013

    0.0 MB

    Metadata (plot_metadata.py)

    00:00.000

    Common errors with onnxruntime (plot_common_errors.py)

    00:00.009

    0.0 MB

    Draw a pipeline (plot_pipeline.py)

    00:00.000

    Profile the execution of a simple model (plot_profiling.py)

    00:00.007

    0.0 MB

    Profile the execution of a simple model (plot_profiling.py)

    00:00.000

    Metadata (plot_metadata.py)

    00:00.005

    0.0 MB

    -
    +
    @@ -118,7 +119,7 @@

    Related Topics

    Quick search

    @@ -140,7 +141,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip b/docs/api/python/downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip index c1b5af3fb627f..45a147fd36b34 100644 Binary files a/docs/api/python/downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip and b/docs/api/python/downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip differ diff --git a/docs/api/python/downloads/1680115d3d937dfbb2d86adb705d9c5d/plot_train_convert_predict.ipynb b/docs/api/python/downloads/1680115d3d937dfbb2d86adb705d9c5d/plot_train_convert_predict.ipynb index 54589b00af045..eee04c34d6f1f 100644 --- a/docs/api/python/downloads/1680115d3d937dfbb2d86adb705d9c5d/plot_train_convert_predict.ipynb +++ b/docs/api/python/downloads/1680115d3d937dfbb2d86adb705d9c5d/plot_train_convert_predict.ipynb @@ -98,7 +98,7 @@ }, "outputs": [], "source": [ - "import onnxruntime as rt\nsess = rt.InferenceSession(\"logreg_iris.onnx\")\n\nprint(\"input name='{}' and shape={}\".format(\n sess.get_inputs()[0].name, sess.get_inputs()[0].shape))\nprint(\"output name='{}' and shape={}\".format(\n sess.get_outputs()[0].name, sess.get_outputs()[0].shape))" + "import onnxruntime as rt\nsess = rt.InferenceSession(\"logreg_iris.onnx\", providers=rt.get_available_providers())\n\nprint(\"input name='{}' and shape={}\".format(\n sess.get_inputs()[0].name, sess.get_inputs()[0].shape))\nprint(\"output name='{}' and shape={}\".format(\n sess.get_outputs()[0].name, sess.get_outputs()[0].shape))" ] }, { @@ -249,7 +249,7 @@ }, "outputs": [], "source": [ - "sess = rt.InferenceSession(\"rf_iris.onnx\")\n\ndef sess_predict_proba_rf(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n\nprint(\"Execution time for predict_proba\")\nspeed(\"loop(X_test, rf.predict_proba, 100)\")\n\nprint(\"Execution time for sess_predict_proba\")\nspeed(\"loop(X_test, sess_predict_proba_rf, 100)\")" + "sess = rt.InferenceSession(\"rf_iris.onnx\", providers=rt.get_available_providers())\n\ndef sess_predict_proba_rf(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n\nprint(\"Execution time for predict_proba\")\nspeed(\"loop(X_test, rf.predict_proba, 100)\")\n\nprint(\"Execution time for sess_predict_proba\")\nspeed(\"loop(X_test, sess_predict_proba_rf, 100)\")" ] }, { @@ -267,7 +267,7 @@ }, "outputs": [], "source": [ - "measures = []\n\nfor n_trees in range(5, 51, 5): \n print(n_trees)\n rf = RandomForestClassifier(n_estimators=n_trees)\n rf.fit(X_train, y_train)\n initial_type = [('float_input', FloatTensorType([1, 4]))]\n onx = convert_sklearn(rf, initial_types=initial_type)\n with open(\"rf_iris_%d.onnx\" % n_trees, \"wb\") as f:\n f.write(onx.SerializeToString())\n sess = rt.InferenceSession(\"rf_iris_%d.onnx\" % n_trees)\n def sess_predict_proba_loop(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n tsk = speed(\"loop(X_test, rf.predict_proba, 100)\", number=5, repeat=5)\n trt = speed(\"loop(X_test, sess_predict_proba_loop, 100)\", number=5, repeat=5)\n measures.append({'n_trees': n_trees, 'sklearn': tsk, 'rt': trt})\n\nfrom pandas import DataFrame\ndf = DataFrame(measures)\nax = df.plot(x=\"n_trees\", y=\"sklearn\", label=\"scikit-learn\", c=\"blue\", logy=True)\ndf.plot(x=\"n_trees\", y=\"rt\", label=\"onnxruntime\",\n ax=ax, c=\"green\", logy=True)\nax.set_xlabel(\"Number of trees\")\nax.set_ylabel(\"Prediction time (s)\")\nax.set_title(\"Speed comparison between scikit-learn and ONNX Runtime\\nFor a random forest on Iris dataset\")\nax.legend()" + "measures = []\n\nfor n_trees in range(5, 51, 5): \n print(n_trees)\n rf = RandomForestClassifier(n_estimators=n_trees)\n rf.fit(X_train, y_train)\n initial_type = [('float_input', FloatTensorType([1, 4]))]\n onx = convert_sklearn(rf, initial_types=initial_type)\n with open(\"rf_iris_%d.onnx\" % n_trees, \"wb\") as f:\n f.write(onx.SerializeToString())\n sess = rt.InferenceSession(\"rf_iris_%d.onnx\" % n_trees, providers=rt.get_available_providers())\n def sess_predict_proba_loop(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n tsk = speed(\"loop(X_test, rf.predict_proba, 100)\", number=5, repeat=5)\n trt = speed(\"loop(X_test, sess_predict_proba_loop, 100)\", number=5, repeat=5)\n measures.append({'n_trees': n_trees, 'sklearn': tsk, 'rt': trt})\n\nfrom pandas import DataFrame\ndf = DataFrame(measures)\nax = df.plot(x=\"n_trees\", y=\"sklearn\", label=\"scikit-learn\", c=\"blue\", logy=True)\ndf.plot(x=\"n_trees\", y=\"rt\", label=\"onnxruntime\",\n ax=ax, c=\"green\", logy=True)\nax.set_xlabel(\"Number of trees\")\nax.set_ylabel(\"Prediction time (s)\")\nax.set_title(\"Speed comparison between scikit-learn and ONNX Runtime\\nFor a random forest on Iris dataset\")\nax.legend()" ] } ], @@ -287,7 +287,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/1b60ac13d6a5a4b72d4e4d28d1544f8d/plot_common_errors.ipynb b/docs/api/python/downloads/1b60ac13d6a5a4b72d4e4d28d1544f8d/plot_common_errors.ipynb index b835e389d0e58..78c57d9d0d211 100644 --- a/docs/api/python/downloads/1b60ac13d6a5a4b72d4e4d28d1544f8d/plot_common_errors.ipynb +++ b/docs/api/python/downloads/1b60ac13d6a5a4b72d4e4d28d1544f8d/plot_common_errors.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport numpy\nfrom onnxruntime.datasets import get_example\n\nexample2 = get_example(\"logreg_iris.onnx\")\nsess = rt.InferenceSession(example2)\n\ninput_name = sess.get_inputs()[0].name\noutput_name = sess.get_outputs()[0].name" + "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport numpy\nfrom onnxruntime.datasets import get_example\n\nexample2 = get_example(\"logreg_iris.onnx\")\nsess = rt.InferenceSession(example2, providers=rt.get_available_providers())\n\ninput_name = sess.get_inputs()[0].name\noutput_name = sess.get_outputs()[0].name" ] }, { @@ -154,7 +154,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/290d1103c4874727a37c05b400ffb83c/plot_load_and_predict.ipynb b/docs/api/python/downloads/290d1103c4874727a37c05b400ffb83c/plot_load_and_predict.ipynb index ebad45f91bf38..964763966024d 100644 --- a/docs/api/python/downloads/290d1103c4874727a37c05b400ffb83c/plot_load_and_predict.ipynb +++ b/docs/api/python/downloads/290d1103c4874727a37c05b400ffb83c/plot_load_and_predict.ipynb @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "example1 = get_example(\"sigmoid.onnx\")\nsess = rt.InferenceSession(example1)" + "example1 = get_example(\"sigmoid.onnx\")\nsess = rt.InferenceSession(example1, providers=rt.get_available_providers())" ] }, { @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/2dbd202de70c8b6a394b8a1c7c1e12b8/plot_pipeline.ipynb b/docs/api/python/downloads/2dbd202de70c8b6a394b8a1c7c1e12b8/plot_pipeline.ipynb index ef872cbbcfdf6..c79f384172df4 100644 --- a/docs/api/python/downloads/2dbd202de70c8b6a394b8a1c7c1e12b8/plot_pipeline.ipynb +++ b/docs/api/python/downloads/2dbd202de70c8b6a394b8a1c7c1e12b8/plot_pipeline.ipynb @@ -118,7 +118,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/3a0c2ba94405e579c84b6f356705659d/plot_train_convert_predict.ipynb b/docs/api/python/downloads/3a0c2ba94405e579c84b6f356705659d/plot_train_convert_predict.ipynb deleted file mode 100644 index cfdd75b320cd2..0000000000000 --- a/docs/api/python/downloads/3a0c2ba94405e579c84b6f356705659d/plot_train_convert_predict.ipynb +++ /dev/null @@ -1,295 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# Train, convert and predict with ONNX Runtime\n\nThis example demonstrates an end to end scenario\nstarting with the training of a machine learned model\nto its use in its converted from.\n\n## Train a logistic regression\n\nThe first step consists in retrieving the iris datset.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.datasets import load_iris\niris = load_iris()\nX, y = iris.data, iris.target\n\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then we fit a model.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.linear_model import LogisticRegression\nclr = LogisticRegression()\nclr.fit(X_train, y_train)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compute the prediction on the test set\nand we show the confusion matrix.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.metrics import confusion_matrix\n\npred = clr.predict(X_test)\nprint(confusion_matrix(y_test, pred))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Conversion to ONNX format\n\nWe use module \n`sklearn-onnx `_\nto convert the model into ONNX format.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from skl2onnx import convert_sklearn\nfrom skl2onnx.common.data_types import FloatTensorType\n\ninitial_type = [('float_input', FloatTensorType([None, 4]))]\nonx = convert_sklearn(clr, initial_types=initial_type)\nwith open(\"logreg_iris.onnx\", \"wb\") as f:\n f.write(onx.SerializeToString())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We load the model with ONNX Runtime and look at\nits input and output.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnxruntime as rt\nsess = rt.InferenceSession(\"logreg_iris.onnx\")\n\nprint(\"input name='{}' and shape={}\".format(\n sess.get_inputs()[0].name, sess.get_inputs()[0].shape))\nprint(\"output name='{}' and shape={}\".format(\n sess.get_outputs()[0].name, sess.get_outputs()[0].shape))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compute the predictions.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "input_name = sess.get_inputs()[0].name\nlabel_name = sess.get_outputs()[0].name\n\nimport numpy\npred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]\nprint(confusion_matrix(pred, pred_onx))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The prediction are perfectly identical.\n\n## Probabilities\n\nProbabilities are needed to compute other\nrelevant metrics such as the ROC Curve.\nLet's see how to get them first with\nscikit-learn.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "prob_sklearn = clr.predict_proba(X_test)\nprint(prob_sklearn[:3])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "And then with ONNX Runtime.\nThe probabilies appear to be \n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "prob_name = sess.get_outputs()[1].name\nprob_rt = sess.run([prob_name], {input_name: X_test.astype(numpy.float32)})[0]\n\nimport pprint\npprint.pprint(prob_rt[0:3])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's benchmark.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from timeit import Timer\n\ndef speed(inst, number=10, repeat=20):\n timer = Timer(inst, globals=globals())\n raw = numpy.array(timer.repeat(repeat, number=number))\n ave = raw.sum() / len(raw) / number\n mi, ma = raw.min() / number, raw.max() / number\n print(\"Average %1.3g min=%1.3g max=%1.3g\" % (ave, mi, ma))\n return ave\n\nprint(\"Execution time for clr.predict\")\nspeed(\"clr.predict(X_test)\")\n\nprint(\"Execution time for ONNX Runtime\")\nspeed(\"sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's benchmark a scenario similar to what a webservice\nexperiences: the model has to do one prediction at a time\nas opposed to a batch of prediction.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "def loop(X_test, fct, n=None):\n nrow = X_test.shape[0]\n if n is None:\n n = nrow\n for i in range(0, n):\n im = i % nrow\n fct(X_test[im: im+1])\n\nprint(\"Execution time for clr.predict\")\nspeed(\"loop(X_test, clr.predict, 100)\")\n\ndef sess_predict(x):\n return sess.run([label_name], {input_name: x.astype(numpy.float32)})[0]\n\nprint(\"Execution time for sess_predict\")\nspeed(\"loop(X_test, sess_predict, 100)\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's do the same for the probabilities.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(\"Execution time for predict_proba\")\nspeed(\"loop(X_test, clr.predict_proba, 100)\")\n\ndef sess_predict_proba(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n\nprint(\"Execution time for sess_predict_proba\")\nspeed(\"loop(X_test, sess_predict_proba, 100)\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This second comparison is better as \nONNX Runtime, in this experience,\ncomputes the label and the probabilities\nin every case.\n\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Benchmark with RandomForest\n\nWe first train and save a model in ONNX format.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.ensemble import RandomForestClassifier\nrf = RandomForestClassifier()\nrf.fit(X_train, y_train)\n\ninitial_type = [('float_input', FloatTensorType([1, 4]))]\nonx = convert_sklearn(rf, initial_types=initial_type)\nwith open(\"rf_iris.onnx\", \"wb\") as f:\n f.write(onx.SerializeToString())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compare.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "sess = rt.InferenceSession(\"rf_iris.onnx\")\n\ndef sess_predict_proba_rf(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n\nprint(\"Execution time for predict_proba\")\nspeed(\"loop(X_test, rf.predict_proba, 100)\")\n\nprint(\"Execution time for sess_predict_proba\")\nspeed(\"loop(X_test, sess_predict_proba_rf, 100)\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's see with different number of trees.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "measures = []\n\nfor n_trees in range(5, 51, 5): \n print(n_trees)\n rf = RandomForestClassifier(n_estimators=n_trees)\n rf.fit(X_train, y_train)\n initial_type = [('float_input', FloatTensorType([1, 4]))]\n onx = convert_sklearn(rf, initial_types=initial_type)\n with open(\"rf_iris_%d.onnx\" % n_trees, \"wb\") as f:\n f.write(onx.SerializeToString())\n sess = rt.InferenceSession(\"rf_iris_%d.onnx\" % n_trees)\n def sess_predict_proba_loop(x):\n return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]\n tsk = speed(\"loop(X_test, rf.predict_proba, 100)\", number=5, repeat=5)\n trt = speed(\"loop(X_test, sess_predict_proba_loop, 100)\", number=5, repeat=5)\n measures.append({'n_trees': n_trees, 'sklearn': tsk, 'rt': trt})\n\nfrom pandas import DataFrame\ndf = DataFrame(measures)\nax = df.plot(x=\"n_trees\", y=\"sklearn\", label=\"scikit-learn\", c=\"blue\", logy=True)\ndf.plot(x=\"n_trees\", y=\"rt\", label=\"onnxruntime\",\n ax=ax, c=\"green\", logy=True)\nax.set_xlabel(\"Number of trees\")\nax.set_ylabel(\"Prediction time (s)\")\nax.set_title(\"Speed comparison between scikit-learn and ONNX Runtime\\nFor a random forest on Iris dataset\")\nax.legend()" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/3a2955e44bf8f95a0eee6e71695ad788/plot_common_errors.py b/docs/api/python/downloads/3a2955e44bf8f95a0eee6e71695ad788/plot_common_errors.py index 0d98e17c45dff..b474574c0fdf6 100644 --- a/docs/api/python/downloads/3a2955e44bf8f95a0eee6e71695ad788/plot_common_errors.py +++ b/docs/api/python/downloads/3a2955e44bf8f95a0eee6e71695ad788/plot_common_errors.py @@ -21,7 +21,7 @@ from onnxruntime.datasets import get_example example2 = get_example("logreg_iris.onnx") -sess = rt.InferenceSession(example2) +sess = rt.InferenceSession(example2, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name output_name = sess.get_outputs()[0].name diff --git a/docs/api/python/downloads/3aca744422de94d33f9aaa3ce99633a9/plot_convert_pipeline_vectorizer.ipynb b/docs/api/python/downloads/3aca744422de94d33f9aaa3ce99633a9/plot_convert_pipeline_vectorizer.ipynb index ce8eb47ad4f6c..b0882340e1346 100644 --- a/docs/api/python/downloads/3aca744422de94d33f9aaa3ce99633a9/plot_convert_pipeline_vectorizer.ipynb +++ b/docs/api/python/downloads/3aca744422de94d33f9aaa3ce99633a9/plot_convert_pipeline_vectorizer.ipynb @@ -98,7 +98,7 @@ }, "outputs": [], "source": [ - "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\n\nsess = rt.InferenceSession(\"pipeline_vectorize.onnx\")\n\nimport numpy\ninp, out = sess.get_inputs()[0], sess.get_outputs()[0]\nprint(\"input name='{}' and shape={} and type={}\".format(inp.name, inp.shape, inp.type))\nprint(\"output name='{}' and shape={} and type={}\".format(out.name, out.shape, out.type))" + "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\n\nsess = rt.InferenceSession(\"pipeline_vectorize.onnx\", providers=rt.get_available_providers())\n\nimport numpy\ninp, out = sess.get_inputs()[0], sess.get_outputs()[0]\nprint(\"input name='{}' and shape={} and type={}\".format(inp.name, inp.shape, inp.type))\nprint(\"output name='{}' and shape={} and type={}\".format(out.name, out.shape, out.type))" ] }, { @@ -179,7 +179,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/3e23fa9ebb26f4728ee8426ed7da0f63/plot_backend.py b/docs/api/python/downloads/3e23fa9ebb26f4728ee8426ed7da0f63/plot_backend.py index 63d3cbce34d08..68096bb8a682e 100644 --- a/docs/api/python/downloads/3e23fa9ebb26f4728ee8426ed7da0f63/plot_backend.py +++ b/docs/api/python/downloads/3e23fa9ebb26f4728ee8426ed7da0f63/plot_backend.py @@ -20,10 +20,16 @@ import onnxruntime.backend as backend from onnx import load +######################################## +# The device depends on how the package was compiled, +# GPU or CPU. +from onnxruntime import get_device +device = get_device() + name = datasets.get_example("logreg_iris.onnx") model = load(name) -rep = backend.prepare(model, 'CPU') +rep = backend.prepare(model, device) x = np.array([[-1.0, -2.0]], dtype=np.float32) try: label, proba = rep.run(x) @@ -32,17 +38,11 @@ except (RuntimeError, InvalidArgument) as e: print(e) -######################################## -# The device depends on how the package was compiled, -# GPU or CPU. -from onnxruntime import get_device -print(get_device()) - ######################################## # The backend can also directly load the model # without using *onnx*. -rep = backend.prepare(name, 'CPU') +rep = backend.prepare(name, device) x = np.array([[-1.0, -2.0]], dtype=np.float32) try: label, proba = rep.run(x) diff --git a/docs/api/python/downloads/4412ae3bda7068f45094acb5373c790e/plot_load_and_predict.py b/docs/api/python/downloads/4412ae3bda7068f45094acb5373c790e/plot_load_and_predict.py deleted file mode 100644 index feb369feb2e27..0000000000000 --- a/docs/api/python/downloads/4412ae3bda7068f45094acb5373c790e/plot_load_and_predict.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -.. _l-example-simple-usage: - -Load and predict with ONNX Runtime and a very simple model -========================================================== - -This example demonstrates how to load a model and compute -the output for an input vector. It also shows how to -retrieve the definition of its inputs and outputs. -""" - -import onnxruntime as rt -import numpy -from onnxruntime.datasets import get_example - -######################### -# Let's load a very simple model. -# The model is available on github `onnx...test_sigmoid `_. - -example1 = get_example("sigmoid.onnx") -sess = rt.InferenceSession(example1) - -######################### -# Let's see the input name and shape. - -input_name = sess.get_inputs()[0].name -print("input name", input_name) -input_shape = sess.get_inputs()[0].shape -print("input shape", input_shape) -input_type = sess.get_inputs()[0].type -print("input type", input_type) - -######################### -# Let's see the output name and shape. - -output_name = sess.get_outputs()[0].name -print("output name", output_name) -output_shape = sess.get_outputs()[0].shape -print("output shape", output_shape) -output_type = sess.get_outputs()[0].type -print("output type", output_type) - -######################### -# Let's compute its outputs (or predictions if it is a machine learned model). - -import numpy.random -x = numpy.random.random((3,4,5)) -x = x.astype(numpy.float32) -res = sess.run([output_name], {input_name: x}) -print(res) diff --git a/docs/api/python/downloads/500c588edb4417e84924953b39d33cc6/plot_convert_pipeline_vectorizer.py b/docs/api/python/downloads/500c588edb4417e84924953b39d33cc6/plot_convert_pipeline_vectorizer.py deleted file mode 100644 index 0de0b30e28de0..0000000000000 --- a/docs/api/python/downloads/500c588edb4417e84924953b39d33cc6/plot_convert_pipeline_vectorizer.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -Train, convert and predict with ONNX Runtime -============================================ - -This example demonstrates an end to end scenario -starting with the training of a scikit-learn pipeline -which takes as inputs not a regular vector but a -dictionary ``{ int: float }`` as its first step is a -`DictVectorizer `_. - -.. contents:: - :local: - -Train a pipeline -++++++++++++++++ - -The first step consists in retrieving the boston datset. -""" -import pandas -from sklearn.datasets import load_boston -boston = load_boston() -X, y = boston.data, boston.target - -from sklearn.model_selection import train_test_split -X_train, X_test, y_train, y_test = train_test_split(X, y) -X_train_dict = pandas.DataFrame(X_train[:,1:]).T.to_dict().values() -X_test_dict = pandas.DataFrame(X_test[:,1:]).T.to_dict().values() - -#################################### -# We create a pipeline. - -from sklearn.pipeline import make_pipeline -from sklearn.ensemble import GradientBoostingRegressor -from sklearn.feature_extraction import DictVectorizer -pipe = make_pipeline( - DictVectorizer(sparse=False), - GradientBoostingRegressor()) - -pipe.fit(X_train_dict, y_train) - -#################################### -# We compute the prediction on the test set -# and we show the confusion matrix. -from sklearn.metrics import r2_score - -pred = pipe.predict(X_test_dict) -print(r2_score(y_test, pred)) - -#################################### -# Conversion to ONNX format -# +++++++++++++++++++++++++ -# -# We use module -# `sklearn-onnx `_ -# to convert the model into ONNX format. - -from skl2onnx import convert_sklearn -from skl2onnx.common.data_types import FloatTensorType, Int64TensorType, DictionaryType, SequenceType - -# initial_type = [('float_input', DictionaryType(Int64TensorType([1]), FloatTensorType([])))] -initial_type = [('float_input', DictionaryType(Int64TensorType([1]), FloatTensorType([])))] -onx = convert_sklearn(pipe, initial_types=initial_type) -with open("pipeline_vectorize.onnx", "wb") as f: - f.write(onx.SerializeToString()) - -################################## -# We load the model with ONNX Runtime and look at -# its input and output. -import onnxruntime as rt -from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument - -sess = rt.InferenceSession("pipeline_vectorize.onnx") - -import numpy -inp, out = sess.get_inputs()[0], sess.get_outputs()[0] -print("input name='{}' and shape={} and type={}".format(inp.name, inp.shape, inp.type)) -print("output name='{}' and shape={} and type={}".format(out.name, out.shape, out.type)) - -################################## -# We compute the predictions. -# We could do that in one call: - -try: - pred_onx = sess.run([out.name], {inp.name: X_test_dict})[0] -except (RuntimeError, InvalidArgument) as e: - print(e) - -############################# -# But it fails because, in case of a DictVectorizer, -# ONNX Runtime expects one observation at a time. -pred_onx = [sess.run([out.name], {inp.name: row})[0][0, 0] for row in X_test_dict] - -############################### -# We compare them to the model's ones. -print(r2_score(pred, pred_onx)) - -######################### -# Very similar. *ONNX Runtime* uses floats instead of doubles, -# that explains the small discrepencies. - diff --git a/docs/api/python/downloads/594159f58c2d97bee3f22ee659067d5a/plot_backend.ipynb b/docs/api/python/downloads/594159f58c2d97bee3f22ee659067d5a/plot_backend.ipynb deleted file mode 100644 index 42788feedebd7..0000000000000 --- a/docs/api/python/downloads/594159f58c2d97bee3f22ee659067d5a/plot_backend.ipynb +++ /dev/null @@ -1,97 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# ONNX Runtime Backend for ONNX\n\n*ONNX Runtime* extends the \n`onnx backend API `_\nto run predictions using this runtime.\nLet's use the API to compute the prediction\nof a simple logistic regression model.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import numpy as np\nfrom onnxruntime import datasets\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport onnxruntime.backend as backend\nfrom onnx import load\n\nname = datasets.get_example(\"logreg_iris.onnx\")\nmodel = load(name)\n\nrep = backend.prepare(model, 'CPU')\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The device depends on how the package was compiled,\nGPU or CPU.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnxruntime import get_device\nprint(get_device())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The backend can also directly load the model\nwithout using *onnx*.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "rep = backend.prepare(name, 'CPU')\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The backend API is implemented by other frameworks\nand makes it easier to switch between multiple runtimes\nwith the same API.\n\n" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip b/docs/api/python/downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip index 9a50a7410fca6..70c6d584da4ce 100644 Binary files a/docs/api/python/downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip and b/docs/api/python/downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip differ diff --git a/docs/api/python/downloads/7c8424f45d0156abd4d0221c65601124/plot_load_and_predict.py b/docs/api/python/downloads/7c8424f45d0156abd4d0221c65601124/plot_load_and_predict.py index feb369feb2e27..9bfdc5795758d 100644 --- a/docs/api/python/downloads/7c8424f45d0156abd4d0221c65601124/plot_load_and_predict.py +++ b/docs/api/python/downloads/7c8424f45d0156abd4d0221c65601124/plot_load_and_predict.py @@ -21,7 +21,7 @@ # The model is available on github `onnx...test_sigmoid `_. example1 = get_example("sigmoid.onnx") -sess = rt.InferenceSession(example1) +sess = rt.InferenceSession(example1, providers=rt.get_available_providers()) ######################### # Let's see the input name and shape. diff --git a/docs/api/python/downloads/7d69185b02f38811ad5d0593ec22c99d/plot_metadata.py b/docs/api/python/downloads/7d69185b02f38811ad5d0593ec22c99d/plot_metadata.py deleted file mode 100644 index df5d15276c634..0000000000000 --- a/docs/api/python/downloads/7d69185b02f38811ad5d0593ec22c99d/plot_metadata.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -Metadata -======== - -ONNX format contains metadata related to how the -model was produced. It is useful when the model -is deployed to production to keep track of which -instance was used at a specific time. -Let's see how to do that with a simple -logistic regression model trained with -*scikit-learn* and converted with *sklearn-onnx*. -""" - -from onnxruntime.datasets import get_example -example = get_example("logreg_iris.onnx") - -import onnx -model = onnx.load(example) - -print("doc_string={}".format(model.doc_string)) -print("domain={}".format(model.domain)) -print("ir_version={}".format(model.ir_version)) -print("metadata_props={}".format(model.metadata_props)) -print("model_version={}".format(model.model_version)) -print("producer_name={}".format(model.producer_name)) -print("producer_version={}".format(model.producer_version)) - -############################# -# With *ONNX Runtime*: - -from onnxruntime import InferenceSession -sess = InferenceSession(example) -meta = sess.get_modelmeta() - -print("custom_metadata_map={}".format(meta.custom_metadata_map)) -print("description={}".format(meta.description)) -print("domain={}".format(meta.domain, meta.domain)) -print("graph_name={}".format(meta.graph_name)) -print("producer_name={}".format(meta.producer_name)) -print("version={}".format(meta.version)) diff --git a/docs/api/python/downloads/8547b931339c42011a7c05ff3b5f5373/plot_common_errors.py b/docs/api/python/downloads/8547b931339c42011a7c05ff3b5f5373/plot_common_errors.py deleted file mode 100644 index 0d98e17c45dff..0000000000000 --- a/docs/api/python/downloads/8547b931339c42011a7c05ff3b5f5373/plot_common_errors.py +++ /dev/null @@ -1,117 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -.. _l-example-common-error: - -Common errors with onnxruntime -============================== - -This example looks into several common situations -in which *onnxruntime* does not return the model -prediction but raises an exception instead. -It starts by loading the model trained in example -:ref:`l-logreg-example` which produced a logistic regression -trained on *Iris* datasets. The model takes -a vector of dimension 2 and returns a class among three. -""" -import onnxruntime as rt -from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument -import numpy -from onnxruntime.datasets import get_example - -example2 = get_example("logreg_iris.onnx") -sess = rt.InferenceSession(example2) - -input_name = sess.get_inputs()[0].name -output_name = sess.get_outputs()[0].name - -############################# -# The first example fails due to *bad types*. -# *onnxruntime* only expects single floats (4 bytes) -# and cannot handle any other kind of floats. - -try: - x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float64) - sess.run([output_name], {input_name: x}) -except Exception as e: - print("Unexpected type") - print("{0}: {1}".format(type(e), e)) - -######################### -# The model fails to return an output if the name -# is misspelled. - -try: - x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) - sess.run(["misspelled"], {input_name: x}) -except Exception as e: - print("Misspelled output name") - print("{0}: {1}".format(type(e), e)) - -########################### -# The output name is optional, it can be replaced by *None* -# and *onnxruntime* will then return all the outputs. - -x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) -try: - res = sess.run(None, {input_name: x}) - print("All outputs") - print(res) -except (RuntimeError, InvalidArgument) as e: - print(e) - -######################### -# The same goes if the input name is misspelled. - -try: - x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) - sess.run([output_name], {"misspelled": x}) -except Exception as e: - print("Misspelled input name") - print("{0}: {1}".format(type(e), e)) - -######################### -# *onnxruntime* does not necessarily fail if the input -# dimension is a multiple of the expected input dimension. - -for x in [ - numpy.array([1.0, 2.0, 3.0, 4.0], dtype=numpy.float32), - numpy.array([[1.0, 2.0, 3.0, 4.0]], dtype=numpy.float32), - numpy.array([[1.0, 2.0], [3.0, 4.0]], dtype=numpy.float32), - numpy.array([1.0, 2.0, 3.0], dtype=numpy.float32), - numpy.array([[1.0, 2.0, 3.0]], dtype=numpy.float32), - ]: - try: - r = sess.run([output_name], {input_name: x}) - print("Shape={0} and predicted labels={1}".format(x.shape, r)) - except (RuntimeError, InvalidArgument) as e: - print("ERROR with Shape={0} - {1}".format(x.shape, e)) - -for x in [ - numpy.array([1.0, 2.0, 3.0, 4.0], dtype=numpy.float32), - numpy.array([[1.0, 2.0, 3.0, 4.0]], dtype=numpy.float32), - numpy.array([[1.0, 2.0], [3.0, 4.0]], dtype=numpy.float32), - numpy.array([1.0, 2.0, 3.0], dtype=numpy.float32), - numpy.array([[1.0, 2.0, 3.0]], dtype=numpy.float32), - ]: - try: - r = sess.run(None, {input_name: x}) - print("Shape={0} and predicted probabilities={1}".format(x.shape, r[1])) - except (RuntimeError, InvalidArgument) as e: - print("ERROR with Shape={0} - {1}".format(x.shape, e)) - -######################### -# It does not fail either if the number of dimension -# is higher than expects but produces a warning. - -for x in [ - numpy.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=numpy.float32), - numpy.array([[[1.0, 2.0, 3.0]]], dtype=numpy.float32), - numpy.array([[[1.0, 2.0]], [[3.0, 4.0]]], dtype=numpy.float32), - ]: - try: - r = sess.run([output_name], {input_name: x}) - print("Shape={0} and predicted labels={1}".format(x.shape, r)) - except (RuntimeError, InvalidArgument) as e: - print("ERROR with Shape={0} - {1}".format(x.shape, e)) diff --git a/docs/api/python/downloads/8dd0c9d6c4ab396fa8f24f6321edc4b0/plot_common_errors.ipynb b/docs/api/python/downloads/8dd0c9d6c4ab396fa8f24f6321edc4b0/plot_common_errors.ipynb deleted file mode 100644 index 1dadcdcca3182..0000000000000 --- a/docs/api/python/downloads/8dd0c9d6c4ab396fa8f24f6321edc4b0/plot_common_errors.ipynb +++ /dev/null @@ -1,162 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# Common errors with onnxruntime\n\nThis example looks into several common situations\nin which *onnxruntime* does not return the model \nprediction but raises an exception instead.\nIt starts by loading the model trained in example\n`l-logreg-example` which produced a logistic regression\ntrained on *Iris* datasets. The model takes\na vector of dimension 2 and returns a class among three.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport numpy\nfrom onnxruntime.datasets import get_example\n\nexample2 = get_example(\"logreg_iris.onnx\")\nsess = rt.InferenceSession(example2)\n\ninput_name = sess.get_inputs()[0].name\noutput_name = sess.get_outputs()[0].name" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The first example fails due to *bad types*.\n*onnxruntime* only expects single floats (4 bytes)\nand cannot handle any other kind of floats.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "try:\n x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float64)\n sess.run([output_name], {input_name: x})\nexcept Exception as e:\n print(\"Unexpected type\")\n print(\"{0}: {1}\".format(type(e), e))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The model fails to return an output if the name\nis misspelled.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "try:\n x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\n sess.run([\"misspelled\"], {input_name: x})\nexcept Exception as e:\n print(\"Misspelled output name\")\n print(\"{0}: {1}\".format(type(e), e))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The output name is optional, it can be replaced by *None*\nand *onnxruntime* will then return all the outputs.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\ntry:\n res = sess.run(None, {input_name: x})\n print(\"All outputs\")\n print(res)\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The same goes if the input name is misspelled.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "try:\n x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\n sess.run([output_name], {\"misspelled\": x})\nexcept Exception as e:\n print(\"Misspelled input name\")\n print(\"{0}: {1}\".format(type(e), e))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "*onnxruntime* does not necessarily fail if the input\ndimension is a multiple of the expected input dimension.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "for x in [\n numpy.array([1.0, 2.0, 3.0, 4.0], dtype=numpy.float32),\n numpy.array([[1.0, 2.0, 3.0, 4.0]], dtype=numpy.float32),\n numpy.array([[1.0, 2.0], [3.0, 4.0]], dtype=numpy.float32),\n numpy.array([1.0, 2.0, 3.0], dtype=numpy.float32),\n numpy.array([[1.0, 2.0, 3.0]], dtype=numpy.float32),\n ]:\n try:\n r = sess.run([output_name], {input_name: x})\n print(\"Shape={0} and predicted labels={1}\".format(x.shape, r))\n except (RuntimeError, InvalidArgument) as e:\n print(\"ERROR with Shape={0} - {1}\".format(x.shape, e))\n\nfor x in [\n numpy.array([1.0, 2.0, 3.0, 4.0], dtype=numpy.float32),\n numpy.array([[1.0, 2.0, 3.0, 4.0]], dtype=numpy.float32),\n numpy.array([[1.0, 2.0], [3.0, 4.0]], dtype=numpy.float32),\n numpy.array([1.0, 2.0, 3.0], dtype=numpy.float32),\n numpy.array([[1.0, 2.0, 3.0]], dtype=numpy.float32),\n ]:\n try:\n r = sess.run(None, {input_name: x})\n print(\"Shape={0} and predicted probabilities={1}\".format(x.shape, r[1]))\n except (RuntimeError, InvalidArgument) as e:\n print(\"ERROR with Shape={0} - {1}\".format(x.shape, e))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It does not fail either if the number of dimension\nis higher than expects but produces a warning.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "for x in [\n numpy.array([[[1.0, 2.0], [3.0, 4.0]]], dtype=numpy.float32),\n numpy.array([[[1.0, 2.0, 3.0]]], dtype=numpy.float32),\n numpy.array([[[1.0, 2.0]], [[3.0, 4.0]]], dtype=numpy.float32),\n ]:\n try:\n r = sess.run([output_name], {input_name: x})\n print(\"Shape={0} and predicted labels={1}\".format(x.shape, r))\n except (RuntimeError, InvalidArgument) as e:\n print(\"ERROR with Shape={0} - {1}\".format(x.shape, e))" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/932fe1ee7f48f55a6155d2f378bc85a0/plot_metadata.py b/docs/api/python/downloads/932fe1ee7f48f55a6155d2f378bc85a0/plot_metadata.py index df5d15276c634..94c45e688f27f 100644 --- a/docs/api/python/downloads/932fe1ee7f48f55a6155d2f378bc85a0/plot_metadata.py +++ b/docs/api/python/downloads/932fe1ee7f48f55a6155d2f378bc85a0/plot_metadata.py @@ -31,8 +31,8 @@ ############################# # With *ONNX Runtime*: -from onnxruntime import InferenceSession -sess = InferenceSession(example) +import onnxruntime as rt +sess = rt.InferenceSession(example, providers=rt.get_available_providers()) meta = sess.get_modelmeta() print("custom_metadata_map={}".format(meta.custom_metadata_map)) diff --git a/docs/api/python/downloads/940d20a5bdb46eb51fb878fbb3bd928d/plot_metadata.ipynb b/docs/api/python/downloads/940d20a5bdb46eb51fb878fbb3bd928d/plot_metadata.ipynb index 4246eaa7057a6..f282c7bc03003 100644 --- a/docs/api/python/downloads/940d20a5bdb46eb51fb878fbb3bd928d/plot_metadata.ipynb +++ b/docs/api/python/downloads/940d20a5bdb46eb51fb878fbb3bd928d/plot_metadata.ipynb @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "from onnxruntime import InferenceSession\nsess = InferenceSession(example)\nmeta = sess.get_modelmeta()\n\nprint(\"custom_metadata_map={}\".format(meta.custom_metadata_map))\nprint(\"description={}\".format(meta.description))\nprint(\"domain={}\".format(meta.domain, meta.domain))\nprint(\"graph_name={}\".format(meta.graph_name))\nprint(\"producer_name={}\".format(meta.producer_name))\nprint(\"version={}\".format(meta.version))" + "import onnxruntime as rt\nsess = rt.InferenceSession(example, providers=rt.get_available_providers())\nmeta = sess.get_modelmeta()\n\nprint(\"custom_metadata_map={}\".format(meta.custom_metadata_map))\nprint(\"description={}\".format(meta.description))\nprint(\"domain={}\".format(meta.domain, meta.domain))\nprint(\"graph_name={}\".format(meta.graph_name))\nprint(\"producer_name={}\".format(meta.producer_name))\nprint(\"version={}\".format(meta.version))" ] } ], @@ -64,7 +64,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/94ba4b1ad7abc78b59124c6a39f9a075/plot_pipeline.py b/docs/api/python/downloads/94ba4b1ad7abc78b59124c6a39f9a075/plot_pipeline.py deleted file mode 100644 index 0a002f6223e1b..0000000000000 --- a/docs/api/python/downloads/94ba4b1ad7abc78b59124c6a39f9a075/plot_pipeline.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" -Draw a pipeline -=============== - -There is no other way to look into one model stored -in ONNX format than looking into its node with -*onnx*. This example demonstrates -how to draw a model and to retrieve it in *json* -format. - -.. contents:: - :local: - -Retrieve a model in JSON format -+++++++++++++++++++++++++++++++ - -That's the most simple way. -""" - -from onnxruntime.datasets import get_example -example1 = get_example("mul_1.onnx") - -import onnx -model = onnx.load(example1) # model is a ModelProto protobuf message - -print(model) - - -################################# -# Draw a model with ONNX -# ++++++++++++++++++++++ -# We use `net_drawer.py `_ -# included in *onnx* package. -# We use *onnx* to load the model -# in a different way than before. - - -from onnx import ModelProto -model = ModelProto() -with open(example1, 'rb') as fid: - content = fid.read() - model.ParseFromString(content) - -################################### -# We convert it into a graph. -from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer -pydot_graph = GetPydotGraph(model.graph, name=model.graph.name, rankdir="LR", - node_producer=GetOpNodeProducer("docstring")) -pydot_graph.write_dot("graph.dot") - -####################################### -# Then into an image -import os -os.system('dot -O -Tpng graph.dot') - -################################ -# Which we display... -import matplotlib.pyplot as plt -image = plt.imread("graph.dot.png") -plt.imshow(image) - - - - - - diff --git a/docs/api/python/downloads/982a1f7abbb8ffc5d5e98b671c35e5aa/plot_convert_pipeline_vectorizer.py b/docs/api/python/downloads/982a1f7abbb8ffc5d5e98b671c35e5aa/plot_convert_pipeline_vectorizer.py index 0de0b30e28de0..af1351d0c87ff 100644 --- a/docs/api/python/downloads/982a1f7abbb8ffc5d5e98b671c35e5aa/plot_convert_pipeline_vectorizer.py +++ b/docs/api/python/downloads/982a1f7abbb8ffc5d5e98b671c35e5aa/plot_convert_pipeline_vectorizer.py @@ -72,7 +72,7 @@ import onnxruntime as rt from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument -sess = rt.InferenceSession("pipeline_vectorize.onnx") +sess = rt.InferenceSession("pipeline_vectorize.onnx", providers=rt.get_available_providers()) import numpy inp, out = sess.get_inputs()[0], sess.get_outputs()[0] diff --git a/docs/api/python/downloads/a8a3fe6bdcf0fdfbed17a5a0f2384419/plot_profiling.ipynb b/docs/api/python/downloads/a8a3fe6bdcf0fdfbed17a5a0f2384419/plot_profiling.ipynb deleted file mode 100644 index 575a43864bfb0..0000000000000 --- a/docs/api/python/downloads/a8a3fe6bdcf0fdfbed17a5a0f2384419/plot_profiling.ipynb +++ /dev/null @@ -1,108 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# Profile the execution of a simple model\n\n*ONNX Runtime* can profile the execution of the model.\nThis example shows how to interpret the results.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnx\nimport onnxruntime as rt\nimport numpy\nfrom onnxruntime.datasets import get_example\n\n\ndef change_ir_version(filename, ir_version=6):\n \"onnxruntime==1.2.0 does not support opset <= 7 and ir_version > 6\"\n with open(filename, \"rb\") as f:\n model = onnx.load(f)\n model.ir_version = 6\n if model.opset_import[0].version <= 7:\n model.opset_import[0].version = 11\n return model" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's load a very simple model and compute some prediction.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "example1 = get_example(\"mul_1.onnx\")\nonnx_model = change_ir_version(example1)\nonnx_model_str = onnx_model.SerializeToString()\nsess = rt.InferenceSession(onnx_model_str)\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\nres = sess.run(None, {input_name: x})\nprint(res)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We need to enable to profiling\nbefore running the predictions.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "options = rt.SessionOptions()\noptions.enable_profiling = True\nsess_profile = rt.InferenceSession(onnx_model_str, options)\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\n\nsess.run(None, {input_name: x})\nprof_file = sess_profile.end_profiling()\nprint(prof_file)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The results are stored un a file in JSON format.\nLet's see what it contains.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import json\nwith open(prof_file, \"r\") as f:\n sess_time = json.load(f)\nimport pprint\npprint.pprint(sess_time)" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/ae37e1cd2f800a09b44216a88ac39d30/plot_metadata.ipynb b/docs/api/python/downloads/ae37e1cd2f800a09b44216a88ac39d30/plot_metadata.ipynb deleted file mode 100644 index 0aa5560d09b44..0000000000000 --- a/docs/api/python/downloads/ae37e1cd2f800a09b44216a88ac39d30/plot_metadata.ipynb +++ /dev/null @@ -1,72 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Metadata\n\nONNX format contains metadata related to how the\nmodel was produced. It is useful when the model\nis deployed to production to keep track of which\ninstance was used at a specific time.\nLet's see how to do that with a simple \nlogistic regression model trained with\n*scikit-learn* and converted with *sklearn-onnx*.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnxruntime.datasets import get_example\nexample = get_example(\"logreg_iris.onnx\")\n\nimport onnx\nmodel = onnx.load(example)\n\nprint(\"doc_string={}\".format(model.doc_string))\nprint(\"domain={}\".format(model.domain))\nprint(\"ir_version={}\".format(model.ir_version))\nprint(\"metadata_props={}\".format(model.metadata_props))\nprint(\"model_version={}\".format(model.model_version))\nprint(\"producer_name={}\".format(model.producer_name))\nprint(\"producer_version={}\".format(model.producer_version))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "With *ONNX Runtime*:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnxruntime import InferenceSession\nsess = InferenceSession(example)\nmeta = sess.get_modelmeta()\n\nprint(\"custom_metadata_map={}\".format(meta.custom_metadata_map))\nprint(\"description={}\".format(meta.description))\nprint(\"domain={}\".format(meta.domain, meta.domain))\nprint(\"graph_name={}\".format(meta.graph_name))\nprint(\"producer_name={}\".format(meta.producer_name))\nprint(\"version={}\".format(meta.version))" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/b81c8c31615f9400a26ee60f0641af3f/plot_dl_keras.py b/docs/api/python/downloads/b81c8c31615f9400a26ee60f0641af3f/plot_dl_keras.py deleted file mode 100644 index 949ee895e5912..0000000000000 --- a/docs/api/python/downloads/b81c8c31615f9400a26ee60f0641af3f/plot_dl_keras.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" - -.. _l-example-backend-api-tensorflow: - -ONNX Runtime for Keras -====================== - -The following demonstrates how to compute the predictions -of a pretrained deep learning model obtained from -`keras `_ -with *onnxruntime*. The conversion requires -`keras `_, -`tensorflow `_, -`keras-onnx `_, -`onnxmltools `_ -but then only *onnxruntime* is required -to compute the predictions. -""" -import os -if not os.path.exists('dense121.onnx'): - from keras.applications.densenet import DenseNet121 - model = DenseNet121(include_top=True, weights='imagenet') - - from keras2onnx import convert_keras - onx = convert_keras(model, 'dense121.onnx') - with open("dense121.onnx", "wb") as f: - f.write(onx.SerializeToString()) - -################################## -# Let's load an image (source: wikipedia). - -from keras.preprocessing.image import array_to_img, img_to_array, load_img -img = load_img('Sannosawa1.jpg') -ximg = img_to_array(img) - -import matplotlib.pyplot as plt -plt.imshow(ximg / 255) -plt.axis('off') - -############################################# -# Let's load the model with onnxruntime. -import onnxruntime as rt -from onnxruntime.capi.onnxruntime_pybind11_state import InvalidGraph - -try: - sess = rt.InferenceSession('dense121.onnx') - ok = True -except (InvalidGraph, TypeError, RuntimeError) as e: - # Probably a mismatch between onnxruntime and onnx version. - print(e) - ok = False - -if ok: - print("The model expects input shape:", sess.get_inputs()[0].shape) - print("image shape:", ximg.shape) - -####################################### -# Let's resize the image. - -if ok: - from skimage.transform import resize - import numpy - - ximg224 = resize(ximg / 255, (224, 224, 3), anti_aliasing=True) - ximg = ximg224[numpy.newaxis, :, :, :] - ximg = ximg.astype(numpy.float32) - - print("new shape:", ximg.shape) - -################################## -# Let's compute the output. - -if ok: - input_name = sess.get_inputs()[0].name - res = sess.run(None, {input_name: ximg}) - prob = res[0] - print(prob.ravel()[:10]) # Too big to be displayed. - - -################################## -# Let's get more comprehensive results. - -if ok: - from keras.applications.densenet import decode_predictions - decoded = decode_predictions(prob) - - import pandas - df = pandas.DataFrame(decoded[0], columns=["class_id", "name", "P"]) - print(df) - - diff --git a/docs/api/python/downloads/be7aeaf8b9b95af92780b5d952019035/plot_convert_pipeline_vectorizer.ipynb b/docs/api/python/downloads/be7aeaf8b9b95af92780b5d952019035/plot_convert_pipeline_vectorizer.ipynb deleted file mode 100644 index 2b285b76adecd..0000000000000 --- a/docs/api/python/downloads/be7aeaf8b9b95af92780b5d952019035/plot_convert_pipeline_vectorizer.ipynb +++ /dev/null @@ -1,187 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Train, convert and predict with ONNX Runtime\n\nThis example demonstrates an end to end scenario\nstarting with the training of a scikit-learn pipeline\nwhich takes as inputs not a regular vector but a\ndictionary ``{ int: float }`` as its first step is a\n`DictVectorizer `_.\n\n## Train a pipeline\n\nThe first step consists in retrieving the boston datset.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import pandas\nfrom sklearn.datasets import load_boston\nboston = load_boston()\nX, y = boston.data, boston.target\n\nfrom sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X, y)\nX_train_dict = pandas.DataFrame(X_train[:,1:]).T.to_dict().values()\nX_test_dict = pandas.DataFrame(X_test[:,1:]).T.to_dict().values()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We create a pipeline.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.pipeline import make_pipeline\nfrom sklearn.ensemble import GradientBoostingRegressor\nfrom sklearn.feature_extraction import DictVectorizer\npipe = make_pipeline(\n DictVectorizer(sparse=False),\n GradientBoostingRegressor())\n \npipe.fit(X_train_dict, y_train)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compute the prediction on the test set\nand we show the confusion matrix.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from sklearn.metrics import r2_score\n\npred = pipe.predict(X_test_dict)\nprint(r2_score(y_test, pred))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Conversion to ONNX format\n\nWe use module \n`sklearn-onnx `_\nto convert the model into ONNX format.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from skl2onnx import convert_sklearn\nfrom skl2onnx.common.data_types import FloatTensorType, Int64TensorType, DictionaryType, SequenceType\n\n# initial_type = [('float_input', DictionaryType(Int64TensorType([1]), FloatTensorType([])))]\ninitial_type = [('float_input', DictionaryType(Int64TensorType([1]), FloatTensorType([])))]\nonx = convert_sklearn(pipe, initial_types=initial_type)\nwith open(\"pipeline_vectorize.onnx\", \"wb\") as f:\n f.write(onx.SerializeToString())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We load the model with ONNX Runtime and look at\nits input and output.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\n\nsess = rt.InferenceSession(\"pipeline_vectorize.onnx\")\n\nimport numpy\ninp, out = sess.get_inputs()[0], sess.get_outputs()[0]\nprint(\"input name='{}' and shape={} and type={}\".format(inp.name, inp.shape, inp.type))\nprint(\"output name='{}' and shape={} and type={}\".format(out.name, out.shape, out.type))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compute the predictions.\nWe could do that in one call:\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "try:\n pred_onx = sess.run([out.name], {inp.name: X_test_dict})[0]\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "But it fails because, in case of a DictVectorizer,\nONNX Runtime expects one observation at a time.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "pred_onx = [sess.run([out.name], {inp.name: row})[0][0, 0] for row in X_test_dict]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We compare them to the model's ones.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "print(r2_score(pred, pred_onx))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Very similar. *ONNX Runtime* uses floats instead of doubles,\nthat explains the small discrepencies.\n\n" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/c2f3ba3f66159c615632f39a9ad32dee/plot_pipeline.ipynb b/docs/api/python/downloads/c2f3ba3f66159c615632f39a9ad32dee/plot_pipeline.ipynb deleted file mode 100644 index 6ccf3e2972926..0000000000000 --- a/docs/api/python/downloads/c2f3ba3f66159c615632f39a9ad32dee/plot_pipeline.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n# Draw a pipeline\n\nThere is no other way to look into one model stored\nin ONNX format than looking into its node with \n*onnx*. This example demonstrates\nhow to draw a model and to retrieve it in *json*\nformat.\n\n## Retrieve a model in JSON format\n\nThat's the most simple way.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnxruntime.datasets import get_example\nexample1 = get_example(\"mul_1.onnx\")\n\nimport onnx\nmodel = onnx.load(example1) # model is a ModelProto protobuf message\n\nprint(model)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Draw a model with ONNX\nWe use `net_drawer.py `_\nincluded in *onnx* package.\nWe use *onnx* to load the model\nin a different way than before.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnx import ModelProto\nmodel = ModelProto()\nwith open(example1, 'rb') as fid:\n content = fid.read()\n model.ParseFromString(content)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We convert it into a graph.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from onnx.tools.net_drawer import GetPydotGraph, GetOpNodeProducer\npydot_graph = GetPydotGraph(model.graph, name=model.graph.name, rankdir=\"LR\",\n node_producer=GetOpNodeProducer(\"docstring\"))\npydot_graph.write_dot(\"graph.dot\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then into an image\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import os\nos.system('dot -O -Tpng graph.dot')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Which we display...\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import matplotlib.pyplot as plt\nimage = plt.imread(\"graph.dot.png\")\nplt.imshow(image)" - ] - } - ], - "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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/c647c128e0cf2b3db04ce60b41ef1a14/plot_train_convert_predict.py b/docs/api/python/downloads/c647c128e0cf2b3db04ce60b41ef1a14/plot_train_convert_predict.py index 5b060c5f41ffe..4aa36b3dce25c 100644 --- a/docs/api/python/downloads/c647c128e0cf2b3db04ce60b41ef1a14/plot_train_convert_predict.py +++ b/docs/api/python/downloads/c647c128e0cf2b3db04ce60b41ef1a14/plot_train_convert_predict.py @@ -64,7 +64,7 @@ # its input and output. import onnxruntime as rt -sess = rt.InferenceSession("logreg_iris.onnx") +sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers()) print("input name='{}' and shape={}".format( sess.get_inputs()[0].name, sess.get_inputs()[0].shape)) @@ -180,7 +180,7 @@ def sess_predict_proba(x): ################################### # We compare. -sess = rt.InferenceSession("rf_iris.onnx") +sess = rt.InferenceSession("rf_iris.onnx", providers=rt.get_available_providers()) def sess_predict_proba_rf(x): return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] @@ -204,7 +204,7 @@ def sess_predict_proba_rf(x): onx = convert_sklearn(rf, initial_types=initial_type) with open("rf_iris_%d.onnx" % n_trees, "wb") as f: f.write(onx.SerializeToString()) - sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees) + sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees, providers=rt.get_available_providers()) def sess_predict_proba_loop(x): return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] tsk = speed("loop(X_test, rf.predict_proba, 100)", number=5, repeat=5) diff --git a/docs/api/python/downloads/c9f88a9294285c733dcce209fcc939de/plot_dl_keras.ipynb b/docs/api/python/downloads/c9f88a9294285c733dcce209fcc939de/plot_dl_keras.ipynb deleted file mode 100644 index a1af6a4f627f5..0000000000000 --- a/docs/api/python/downloads/c9f88a9294285c733dcce209fcc939de/plot_dl_keras.ipynb +++ /dev/null @@ -1,144 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# ONNX Runtime for Keras\n\nThe following demonstrates how to compute the predictions\nof a pretrained deep learning model obtained from \n`keras `_\nwith *onnxruntime*. The conversion requires\n`keras `_,\n`tensorflow `_,\n`keras-onnx `_,\n`onnxmltools `_\nbut then only *onnxruntime* is required\nto compute the predictions.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import os\nif not os.path.exists('dense121.onnx'):\n from keras.applications.densenet import DenseNet121\n model = DenseNet121(include_top=True, weights='imagenet')\n\n from keras2onnx import convert_keras\n onx = convert_keras(model, 'dense121.onnx')\n with open(\"dense121.onnx\", \"wb\") as f:\n f.write(onx.SerializeToString())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's load an image (source: wikipedia).\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "from keras.preprocessing.image import array_to_img, img_to_array, load_img\nimg = load_img('Sannosawa1.jpg')\nximg = img_to_array(img)\n\nimport matplotlib.pyplot as plt\nplt.imshow(ximg / 255)\nplt.axis('off')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's load the model with onnxruntime.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnxruntime as rt\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidGraph\n\ntry:\n sess = rt.InferenceSession('dense121.onnx')\n ok = True\nexcept (InvalidGraph, TypeError, RuntimeError) as e:\n # Probably a mismatch between onnxruntime and onnx version.\n print(e)\n ok = False\n\nif ok:\n print(\"The model expects input shape:\", sess.get_inputs()[0].shape)\n print(\"image shape:\", ximg.shape)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's resize the image.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "if ok:\n from skimage.transform import resize\n import numpy\n\n ximg224 = resize(ximg / 255, (224, 224, 3), anti_aliasing=True)\n ximg = ximg224[numpy.newaxis, :, :, :]\n ximg = ximg.astype(numpy.float32)\n\n print(\"new shape:\", ximg.shape)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's compute the output.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "if ok:\n input_name = sess.get_inputs()[0].name\n res = sess.run(None, {input_name: ximg})\n prob = res[0]\n print(prob.ravel()[:10]) # Too big to be displayed." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's get more comprehensive results.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "if ok:\n from keras.applications.densenet import decode_predictions\n decoded = decode_predictions(prob)\n\n import pandas\n df = pandas.DataFrame(decoded[0], columns=[\"class_id\", \"name\", \"P\"])\n print(df)" - ] - } - ], - "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.8.7" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/ccbbfd4f60683438ab99a4c42d3fbbdf/plot_profiling.ipynb b/docs/api/python/downloads/ccbbfd4f60683438ab99a4c42d3fbbdf/plot_profiling.ipynb index e6d61fa627ead..8c91e80384b42 100644 --- a/docs/api/python/downloads/ccbbfd4f60683438ab99a4c42d3fbbdf/plot_profiling.ipynb +++ b/docs/api/python/downloads/ccbbfd4f60683438ab99a4c42d3fbbdf/plot_profiling.ipynb @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "example1 = get_example(\"mul_1.onnx\")\nonnx_model = change_ir_version(example1)\nonnx_model_str = onnx_model.SerializeToString()\nsess = rt.InferenceSession(onnx_model_str)\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\nres = sess.run(None, {input_name: x})\nprint(res)" + "example1 = get_example(\"mul_1.onnx\")\nonnx_model = change_ir_version(example1)\nonnx_model_str = onnx_model.SerializeToString()\nsess = rt.InferenceSession(onnx_model_str, providers=rt.get_available_providers())\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\nres = sess.run(None, {input_name: x})\nprint(res)" ] }, { @@ -62,7 +62,7 @@ }, "outputs": [], "source": [ - "options = rt.SessionOptions()\noptions.enable_profiling = True\nsess_profile = rt.InferenceSession(onnx_model_str, options)\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\n\nsess.run(None, {input_name: x})\nprof_file = sess_profile.end_profiling()\nprint(prof_file)" + "options = rt.SessionOptions()\noptions.enable_profiling = True\nsess_profile = rt.InferenceSession(onnx_model_str, options, providers=rt.get_available_providers())\ninput_name = sess.get_inputs()[0].name\n\nx = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)\n\nsess.run(None, {input_name: x})\nprof_file = sess_profile.end_profiling()\nprint(prof_file)" ] }, { @@ -100,7 +100,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/downloads/cfe61aca1f0a89486c7024466ea500fd/plot_profiling.py b/docs/api/python/downloads/cfe61aca1f0a89486c7024466ea500fd/plot_profiling.py index f0ea727ede1b2..402e7b3baee10 100644 --- a/docs/api/python/downloads/cfe61aca1f0a89486c7024466ea500fd/plot_profiling.py +++ b/docs/api/python/downloads/cfe61aca1f0a89486c7024466ea500fd/plot_profiling.py @@ -35,7 +35,7 @@ def change_ir_version(filename, ir_version=6): example1 = get_example("mul_1.onnx") onnx_model = change_ir_version(example1) onnx_model_str = onnx_model.SerializeToString() -sess = rt.InferenceSession(onnx_model_str) +sess = rt.InferenceSession(onnx_model_str, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) @@ -48,7 +48,7 @@ def change_ir_version(filename, ir_version=6): options = rt.SessionOptions() options.enable_profiling = True -sess_profile = rt.InferenceSession(onnx_model_str, options) +sess_profile = rt.InferenceSession(onnx_model_str, options, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) diff --git a/docs/api/python/downloads/d83345a79a181a29892287297803aeec/plot_train_convert_predict.py b/docs/api/python/downloads/d83345a79a181a29892287297803aeec/plot_train_convert_predict.py deleted file mode 100644 index 5b060c5f41ffe..0000000000000 --- a/docs/api/python/downloads/d83345a79a181a29892287297803aeec/plot_train_convert_predict.py +++ /dev/null @@ -1,222 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" - -.. _l-logreg-example: - -Train, convert and predict with ONNX Runtime -============================================ - -This example demonstrates an end to end scenario -starting with the training of a machine learned model -to its use in its converted from. - -.. contents:: - :local: - -Train a logistic regression -+++++++++++++++++++++++++++ - -The first step consists in retrieving the iris datset. -""" - -from sklearn.datasets import load_iris -iris = load_iris() -X, y = iris.data, iris.target - -from sklearn.model_selection import train_test_split -X_train, X_test, y_train, y_test = train_test_split(X, y) - -#################################### -# Then we fit a model. - -from sklearn.linear_model import LogisticRegression -clr = LogisticRegression() -clr.fit(X_train, y_train) - -#################################### -# We compute the prediction on the test set -# and we show the confusion matrix. -from sklearn.metrics import confusion_matrix - -pred = clr.predict(X_test) -print(confusion_matrix(y_test, pred)) - -#################################### -# Conversion to ONNX format -# +++++++++++++++++++++++++ -# -# We use module -# `sklearn-onnx `_ -# to convert the model into ONNX format. - -from skl2onnx import convert_sklearn -from skl2onnx.common.data_types import FloatTensorType - -initial_type = [('float_input', FloatTensorType([None, 4]))] -onx = convert_sklearn(clr, initial_types=initial_type) -with open("logreg_iris.onnx", "wb") as f: - f.write(onx.SerializeToString()) - -################################## -# We load the model with ONNX Runtime and look at -# its input and output. - -import onnxruntime as rt -sess = rt.InferenceSession("logreg_iris.onnx") - -print("input name='{}' and shape={}".format( - sess.get_inputs()[0].name, sess.get_inputs()[0].shape)) -print("output name='{}' and shape={}".format( - sess.get_outputs()[0].name, sess.get_outputs()[0].shape)) - -################################## -# We compute the predictions. - -input_name = sess.get_inputs()[0].name -label_name = sess.get_outputs()[0].name - -import numpy -pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0] -print(confusion_matrix(pred, pred_onx)) - -################################### -# The prediction are perfectly identical. -# -# Probabilities -# +++++++++++++ -# -# Probabilities are needed to compute other -# relevant metrics such as the ROC Curve. -# Let's see how to get them first with -# scikit-learn. - -prob_sklearn = clr.predict_proba(X_test) -print(prob_sklearn[:3]) - -############################# -# And then with ONNX Runtime. -# The probabilies appear to be - -prob_name = sess.get_outputs()[1].name -prob_rt = sess.run([prob_name], {input_name: X_test.astype(numpy.float32)})[0] - -import pprint -pprint.pprint(prob_rt[0:3]) - -############################### -# Let's benchmark. -from timeit import Timer - -def speed(inst, number=10, repeat=20): - timer = Timer(inst, globals=globals()) - raw = numpy.array(timer.repeat(repeat, number=number)) - ave = raw.sum() / len(raw) / number - mi, ma = raw.min() / number, raw.max() / number - print("Average %1.3g min=%1.3g max=%1.3g" % (ave, mi, ma)) - return ave - -print("Execution time for clr.predict") -speed("clr.predict(X_test)") - -print("Execution time for ONNX Runtime") -speed("sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]") - -############################### -# Let's benchmark a scenario similar to what a webservice -# experiences: the model has to do one prediction at a time -# as opposed to a batch of prediction. - -def loop(X_test, fct, n=None): - nrow = X_test.shape[0] - if n is None: - n = nrow - for i in range(0, n): - im = i % nrow - fct(X_test[im: im+1]) - -print("Execution time for clr.predict") -speed("loop(X_test, clr.predict, 100)") - -def sess_predict(x): - return sess.run([label_name], {input_name: x.astype(numpy.float32)})[0] - -print("Execution time for sess_predict") -speed("loop(X_test, sess_predict, 100)") - -##################################### -# Let's do the same for the probabilities. - -print("Execution time for predict_proba") -speed("loop(X_test, clr.predict_proba, 100)") - -def sess_predict_proba(x): - return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] - -print("Execution time for sess_predict_proba") -speed("loop(X_test, sess_predict_proba, 100)") - -##################################### -# This second comparison is better as -# ONNX Runtime, in this experience, -# computes the label and the probabilities -# in every case. - -########################################## -# Benchmark with RandomForest -# +++++++++++++++++++++++++++ -# -# We first train and save a model in ONNX format. -from sklearn.ensemble import RandomForestClassifier -rf = RandomForestClassifier() -rf.fit(X_train, y_train) - -initial_type = [('float_input', FloatTensorType([1, 4]))] -onx = convert_sklearn(rf, initial_types=initial_type) -with open("rf_iris.onnx", "wb") as f: - f.write(onx.SerializeToString()) - -################################### -# We compare. - -sess = rt.InferenceSession("rf_iris.onnx") - -def sess_predict_proba_rf(x): - return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] - -print("Execution time for predict_proba") -speed("loop(X_test, rf.predict_proba, 100)") - -print("Execution time for sess_predict_proba") -speed("loop(X_test, sess_predict_proba_rf, 100)") - -################################## -# Let's see with different number of trees. - -measures = [] - -for n_trees in range(5, 51, 5): - print(n_trees) - rf = RandomForestClassifier(n_estimators=n_trees) - rf.fit(X_train, y_train) - initial_type = [('float_input', FloatTensorType([1, 4]))] - onx = convert_sklearn(rf, initial_types=initial_type) - with open("rf_iris_%d.onnx" % n_trees, "wb") as f: - f.write(onx.SerializeToString()) - sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees) - def sess_predict_proba_loop(x): - return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] - tsk = speed("loop(X_test, rf.predict_proba, 100)", number=5, repeat=5) - trt = speed("loop(X_test, sess_predict_proba_loop, 100)", number=5, repeat=5) - measures.append({'n_trees': n_trees, 'sklearn': tsk, 'rt': trt}) - -from pandas import DataFrame -df = DataFrame(measures) -ax = df.plot(x="n_trees", y="sklearn", label="scikit-learn", c="blue", logy=True) -df.plot(x="n_trees", y="rt", label="onnxruntime", - ax=ax, c="green", logy=True) -ax.set_xlabel("Number of trees") -ax.set_ylabel("Prediction time (s)") -ax.set_title("Speed comparison between scikit-learn and ONNX Runtime\nFor a random forest on Iris dataset") -ax.legend() diff --git a/docs/api/python/downloads/dee2ae82948a521867a372a6b9515393/plot_load_and_predict.ipynb b/docs/api/python/downloads/dee2ae82948a521867a372a6b9515393/plot_load_and_predict.ipynb deleted file mode 100644 index 14032652289eb..0000000000000 --- a/docs/api/python/downloads/dee2ae82948a521867a372a6b9515393/plot_load_and_predict.ipynb +++ /dev/null @@ -1,126 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "%matplotlib inline" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "\n\n# Load and predict with ONNX Runtime and a very simple model\n\nThis example demonstrates how to load a model and compute\nthe output for an input vector. It also shows how to\nretrieve the definition of its inputs and outputs.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import onnxruntime as rt\nimport numpy\nfrom onnxruntime.datasets import get_example" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's load a very simple model.\nThe model is available on github `onnx...test_sigmoid `_.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "example1 = get_example(\"sigmoid.onnx\")\nsess = rt.InferenceSession(example1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's see the input name and shape.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "input_name = sess.get_inputs()[0].name\nprint(\"input name\", input_name)\ninput_shape = sess.get_inputs()[0].shape\nprint(\"input shape\", input_shape)\ninput_type = sess.get_inputs()[0].type\nprint(\"input type\", input_type)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's see the output name and shape.\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "output_name = sess.get_outputs()[0].name\nprint(\"output name\", output_name) \noutput_shape = sess.get_outputs()[0].shape\nprint(\"output shape\", output_shape)\noutput_type = sess.get_outputs()[0].type\nprint(\"output type\", output_type)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's compute its outputs (or predictions if it is a machine learned model).\n\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "import numpy.random\nx = numpy.random.random((3,4,5))\nx = x.astype(numpy.float32)\nres = sess.run([output_name], {input_name: x})\nprint(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.7.2" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/docs/api/python/downloads/df88a32237a9b3e764a8da54c1743145/plot_backend.py b/docs/api/python/downloads/df88a32237a9b3e764a8da54c1743145/plot_backend.py deleted file mode 100644 index 63d3cbce34d08..0000000000000 --- a/docs/api/python/downloads/df88a32237a9b3e764a8da54c1743145/plot_backend.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" - -.. _l-example-backend-api: - -ONNX Runtime Backend for ONNX -============================= - -*ONNX Runtime* extends the -`onnx backend API `_ -to run predictions using this runtime. -Let's use the API to compute the prediction -of a simple logistic regression model. -""" -import numpy as np -from onnxruntime import datasets -from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument -import onnxruntime.backend as backend -from onnx import load - -name = datasets.get_example("logreg_iris.onnx") -model = load(name) - -rep = backend.prepare(model, 'CPU') -x = np.array([[-1.0, -2.0]], dtype=np.float32) -try: - label, proba = rep.run(x) - print("label={}".format(label)) - print("probabilities={}".format(proba)) -except (RuntimeError, InvalidArgument) as e: - print(e) - -######################################## -# The device depends on how the package was compiled, -# GPU or CPU. -from onnxruntime import get_device -print(get_device()) - -######################################## -# The backend can also directly load the model -# without using *onnx*. - -rep = backend.prepare(name, 'CPU') -x = np.array([[-1.0, -2.0]], dtype=np.float32) -try: - label, proba = rep.run(x) - print("label={}".format(label)) - print("probabilities={}".format(proba)) -except (RuntimeError, InvalidArgument) as e: - print(e) - -####################################### -# The backend API is implemented by other frameworks -# and makes it easier to switch between multiple runtimes -# with the same API. diff --git a/docs/api/python/downloads/e4ee07af6afb721729db3bf156693fa2/plot_profiling.py b/docs/api/python/downloads/e4ee07af6afb721729db3bf156693fa2/plot_profiling.py deleted file mode 100644 index f0ea727ede1b2..0000000000000 --- a/docs/api/python/downloads/e4ee07af6afb721729db3bf156693fa2/plot_profiling.py +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -""" - -.. _l-example-profiling: - -Profile the execution of a simple model -======================================= - -*ONNX Runtime* can profile the execution of the model. -This example shows how to interpret the results. -""" -import onnx -import onnxruntime as rt -import numpy -from onnxruntime.datasets import get_example - - -def change_ir_version(filename, ir_version=6): - "onnxruntime==1.2.0 does not support opset <= 7 and ir_version > 6" - with open(filename, "rb") as f: - model = onnx.load(f) - model.ir_version = 6 - if model.opset_import[0].version <= 7: - model.opset_import[0].version = 11 - return model - - - - -######################### -# Let's load a very simple model and compute some prediction. - -example1 = get_example("mul_1.onnx") -onnx_model = change_ir_version(example1) -onnx_model_str = onnx_model.SerializeToString() -sess = rt.InferenceSession(onnx_model_str) -input_name = sess.get_inputs()[0].name - -x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) -res = sess.run(None, {input_name: x}) -print(res) - -######################### -# We need to enable to profiling -# before running the predictions. - -options = rt.SessionOptions() -options.enable_profiling = True -sess_profile = rt.InferenceSession(onnx_model_str, options) -input_name = sess.get_inputs()[0].name - -x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) - -sess.run(None, {input_name: x}) -prof_file = sess_profile.end_profiling() -print(prof_file) - -########################### -# The results are stored un a file in JSON format. -# Let's see what it contains. -import json -with open(prof_file, "r") as f: - sess_time = json.load(f) -import pprint -pprint.pprint(sess_time) - - - diff --git a/docs/api/python/downloads/f8e5d8e309ca291f68bd029c26838ccc/plot_backend.ipynb b/docs/api/python/downloads/f8e5d8e309ca291f68bd029c26838ccc/plot_backend.ipynb index b4e02617aa957..3dab79a3dbce2 100644 --- a/docs/api/python/downloads/f8e5d8e309ca291f68bd029c26838ccc/plot_backend.ipynb +++ b/docs/api/python/downloads/f8e5d8e309ca291f68bd029c26838ccc/plot_backend.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "import numpy as np\nfrom onnxruntime import datasets\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport onnxruntime.backend as backend\nfrom onnx import load\n\nname = datasets.get_example(\"logreg_iris.onnx\")\nmodel = load(name)\n\nrep = backend.prepare(model, 'CPU')\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" + "import numpy as np\nfrom onnxruntime import datasets\nfrom onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument\nimport onnxruntime.backend as backend\nfrom onnx import load" ] }, { @@ -44,7 +44,7 @@ }, "outputs": [], "source": [ - "from onnxruntime import get_device\nprint(get_device())" + "from onnxruntime import get_device\ndevice = get_device()\n\nname = datasets.get_example(\"logreg_iris.onnx\")\nmodel = load(name)\n\nrep = backend.prepare(model, device)\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" ] }, { @@ -62,7 +62,7 @@ }, "outputs": [], "source": [ - "rep = backend.prepare(name, 'CPU')\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" + "rep = backend.prepare(name, device)\nx = np.array([[-1.0, -2.0]], dtype=np.float32)\ntry:\n label, proba = rep.run(x)\n print(\"label={}\".format(label))\n print(\"probabilities={}\".format(proba))\nexcept (RuntimeError, InvalidArgument) as e:\n print(e)" ] }, { @@ -89,7 +89,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.8.10" } }, "nbformat": 4, diff --git a/docs/api/python/examples_md.html b/docs/api/python/examples_md.html index 9b711c0700a7c..54d0311599a44 100644 --- a/docs/api/python/examples_md.html +++ b/docs/api/python/examples_md.html @@ -4,16 +4,17 @@ - - Gallery of examples — ONNX Runtime 1.7.0 documentation - - + + + Gallery of examples — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -73,7 +74,7 @@

    Related Topics

    Quick search

    @@ -95,7 +96,7 @@

    Quick search

    ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/genindex.html b/docs/api/python/genindex.html index f901bb353d7a3..aa4eb6187c7e6 100644 --- a/docs/api/python/genindex.html +++ b/docs/api/python/genindex.html @@ -5,15 +5,15 @@ - Index — ONNX Runtime 1.7.0 documentation - - + Index — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -40,10 +40,13 @@

    Index

    A + | B | C | D | E + | F | G + | H | I | L | M @@ -64,11 +67,37 @@

    A

  • add_free_dimension_override_by_name() (onnxruntime.SessionOptions method)
  • - - + + + +

    B

    + + +
    @@ -76,7 +105,11 @@

    A

    C

    +
    @@ -84,11 +117,29 @@

    C

    D

    @@ -96,17 +147,31 @@

    D

    E

    +
    + +

    F

    + +
    @@ -118,15 +183,43 @@

    G

  • get_example() (in module onnxruntime.datasets)
  • -
  • get_session_config_entry() (onnxruntime.SessionOptions method) +
  • get_inputs() (onnxruntime.InferenceSession method) +
  • +
  • get_modelmeta() (onnxruntime.InferenceSession method) +
  • +
  • get_outputs() (onnxruntime.InferenceSession method) + +
  • +
  • get_overridable_initializers() (onnxruntime.InferenceSession method)
  • + + +

    H

    + +
    @@ -136,13 +229,23 @@

    I

    @@ -150,13 +253,13 @@

    I

    L

    @@ -224,9 +339,17 @@

    R

      -
    • run() (in module onnxruntime.backend) +
    • run_with_iobinding() (onnxruntime.InferenceSession method) +
    • +
    • run_with_ort_values() (onnxruntime.InferenceSession method)
    • RunOptions (class in onnxruntime)
    • @@ -237,10 +360,20 @@

      S

        -
      • shape() (onnxruntime.NodeArg property) +
      • sparse_coo_from_numpy() (onnxruntime.SparseTensor static method) +
      • +
      • sparse_csr_from_numpy() (onnxruntime.SparseTensor static method) +
      • +
      • SparseTensor (class in onnxruntime)
      • supports_device() (in module onnxruntime.backend)
      • @@ -250,11 +383,13 @@

        S

        T

        @@ -262,7 +397,7 @@

        T

        U

        @@ -270,7 +405,11 @@

        U

        V

        +
        @@ -313,7 +452,7 @@

        Related Topics

        Quick search

        @@ -335,7 +474,7 @@

        Quick search

        ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 diff --git a/docs/api/python/images/sphx_glr_plot_backend_thumb.png b/docs/api/python/images/sphx_glr_plot_backend_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_backend_thumb.png and b/docs/api/python/images/sphx_glr_plot_backend_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_common_errors_thumb.png b/docs/api/python/images/sphx_glr_plot_common_errors_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_common_errors_thumb.png and b/docs/api/python/images/sphx_glr_plot_common_errors_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_convert_pipeline_vectorizer_thumb.png b/docs/api/python/images/sphx_glr_plot_convert_pipeline_vectorizer_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_convert_pipeline_vectorizer_thumb.png and b/docs/api/python/images/sphx_glr_plot_convert_pipeline_vectorizer_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_load_and_predict_thumb.png b/docs/api/python/images/sphx_glr_plot_load_and_predict_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_load_and_predict_thumb.png and b/docs/api/python/images/sphx_glr_plot_load_and_predict_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_metadata_thumb.png b/docs/api/python/images/sphx_glr_plot_metadata_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_metadata_thumb.png and b/docs/api/python/images/sphx_glr_plot_metadata_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_pipeline_001.png b/docs/api/python/images/sphx_glr_plot_pipeline_001.png index c91809a34eea5..34c5fb668a966 100644 Binary files a/docs/api/python/images/sphx_glr_plot_pipeline_001.png and b/docs/api/python/images/sphx_glr_plot_pipeline_001.png differ diff --git a/docs/api/python/images/sphx_glr_plot_pipeline_thumb.png b/docs/api/python/images/sphx_glr_plot_pipeline_thumb.png index b2147e8559020..0a2315a0fb439 100644 Binary files a/docs/api/python/images/sphx_glr_plot_pipeline_thumb.png and b/docs/api/python/images/sphx_glr_plot_pipeline_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_profiling_thumb.png b/docs/api/python/images/sphx_glr_plot_profiling_thumb.png index 233f8e605efca..8a5fed589d17f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_profiling_thumb.png and b/docs/api/python/images/sphx_glr_plot_profiling_thumb.png differ diff --git a/docs/api/python/images/sphx_glr_plot_train_convert_predict_001.png b/docs/api/python/images/sphx_glr_plot_train_convert_predict_001.png index 1bf4999d1cd48..a0015a5ad871f 100644 Binary files a/docs/api/python/images/sphx_glr_plot_train_convert_predict_001.png and b/docs/api/python/images/sphx_glr_plot_train_convert_predict_001.png differ diff --git a/docs/api/python/images/sphx_glr_plot_train_convert_predict_thumb.png b/docs/api/python/images/sphx_glr_plot_train_convert_predict_thumb.png index 358dfc6dd1e09..6eeb0f2bb9225 100644 Binary files a/docs/api/python/images/sphx_glr_plot_train_convert_predict_thumb.png and b/docs/api/python/images/sphx_glr_plot_train_convert_predict_thumb.png differ diff --git a/docs/api/python/index.html b/docs/api/python/index.html index df5cd71a2e5f5..8b11848df1bfb 100644 --- a/docs/api/python/index.html +++ b/docs/api/python/index.html @@ -4,16 +4,17 @@ - - Python Bindings for ONNX Runtime — ONNX Runtime 1.7.0 documentation - - + + + Python Bindings for ONNX Runtime — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -36,7 +37,7 @@
        -
        +

        Python Bindings for ONNX Runtime

        ONNX Runtime is a performance-focused scoring engine for Open Neural Network Exchange (ONNX) models. For more information on ONNX Runtime, please see aka.ms/onnxruntime or the Github project.

        @@ -47,7 +48,7 @@

        Python Bindings for ONNX RuntimeGallery of examples

      - + @@ -87,7 +88,7 @@

      Related Topics

      Quick search

      @@ -109,7 +110,7 @@

      Quick search

      ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 | diff --git a/docs/api/python/modules/index.html b/docs/api/python/modules/index.html index 82fb75be7d382..95672aba918e6 100644 --- a/docs/api/python/modules/index.html +++ b/docs/api/python/modules/index.html @@ -5,15 +5,15 @@ - Overview: module code — ONNX Runtime 1.7.0 documentation - - + Overview: module code — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -77,7 +77,7 @@

      Related Topics

      Quick search

      @@ -99,7 +99,7 @@

      Quick search

      ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 diff --git a/docs/api/python/modules/onnxruntime/capi/onnxruntime_inference_collection.html b/docs/api/python/modules/onnxruntime/capi/onnxruntime_inference_collection.html index eb51908d06367..62ba39e85ba4b 100644 --- a/docs/api/python/modules/onnxruntime/capi/onnxruntime_inference_collection.html +++ b/docs/api/python/modules/onnxruntime/capi/onnxruntime_inference_collection.html @@ -5,15 +5,15 @@ - onnxruntime.capi.onnxruntime_inference_collection — ONNX Runtime 1.7.0 documentation - - + onnxruntime.capi.onnxruntime_inference_collection — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -45,17 +45,19 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      import os import warnings -from onnxruntime.capi import _pybind_state as C +from onnxruntime.capi import _pybind_state as C def get_ort_device_type(device): - device = device.lower() - if device == 'cuda': + device_type = device if type(device) is str else device.type.lower() + if device_type == 'cuda': return C.OrtDevice.cuda() - elif device == 'cpu': + elif device_type == 'cpu': return C.OrtDevice.cpu() + elif device_type == 'ort': + return C.get_ort_device(device.index).device_type() else: - raise Exception('Unsupported device type: ' + device) + raise Exception('Unsupported device type: ' + device_type) def check_and_normalize_provider_args(providers, provider_options, available_provider_names): @@ -88,8 +90,8 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      def set_provider_options(name, options): if name not in available_provider_names: - raise ValueError("Specified provider '{}' is unavailable. Available providers: '{}'".format( - name, ", ".join(available_provider_names))) + warnings.warn("Specified provider '{}' is not in available provider names." + "Available providers: '{}'".format(name, ", ".join(available_provider_names))) if name in provider_name_to_options: warnings.warn("Duplicate provider '{}' encountered, ignoring.".format(name)) @@ -134,7 +136,7 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      """ This is the main class used to run a model. """ - def __init__(self): + def __init__(self): # self._sess is managed by the derived class and relies on bindings from C.InferenceSession self._sess = None @@ -176,19 +178,16 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      precedence. Values can either be provider names or tuples of (provider name, options dict). If not provided, then all available providers are used with the default precedence. - The next release (ORT 1.10) will require explicitly setting - this providers parameter if you want to use execution providers - other than the default CPU provider (as opposed to the current - behavior of providers getting set/registered by default based on the - build flags) when instantiating InferenceSession. :param provider_options: Optional sequence of options dicts corresponding to the providers listed in 'providers'. 'providers' can contain either names or names and options. When any options are given in 'providers', 'provider_options' should not be used. - The list of providers is ordered by precedence. For example ['CUDAExecutionProvider', 'CPUExecutionProvider'] - means execute a node using CUDAExecutionProvider if capable, otherwise execute using CPUExecutionProvider. + The list of providers is ordered by precedence. For example + `['CUDAExecutionProvider', 'CPUExecutionProvider']` + means execute a node using CUDAExecutionProvider if capable, + otherwise execute using CPUExecutionProvider. """ # recreate the underlying C.InferenceSession self._reset_session(providers, provider_options) @@ -240,6 +239,49 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      else: raise + def run_with_ort_values(self, output_names, input_dict_ort_values, run_options=None): + """ + Compute the predictions. + + :param output_names: name of the outputs + :param input_feed: dictionary ``{ input_name: input_ort_value }`` + See ``OrtValue`` class how to create `OrtValue` + from numpy array or `SparseTensor` + :param run_options: See :class:`onnxruntime.RunOptions`. + :return: an array of `OrtValue` + + :: + + sess.run([output_name], {input_name: x}) + """ + def invoke(sess, output_names, input_dict_ort_values, run_options): + input_dict = {} + for n, v in input_dict_ort_values.items(): + input_dict[n] = v._get_c_value() + result = sess.run_with_ort_values(input_dict, output_names, run_options) + ort_values = [OrtValue(v) for v in result] + return ort_values + + num_required_inputs = len(self._inputs_meta) + num_inputs = len(input_dict_ort_values) + # the graph may have optional inputs used to override initializers. allow for that. + if num_inputs < num_required_inputs: + raise ValueError("Model requires {} inputs. Input Feed contains {}".format(num_required_inputs, num_inputs)) + if not output_names: + output_names = [output.name for output in self._outputs_meta] + try: + return invoke(self._sess, output_names, input_dict_ort_values, run_options) + except C.EPFail as err: + if self._enable_fallback: + print("EP Error: {} using {}".format(str(err), self._providers)) + print("Falling back to {} and retrying.".format(self._fallback_providers)) + self.set_providers(self._fallback_providers) + # Fallback only once. + self.disable_fallback() + return invoke(self._sess, output_names, input_dict_ort_values, run_options) + else: + raise + def end_profiling(self): """ End profiling and return results in a file. @@ -276,7 +318,7 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      """ This is the main class used to run a model. """ - def __init__(self, path_or_bytes, sess_options=None, providers=None, provider_options=None): + def __init__(self, path_or_bytes, sess_options=None, providers=None, provider_options=None, **kwargs): """ :param path_or_bytes: filename or serialized ONNX or ORT format model in a byte string :param sess_options: session options @@ -289,9 +331,12 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      The model type will be inferred unless explicitly set in the SessionOptions. To explicitly set: - so = onnxruntime.SessionOptions() - so.add_session_config_entry('session.load_model_format', 'ONNX') or - so.add_session_config_entry('session.load_model_format', 'ORT') or + + :: + + so = onnxruntime.SessionOptions() + # so.add_session_config_entry('session.load_model_format', 'ONNX') or + so.add_session_config_entry('session.load_model_format', 'ORT') A file extension of '.ort' will be inferred as an ORT format model. All other filenames are assumed to be ONNX format models. @@ -299,8 +344,10 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      'providers' can contain either names or names and options. When any options are given in 'providers', 'provider_options' should not be used. - The list of providers is ordered by precedence. For example ['CUDAExecutionProvider', 'CPUExecutionProvider'] - means execute a node using CUDAExecutionProvider if capable, otherwise execute using CPUExecutionProvider. + The list of providers is ordered by precedence. For example + `['CUDAExecutionProvider', 'CPUExecutionProvider']` + means execute a node using `CUDAExecutionProvider` + if capable, otherwise execute using `CPUExecutionProvider`. """ Session.__init__(self) @@ -319,11 +366,14 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      self._enable_fallback = True self._read_config_from_model = os.environ.get('ORT_LOAD_CONFIG_FROM_MODEL') == '1' + # internal parameters that we don't expect to be used in general so aren't documented + disabled_optimizers = kwargs['disabled_optimizers'] if 'disabled_optimizers' in kwargs else None + try: - self._create_inference_session(providers, provider_options) - except RuntimeError: + self._create_inference_session(providers, provider_options, disabled_optimizers) + except ValueError: if self._enable_fallback: - print("EP Error using {}".format(self._providers)) + print("EP Error using {}".format(providers)) print("Falling back to {} and retrying.".format(self._fallback_providers)) self._create_inference_session(self._fallback_providers, None) # Fallback only once. @@ -331,28 +381,40 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      else: raise - def _create_inference_session(self, providers, provider_options): + def _create_inference_session(self, providers, provider_options, disabled_optimizers=None): available_providers = C.get_available_providers() - # validate providers and provider_options before other initialization - providers, provider_options = check_and_normalize_provider_args(providers, - provider_options, - available_providers) - # Tensorrt can fall back to CUDA. All others fall back to CPU. if 'TensorrtExecutionProvider' in available_providers: self._fallback_providers = ['CUDAExecutionProvider', 'CPUExecutionProvider'] else: self._fallback_providers = ['CPUExecutionProvider'] + # validate providers and provider_options before other initialization + providers, provider_options = check_and_normalize_provider_args(providers, + provider_options, + available_providers) + if providers == [] and len(available_providers) > 1: + self.disable_fallback() + raise ValueError("This ORT build has {} enabled. ".format(available_providers) + + "Since ORT 1.9, you are required to explicitly set " + + "the providers parameter when instantiating InferenceSession. For example, " + "onnxruntime.InferenceSession(..., providers={}, ...)".format(available_providers)) + session_options = self._sess_options if self._sess_options else C.get_default_session_options() if self._model_path: sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model) else: sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model) + if disabled_optimizers is None: + disabled_optimizers = set() + elif not isinstance(disabled_optimizers, set): + # convert to set. assumes iterable + disabled_optimizers = set(disabled_optimizers) + # initialize the C++ InferenceSession - sess.initialize_session(providers, provider_options) + sess.initialize_session(providers, provider_options, disabled_optimizers) self._sess = sess self._sess_options = self._sess.session_options @@ -383,15 +445,15 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      self._create_inference_session(providers, provider_options)
      -class IOBinding: +
      [docs]class IOBinding: ''' This class provides API to bind input/output to a specified device, e.g. GPU. ''' - def __init__(self, session): + def __init__(self, session): self._iobinding = C.SessionIOBinding(session._sess) - self._numpy_obj_references = [] + self._numpy_obj_references = {} - def bind_cpu_input(self, name, arr_on_cpu): +
      [docs] def bind_cpu_input(self, name, arr_on_cpu): ''' bind an input to array on CPU :param name: input name @@ -400,10 +462,10 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      # Hold a reference to the numpy object as the bound OrtValue is backed # directly by the data buffer of the numpy object and so the numpy object # must be around until this IOBinding instance is around - self._numpy_obj_references.append(arr_on_cpu) - self._iobinding.bind_input(name, arr_on_cpu) + self._numpy_obj_references[name] = arr_on_cpu + self._iobinding.bind_input(name, arr_on_cpu)
      - def bind_input(self, name, device_type, device_id, element_type, shape, buffer_ptr): +
      [docs] def bind_input(self, name, device_type, device_id, element_type, shape, buffer_ptr): ''' :param name: input name :param device_type: e.g. cpu, cuda @@ -415,16 +477,19 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      self._iobinding.bind_input(name, C.OrtDevice(get_ort_device_type(device_type), C.OrtDevice.default_memory(), device_id), - element_type, shape, buffer_ptr) + element_type, shape, buffer_ptr)
      - def bind_ortvalue_input(self, name, ortvalue): +
      [docs] def bind_ortvalue_input(self, name, ortvalue): ''' :param name: input name :param ortvalue: OrtValue instance to bind ''' - self._iobinding.bind_ortvalue_input(name, ortvalue._ortvalue) + self._iobinding.bind_ortvalue_input(name, ortvalue._ortvalue)
      + + def synchronize_inputs(self): + self._iobinding.synchronize_inputs() - def bind_output(self, name, device_type='cpu', device_id=0, element_type=None, shape=None, buffer_ptr=None): +
      [docs] def bind_output(self, name, device_type='cpu', device_id=0, element_type=None, shape=None, buffer_ptr=None): ''' :param name: output name :param device_type: e.g. cpu, cuda, cpu by default @@ -450,16 +515,19 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      self._iobinding.bind_output(name, C.OrtDevice(get_ort_device_type(device_type), C.OrtDevice.default_memory(), device_id), - element_type, shape, buffer_ptr) + element_type, shape, buffer_ptr)
      - def bind_ortvalue_output(self, name, ortvalue): +
      [docs] def bind_ortvalue_output(self, name, ortvalue): ''' :param name: output name :param ortvalue: OrtValue instance to bind ''' - self._iobinding.bind_ortvalue_output(name, ortvalue._ortvalue) + self._iobinding.bind_ortvalue_output(name, ortvalue._ortvalue)
      - def get_outputs(self): + def synchronize_outputs(self): + self._iobinding.synchronize_outputs() + +
      [docs] def get_outputs(self): ''' Returns the output OrtValues from the Run() that preceded the call. The data buffer of the obtained OrtValues may not reside on CPU memory @@ -469,26 +537,26 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      for ortvalue in self._iobinding.get_outputs(): returned_ortvalues.append(OrtValue(ortvalue)) - return returned_ortvalues + return returned_ortvalues
      - def copy_outputs_to_cpu(self): +
      [docs] def copy_outputs_to_cpu(self): '''Copy output contents to CPU (if on another device). No-op if already on the CPU.''' - return self._iobinding.copy_outputs_to_cpu() + return self._iobinding.copy_outputs_to_cpu()
      def clear_binding_inputs(self): self._iobinding.clear_binding_inputs() def clear_binding_outputs(self): - self._iobinding.clear_binding_outputs() + self._iobinding.clear_binding_outputs()
      -class OrtValue: +
      [docs]class OrtValue: ''' A data structure that supports all ONNX data formats (tensors and non-tensors) that allows users to place the data backing these on a device, for example, on a CUDA supported device. This class provides APIs to construct and deal with OrtValues. ''' - def __init__(self, ortvalue, numpy_obj=None): + def __init__(self, ortvalue, numpy_obj=None): if isinstance(ortvalue, C.OrtValue): self._ortvalue = ortvalue # Hold a ref count to the numpy object if the OrtValue is backed directly @@ -499,11 +567,15 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      raise ValueError("`Provided ortvalue` needs to be of type " + "`onnxruntime.capi.onnxruntime_pybind11_state.OrtValue`") - @staticmethod + def _get_c_value(self): + return self._ortvalue + +
      [docs] @staticmethod def ortvalue_from_numpy(numpy_obj, device_type='cpu', device_id=0): ''' Factory method to construct an OrtValue (which holds a Tensor) from a given Numpy object A copy of the data in the Numpy object is held by the OrtValue only if the device is NOT cpu + :param numpy_obj: The Numpy object to construct the OrtValue from :param device_type: e.g. cpu, cuda, cpu by default :param device_id: device id, e.g. 0 @@ -512,12 +584,13 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      # is backed directly by the data buffer of the numpy object and so the numpy object # must be around until this OrtValue instance is around return OrtValue(C.OrtValue.ortvalue_from_numpy(numpy_obj, C.OrtDevice(get_ort_device_type(device_type), - C.OrtDevice.default_memory(), device_id)), numpy_obj if device_type.lower() == 'cpu' else None) + C.OrtDevice.default_memory(), device_id)), numpy_obj if device_type.lower() == 'cpu' else None)
      - @staticmethod +
      [docs] @staticmethod def ortvalue_from_shape_and_type(shape=None, element_type=None, device_type='cpu', device_id=0): ''' Factory method to construct an OrtValue (which holds a Tensor) from given shape and element_type + :param shape: List of integers indicating the shape of the OrtValue :param element_type: The data type of the elements in the OrtValue (numpy type) :param device_type: e.g. cpu, cuda, cpu by default @@ -527,44 +600,272 @@

      Source code for onnxruntime.capi.onnxruntime_inference_collection

      raise ValueError("`element_type` and `shape` are to be provided if pre-allocated memory is provided") return OrtValue(C.OrtValue.ortvalue_from_shape_and_type(shape, element_type, - C.OrtDevice(get_ort_device_type(device_type), C.OrtDevice.default_memory(), device_id))) + C.OrtDevice(get_ort_device_type(device_type), C.OrtDevice.default_memory(), device_id)))
      + +
      [docs] @staticmethod + def ort_value_from_sparse_tensor(sparse_tensor): + ''' + The function will construct an OrtValue instance from a valid SparseTensor + The new instance of OrtValue will assume the ownership of sparse_tensor + ''' + return OrtValue(C.OrtValue.ort_value_from_sparse_tensor(sparse_tensor._get_c_tensor()))
      + +
      [docs] def as_sparse_tensor(self): + ''' + The function will return SparseTensor contained in this OrtValue + ''' + return SparseTensor(self._ortvalue.as_sparse_tensor())
      - def data_ptr(self): +
      [docs] def data_ptr(self): ''' Returns the address of the first element in the OrtValue's data buffer ''' - return self._ortvalue.data_ptr() + return self._ortvalue.data_ptr()
      - def device_name(self): +
      [docs] def device_name(self): ''' Returns the name of the device where the OrtValue's data buffer resides e.g. cpu, cuda ''' - return self._ortvalue.device_name().lower() + return self._ortvalue.device_name().lower()
      - def shape(self): +
      [docs] def shape(self): ''' Returns the shape of the data in the OrtValue ''' - return self._ortvalue.shape() + return self._ortvalue.shape()
      - def data_type(self): +
      [docs] def data_type(self): ''' Returns the data type of the data in the OrtValue ''' - return self._ortvalue.data_type() + return self._ortvalue.data_type()
      - def is_tensor(self): +
      [docs] def has_value(self): ''' - Returns True if the OrtValue is a Tensor, else returns False + Returns True if the OrtValue corresponding to an + optional type contains data, else returns False ''' - return self._ortvalue.is_tensor() + return self._ortvalue.has_value()
      - def numpy(self): +
      [docs] def is_tensor(self): + ''' + Returns True if the OrtValue contains a Tensor, else returns False + ''' + return self._ortvalue.is_tensor()
      + +
      [docs] def is_sparse_tensor(self): + ''' + Returns True if the OrtValue contains a SparseTensor, else returns False + ''' + return self._ortvalue.is_sparse_tensor()
      + +
      [docs] def is_tensor_sequence(self): + ''' + Returns True if the OrtValue contains a Tensor Sequence, else returns False + ''' + return self._ortvalue.is_tensor_sequence()
      + +
      [docs] def numpy(self): ''' Returns a Numpy object from the OrtValue. Valid only for OrtValues holding Tensors. Throws for OrtValues holding non-Tensors. + Use accessors to gain a reference to non-Tensor objects such as SparseTensor + ''' + return self._ortvalue.numpy()
      + + +
      [docs]class OrtDevice: + ''' + A data structure that exposes the underlying C++ OrtDevice + ''' + def __init__(self, c_ort_device): + ''' + Internal constructor + ''' + if isinstance(c_ort_device, C.OrtDevice): + self._ort_device = c_ort_device + else: + raise ValueError("`Provided object` needs to be of type " + + "`onnxruntime.capi.onnxruntime_pybind11_state.OrtDevice`") + + def _get_c_device(self): + ''' + Internal accessor to underlying object + ''' + return self._ort_device + + @staticmethod + def make(ort_device_name, device_id): + return OrtDevice(C.OrtDevice(get_ort_device_type(ort_device_name), + C.OrtDevice.default_memory(), device_id)) + + def device_id(self): + return self._ort_device.device_id() + + def device_type(self): + return self._ort_device.device_type()
      + + +
      [docs]class SparseTensor: + ''' + A data structure that project the C++ SparseTensor object + The class provides API to work with the object. + Depending on the format, the class will hold more than one buffer + depending on the format + ''' + def __init__(self, sparse_tensor): + ''' + Internal constructor + ''' + if isinstance(sparse_tensor, C.SparseTensor): + self._tensor = sparse_tensor + else: + # An end user won't hit this error + raise ValueError("`Provided object` needs to be of type " + + "`onnxruntime.capi.onnxruntime_pybind11_state.SparseTensor`") + + def _get_c_tensor(self): + return self._tensor + +
      [docs] @staticmethod + def sparse_coo_from_numpy(dense_shape, values, coo_indices, ort_device): + ''' + Factory method to construct a SparseTensor in COO format from given arguments + + :param dense_shape: 1-D numpy array(int64) or a python list that contains a dense_shape of the sparse tensor + must be on cpu memory + :param values: a homogeneous, contiguous 1-D numpy array that contains non-zero elements of the tensor + of a type. + :param coo_indices: contiguous numpy array(int64) that contains COO indices for the tensor. coo_indices may + have a 1-D shape when it contains a linear index of non-zero values and its length must be equal to + that of the values. It can also be of 2-D shape, in which has it contains pairs of coordinates for + each of the nnz values and its length must be exactly twice of the values length. + :param ort_device: - describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is + suppored for non-numeric data types. + + For primitive types, the method will map values and coo_indices arrays into native memory and will use + them as backing storage. It will increment the reference count for numpy arrays and it will decrement it + on GC. The buffers may reside in any storage either CPU or GPU. + For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those + on other devices and their memory can not be mapped. + ''' + return SparseTensor(C.SparseTensor.sparse_coo_from_numpy(dense_shape, values, coo_indices, + ort_device._get_c_device()))
      + +
      [docs] @staticmethod + def sparse_csr_from_numpy(dense_shape, values, inner_indices, outer_indices, ort_device): + ''' + Factory method to construct a SparseTensor in CSR format from given arguments + + :param dense_shape: 1-D numpy array(int64) or a python list that contains a dense_shape of the + sparse tensor (rows, cols) must be on cpu memory + :param values: a contiguous, homogeneous 1-D numpy array that contains non-zero elements of the tensor + of a type. + :param inner_indices: contiguous 1-D numpy array(int64) that contains CSR inner indices for the tensor. + Its length must be equal to that of the values. + :param outer_indices: contiguous 1-D numpy array(int64) that contains CSR outer indices for the tensor. + Its length must be equal to the number of rows + 1. + :param ort_device: - describes the backing memory owned by the supplied nummpy arrays. Only CPU memory is + suppored for non-numeric data types. + + For primitive types, the method will map values and indices arrays into native memory and will use them as + backing storage. It will increment the reference count and it will decrement then count when it is GCed. + The buffers may reside in any storage either CPU or GPU. + For strings and objects, it will create a copy of the arrays in CPU memory as ORT does not support those + on other devices and their memory can not be mapped. + ''' + return SparseTensor(C.SparseTensor.sparse_csr_from_numpy(dense_shape, values, inner_indices, outer_indices, + ort_device._get_c_device()))
      + +
      [docs] def values(self): + ''' + The method returns a numpy array that is backed by the native memory + if the data type is numeric. Otherwise, the returned numpy array that contains + copies of the strings. + ''' + return self._tensor.values()
      + +
      [docs] def as_coo_view(self): + ''' + The method will return coo representation of the sparse tensor which will enable + querying COO indices. If the instance did not contain COO format, it would throw. + You can query coo indices as: + + :: + + coo_indices = sparse_tensor.as_coo_view().indices() + + which will return a numpy array that is backed by the native memory. + ''' + return self._tensor.get_coo_data()
      + +
      [docs] def as_csrc_view(self): + ''' + The method will return CSR(C) representation of the sparse tensor which will enable + querying CRS(C) indices. If the instance dit not contain CSR(C) format, it would throw. + You can query indices as: + + :: + + inner_ndices = sparse_tensor.as_csrc_view().inner() + outer_ndices = sparse_tensor.as_csrc_view().outer() + + returning numpy arrays backed by the native memory. + ''' + return self._tensor.get_csrc_data()
      + +
      [docs] def as_blocksparse_view(self): + ''' + The method will return coo representation of the sparse tensor which will enable + querying BlockSparse indices. If the instance did not contain BlockSparse format, it would throw. + You can query coo indices as: + + :: + + block_sparse_indices = sparse_tensor.as_blocksparse_view().indices() + + which will return a numpy array that is backed by the native memory + ''' + return self._tensor.get_blocksparse_data()
      + +
      [docs] def to_cuda(self, ort_device): + ''' + Returns a copy of this instance on the specified cuda device + + :param ort_device: with name 'cuda' and valid gpu device id + + The method will throw if: + + - this instance contains strings + - this instance is already on GPU. Cross GPU copy is not supported + - CUDA is not present in this build + - if the specified device is not valid + ''' + return SparseTensor(self._tensor.to_cuda(ort_device._get_c_device()))
      + +
      [docs] def format(self): + ''' + Returns a OrtSparseFormat enumeration + ''' + return self._tensor.format
      + +
      [docs] def dense_shape(self): + ''' + Returns a numpy array(int64) containing a dense shape of a sparse tensor + ''' + return self._tensor.dense_shape()
      + +
      [docs] def data_type(self): + ''' + Returns a string data type of the data in the OrtValue + ''' + return self._tensor.data_type()
      + +
      [docs] def device_name(self): + ''' + Returns the name of the device where the SparseTensor data buffers reside e.g. cpu, cuda ''' - return self._ortvalue.numpy() + return self._tensor.device_name().lower()
      @@ -605,7 +906,7 @@

      Related Topics

      Quick search

      @@ -627,7 +928,7 @@

      Quick search

      ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12
      diff --git a/docs/api/python/modules/onnxruntime/datasets.html b/docs/api/python/modules/onnxruntime/datasets.html index 5ccd25ab09dc2..b4e759a2d8dd6 100644 --- a/docs/api/python/modules/onnxruntime/datasets.html +++ b/docs/api/python/modules/onnxruntime/datasets.html @@ -5,15 +5,15 @@ - onnxruntime.datasets — ONNX Runtime 1.7.0 documentation - - + onnxruntime.datasets — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -93,7 +93,7 @@

      Related Topics

      Quick search

      @@ -115,7 +115,7 @@

      Quick search

      ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12
      diff --git a/docs/api/python/objects.inv b/docs/api/python/objects.inv index dcfe5e81a2d19..138759759d8a3 100644 Binary files a/docs/api/python/objects.inv and b/docs/api/python/objects.inv differ diff --git a/docs/api/python/search.html b/docs/api/python/search.html index 03ed4fa1a1510..75827edb1896e 100644 --- a/docs/api/python/search.html +++ b/docs/api/python/search.html @@ -5,16 +5,16 @@ - Search — ONNX Runtime 1.7.0 documentation - - + Search — ONNX Runtime 1.11.0 documentation + + - - - - + + + + - + @@ -42,26 +42,35 @@

      Search

      -
      - + + + +

      Searching for multiple words only shows matches that contain all words.

      + +
      - +
      + +
      +
      @@ -111,7 +120,7 @@

      Related Topics

      ©2018-2021, Microsoft. | - Powered by Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12
      diff --git a/docs/api/python/searchindex.js b/docs/api/python/searchindex.js index 7565a42d573ff..33823485fffc9 100644 --- a/docs/api/python/searchindex.js +++ b/docs/api/python/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["README","api_summary","auto_examples/index","auto_examples/plot_backend","auto_examples/plot_common_errors","auto_examples/plot_convert_pipeline_vectorizer","auto_examples/plot_load_and_predict","auto_examples/plot_metadata","auto_examples/plot_pipeline","auto_examples/plot_profiling","auto_examples/plot_train_convert_predict","auto_examples/sg_execution_times","examples_md","index","tutorial"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":3,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":2,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.intersphinx":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["README.rst","api_summary.rst","auto_examples/index.rst","auto_examples/plot_backend.rst","auto_examples/plot_common_errors.rst","auto_examples/plot_convert_pipeline_vectorizer.rst","auto_examples/plot_load_and_predict.rst","auto_examples/plot_metadata.rst","auto_examples/plot_pipeline.rst","auto_examples/plot_profiling.rst","auto_examples/plot_train_convert_predict.rst","auto_examples/sg_execution_times.rst","examples_md.rst","index.rst","tutorial.rst"],objects:{"onnxruntime.ModelMetadata":{custom_metadata_map:[1,1,1,""],description:[1,1,1,""],domain:[1,1,1,""],graph_description:[1,1,1,""],graph_name:[1,1,1,""],producer_name:[1,1,1,""],version:[1,1,1,""]},"onnxruntime.NodeArg":{name:[1,1,1,""],shape:[1,1,1,""],type:[1,1,1,""]},"onnxruntime.RunOptions":{log_severity_level:[1,1,1,""],log_verbosity_level:[1,1,1,""],logid:[1,1,1,""],only_execute_path_to_fetches:[1,1,1,""],terminate:[1,1,1,""]},"onnxruntime.SessionOptions":{add_free_dimension_override_by_denotation:[1,1,1,""],add_free_dimension_override_by_name:[1,1,1,""],add_initializer:[1,1,1,""],add_session_config_entry:[1,1,1,""],enable_cpu_mem_arena:[1,1,1,""],enable_mem_pattern:[1,1,1,""],enable_profiling:[1,1,1,""],execution_mode:[1,1,1,""],execution_order:[1,1,1,""],get_session_config_entry:[1,1,1,""],graph_optimization_level:[1,1,1,""],inter_op_num_threads:[1,1,1,""],intra_op_num_threads:[1,1,1,""],log_severity_level:[1,1,1,""],log_verbosity_level:[1,1,1,""],logid:[1,1,1,""],optimized_model_filepath:[1,1,1,""],profile_file_prefix:[1,1,1,""],register_custom_ops_library:[1,1,1,""],use_deterministic_compute:[1,1,1,""]},"onnxruntime.backend":{is_compatible:[1,2,1,""],prepare:[1,2,1,""],run:[1,2,1,""],supports_device:[1,2,1,""]},"onnxruntime.datasets":{get_example:[1,2,1,""]},onnxruntime:{InferenceSession:[1,0,1,""],ModelMetadata:[1,0,1,""],NodeArg:[1,0,1,""],RunOptions:[1,0,1,""],SessionOptions:[1,0,1,""],get_device:[1,2,1,""]}},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"],"2":["py","function","Python function"]},objtypes:{"0":"py:class","1":"py:method","2":"py:function"},terms:{"000":11,"000101":10,"0002686927327886224":4,"00152":10,"00156":10,"0015644603711552918":10,"00161":10,"00163":10,"00165":10,"00166":10,"00167":10,"00169":10,"0016972313076257703":10,"0017":10,"00172":10,"00173":10,"00174":10,"00175":10,"00176":10,"00177":10,"00179":10,"0018":10,"00181":10,"00183":10,"00185":10,"00187":10,"00188":10,"00189":10,"0019":10,"00196":10,"0024466365575790405":4,"00245":10,"00274":10,"0027408220106735826":10,"0041598789393901825":10,"00442":10,"006":7,"00694":10,"00723":10,"00837":10,"010":9,"0104":10,"0108":10,"0115":10,"0116":7,"012":6,"018":4,"019":3,"021566055715084076":4,"0215695519000296e":10,"027834143489599228":4,"02e":10,"04_18":9,"05173242464661598":10,"055770788341760635":10,"05987146869301796":10,"0x7fca300dcda0":10,"0x7fd0a620e860":8,"100":10,"101":9,"107":10,"118":10,"134":9,"14094172418117523":10,"15987711e":10,"165":10,"167":10,"169":10,"17324282e":10,"17e":10,"227":[9,10],"228":10,"231":10,"244":8,"286":10,"291":10,"296":10,"342":10,"346":10,"3c59201b940f410fa29dc71ea9d5767d":7,"404":10,"407":10,"40941788e":10,"417":[10,11],"44228260e":10,"459":10,"463":10,"467":10,"5007695":6,"50415695":6,"5052765":6,"5105157":6,"5138594":6,"51468205":6,"5150477":6,"5155948":6,"51758766":6,"5197903":6,"521":10,"5294609":6,"531":10,"53817046":6,"5395019":6,"5410304":6,"5447472":6,"54898335e":10,"54921585":6,"551158":6,"55247986":6,"556":10,"5584753":6,"56175166":6,"5651827":6,"56617785":6,"56778824":6,"56e":10,"5707261":6,"57149607":6,"57431483":6,"577":10,"57707615e":10,"582":10,"5845876":6,"5885481":6,"5907483":6,"592":5,"59442437":6,"596162":6,"59664494":6,"596786":6,"597":10,"60125333":6,"6099661":6,"61100346":6,"6119356":6,"61e":10,"62632954":6,"6270167988259345e":4,"62868774":6,"642":10,"64250827":6,"645":10,"6528918":6,"6545371":6,"6563896":6,"66830933":6,"66855776":6,"67160237":6,"6744693":6,"6819708":6,"6910895":6,"6941072":6,"7030401":6,"7051111":6,"7062323":6,"70664704":6,"7088654":6,"7094791":6,"71235013":6,"7210481":6,"724396":6,"72844744":6,"72e":10,"765":10,"78002823e":10,"78002844931325e":10,"787709464906584e":4,"848444978558249":5,"8548984527587891":10,"88396143e":10,"888396143913269":10,"9442282915115356":10,"9505997896194458":4,"98714288e":10,"9974970817565918":4,"9997311234474182":4,"9999999999999528":5,"boolean":1,"byte":[1,4],"case":[1,5,10],"class":[1,4],"default":1,"float":[1,4,5,6],"function":1,"import":[3,4,5,6,7,8,9,10,14],"int":[1,5],"public":1,"return":[1,4,9,10],"switch":3,"true":[1,9,10],"try":[3,4,5],"while":1,And:10,But:5,For:[0,13],That:8,The:[1,3,4,5,6,9,10,14],Then:[8,10],There:[8,14],These:1,With:7,_logist:10,_logistic_solver_convergence_msg:10,about:1,absolut:1,access:1,across:1,actual:[1,4,5],add_free_dimension_override_by_denot:1,add_free_dimension_override_by_nam:1,add_initi:1,add_session_config_entri:1,addit:1,address:1,aka:[0,13],all:[1,2,4],alloc:1,allow:1,also:[1,3,6,10],altern:10,alwai:1,among:4,ani:[1,4],api:[3,13],appear:10,append:[1,10],appli:1,applic:14,arena:1,arg0:1,arg1:1,arg:[1,9],argument:1,arrai:[1,3,4,6,9,10],array_equ:1,associ:1,assum:1,astyp:[6,10,14],auto_exampl:11,auto_examples_jupyt:2,auto_examples_python:2,avail:6,ave:10,averag:10,axesimag:8,back:1,backend:[2,11],bad:4,basic:1,batch:[10,14],becaus:[1,5],befor:[8,9],being:1,below:1,better:10,between:[1,3,10],bind:1,bind_cpu_input:1,bind_input:1,bind_ortvalue_input:1,bind_ortvalue_output:1,bind_output:1,blue:10,boston:5,both:1,bound:1,briefli:14,buffer_ptr:1,build:1,call:[1,5],can:[1,3,4,9,14],cannot:4,capi:[1,3,4,5],cat:9,chang:[1,14],change_ir_vers:9,check:1,chenta:8,choos:1,chosen:1,click:[3,4,5,6,7,8,9,10],clr:[10,14],code:[1,2,3,4,5,6,7,8,9,10,14],com:0,common:[2,5,10,11,14],commonli:14,compar:[5,10],comparison:[1,10],compat:1,compil:[1,3],compos:14,comput:[1,3,5,6,9,10,14],config:1,configur:1,conform:1,confus:[5,10],confusion_matrix:10,consist:[5,10],consum:1,contain:[1,7,9],content:8,converg:10,convergencewarn:10,convert:[2,7,8,11],convert_sklearn:[5,10,14],copi:1,copy_outputs_to_cpu:1,correspond:1,could:5,cpu:[1,3,14],creat:[1,5,14],creation:1,cuda:1,current:1,curv:10,custom:1,custom_metadata_map:[1,7],data:[1,4,5,10,14],data_ptr:1,data_typ:[1,5,8,10,14],datafram:[5,10],dataset:[3,4,5,6,7,8,9,10,14],datset:[5,10],debug:1,def:[9,10],defin:[1,14],definit:[1,6],demonstr:[5,6,8,10],denot:1,depend:[1,3,14],deploi:7,describ:14,descript:[1,7],detail:14,determinist:1,devic:3,device_id:1,device_nam:1,device_typ:1,dictionari:[1,5],dictionarytyp:5,dictvector:5,differ:[8,10],dim:8,dim_valu:8,dimens:[1,3,4],directli:[1,3],discrep:5,discuss:1,displai:8,doc_str:7,docstr:8,document:[1,10],doe:[4,9],domain:[1,7,8],don:1,dot:8,doubl:[4,5],download:[1,2,3,4,5,6,7,8,9,10],draw:[2,11],dtype:[3,4,6,9],due:4,dur:9,dynam:1,each:1,easi:14,easier:3,either:[3,4],elem_typ:8,element_typ:1,enabl:[1,9],enable_cpu_mem_arena:1,enable_mem_pattern:1,enable_profil:[1,9],end:[1,5,10],end_profil:9,engin:[0,13],ensembl:[5,10],entri:1,error:[1,2,11],etc:1,everi:10,exampl:[3,4,5,6,7,8,9,10,13],example1:[6,8,9],example2:4,except:[3,4,5],exchang:[0,13],execut:[1,2,10,11],execution_mod:1,execution_ord:1,exit:1,expect:[3,4,5],experi:10,explain:5,expos:1,extend:3,extra_warning_msg:10,facilit:1,fail:[4,5,10],fals:[1,5],famou:14,fatal:1,favorit:4,fct:10,featur:1,feature_extract:5,feed:[1,4],fetch:1,few:1,fid:8,file:[1,9,11],filenam:[1,9],first:[4,5,10,14],fit:[5,10,14],fix:[3,4],float32:[1,3,4,6,9,10,14],float64:4,float_data:8,float_input:[3,4,5,10,14],floattensortyp:[5,10,14],focus:[0,13],follow:[1,3,4],forest:10,format:[1,3,4,7,9],framework:[3,4],free:1,from:[1,3,4,5,6,7,8,9,10,14],full:[3,4,5,6,7,8,9,10],futur:1,galleri:[3,4,5,6,7,8,9,10,13],gener:[1,2,3,4,5,6,7,8,9,10],get:[1,10,14],get_devic:[1,3],get_exampl:[1,3,4,6,7,8,9],get_input:[4,5,6,9,10,14],get_modelmeta:7,get_output:[1,4,5,6,10,14],get_session_config_entri:1,getopnodeproduc:8,getpydotgraph:8,github:[0,6,13],given:1,global:10,goe:4,got:[3,4],gpu:[1,3,14],gracefulli:1,gradientboostingregressor:5,graph:[1,8],graph_descript:1,graph_nam:[1,7],graph_optimization_level:1,green:10,handl:4,has:[1,10],here:[1,3,4,5,6,7,8,9,10,14],high:14,higher:4,hold:1,host:1,how:[3,6,7,8,9,10],html:10,http:[0,10],ident:10,identifi:1,imag:8,implement:[1,3],imread:8,imshow:8,includ:[1,8],increas:10,index:[3,4],indic:[1,3,4],individu:1,inferenc:1,inferencesess:[1,4,5,6,7,9,10,14],info:1,inform:[0,1,13],initi:[1,8],initial_typ:[5,10,14],inp:5,input:[1,3,4,5,6,8,10],input_nam:[4,6,9,10,14],input_shap:6,input_typ:6,insensit:1,inst:10,instal:1,instanc:[1,7],instead:[4,5],int64:[4,5],int64tensortyp:5,inter_op_num_thread:1,interest:1,interpret:9,intra_op_num_thread:1,introduc:1,invalid:[3,4],invalid_argu:[3,4,5],invalidargu:[3,4,5],invoc:1,io_bind:1,ipynb:[3,4,5,6,7,8,9,10],ir_vers:[7,8,9],iri:[4,10,14],is_compat:1,is_tensor:1,issu:1,iter:10,its:[1,5,6,8,10,14],json:9,jupyt:[2,3,4,5,6,7,8,9,10],keep:7,kei:1,kernel:1,kind:4,kwarg:1,label:[3,4,10],label_nam:[10,14],lbfg:10,learn:[5,6,7,10,14],legend:10,len:10,let:[1,3,6,7,9,10],level:[1,14],lib:10,libari:1,librari:1,limit:10,linear_model:[10,14],list:[1,14],load:[2,3,4,5,7,8,9,10,11],load_boston:5,load_iri:[10,14],log:1,log_severity_level:1,log_verbosity_level:1,logger:1,logi:10,logid:1,logist:[3,4,7],logisticregress:[10,14],logreg_iri:[3,4,7,10,14],look:[4,5,8,10],loop:10,machin:[6,10,14],mai:1,main:1,make:3,make_pipelin:5,map:[1,5],math:1,matplotlib:[8,10],matrix:[5,10],max:10,max_it:10,mean:1,measur:10,memori:1,messag:8,meta:7,metadata:[1,2,11],metadata_prop:7,metric:[5,10],microsoft:0,min:10,miniconda:10,minut:[3,4,5,6,7,8,9,10],misspel:4,mkl:1,mode:1,model:[0,2,3,4,5,7,10,11,13],model_loading_arrai:9,model_select:[5,10,14],model_vers:7,modelmetadata:1,modelproto:[1,8],modul:[5,10],more:[0,13,14],most:8,mul:8,mul_1:[8,9],multipl:[3,4],n_estim:10,n_tree:10,name:[1,3,4,5,6,8,9,10,14],nativ:1,necessarili:4,need:[1,9,10],net_draw:8,network:[0,13],neural:[0,13],nfor:10,node:[1,8],node_produc:8,nodearg:1,none:[1,4,5,9,10,14],note:0,notebook:[2,3,4,5,6,7,8,9,10],nrow:10,number:[1,4,10],numpi:[1,3,4,5,6,9,10,14],object:[1,8,10],observ:5,one:[1,5,8,10,14],ones:5,onli:[1,4],only_execute_path_to_fetch:1,onnx:[1,2,4,7,9,11],onnx_model:9,onnx_model_str:9,onnxml:7,onnxmltool:[7,14],onnxruntim:[0,1,2,3,5,6,7,8,9,10,11,13,14],onnxruntime_profile__2021:9,onnxruntime_pybind11_st:[1,3,4,5],onnxruntimeerror:[3,4,5],onx:[5,10,14],op_typ:8,open:[0,5,8,9,10,13,14],oper:14,oppos:10,opset:9,opset_import:[8,9],opt:10,optim:[1,14],optimized_model_filepath:1,option:[1,4,9,10],order:1,org:10,ort:1,ort_output:1,ortvalue_from_numpi:1,ortvalue_from_shape_and_typ:1,other:[1,3,4,8,10,14],out:[3,4,5,6,7,8,9,10],output:[1,4,5,6,8,10,14],output_label:10,output_nam:[4,6],output_shap:6,output_typ:6,over:1,packag:[1,3,8,10],pair:1,panda:[5,10],parallel:1,paramet:1,parsefromstr:8,part:1,particular:1,particularli:1,path:1,path_or_byt:1,pattern:1,perfectli:10,perform:[0,1,13,14],pid:9,pipe:5,pipelin:[2,11,14],pipeline_vector:5,place:1,pleas:[0,3,4,10,13],plot:10,plot_backend:[3,11],plot_common_error:[4,11],plot_convert_pipeline_vector:[5,11],plot_load_and_predict:[6,11],plot_metadata:[7,11],plot_pipelin:[8,11],plot_profil:[9,11],plot_train_convert_predict:[10,11],plt:8,png:8,pprint:[9,10],pre:1,pred:[5,10],pred_onx:[5,10,14],predict:[1,2,3,4,9,11,14],predict_proba:10,prefix:1,prepar:[1,3],preprocess:10,print:[3,4,5,6,7,8,9,10,14],prob_nam:10,prob_rt:10,prob_sklearn:10,proba:3,probabili:10,probabl:[3,4],produc:[1,4,7],producer_nam:[1,7,8],producer_vers:7,product:7,prof_fil:9,profil:[1,2,11],profile_file_prefix:1,project:[0,13],properti:1,protobuf:8,provid:[1,14],provider_opt:1,put:1,pydot_graph:8,pyplot:8,python3:10,python:[1,2,3,4,5,6,7,8,9,10],r2_score:5,rais:4,random:[6,10],randomforestclassifi:10,rang:10,rank:4,rankdir:8,rather:14,raw:10,reach:10,read:[1,8],readi:1,refer:10,register_custom_ops_librari:1,regress:[3,4,7],regular:[1,5],relat:7,releas:0,relev:10,rep:3,repeat:10,replac:4,request:1,requir:1,res:[1,4,6,9],result:9,retriev:[1,5,6,10],rf_iri:10,rf_iris_:10,roc:10,row:5,run:[3,4,5,6,7,8,9,10],run_log_severity_level:1,run_with_iobind:1,runopt:1,runtim:[1,2,7,9,11],runtimeerror:[3,4,5],same:[3,4,10],save:[1,10],save_model_format:1,scale:10,scenario:[1,5,10,14],scikit:[5,7,10,14],score:[0,13],script:[3,4,5,6,7,8,9,10],second:[3,4,5,6,7,8,9,10],see:[0,1,6,7,9,10,13,14],self:1,seq:5,sequenc:1,sequencetyp:5,sequenti:1,serial:1,serializetostr:[5,9,10,14],servic:14,ses:1,sess:[1,4,5,6,7,9,10,14],sess_opt:1,sess_predict:10,sess_predict_proba:10,sess_predict_proba_loop:10,sess_predict_proba_rf:10,sess_profil:9,sess_tim:9,session:[1,9],session_initi:9,session_log_severity_level:1,sessionopt:[1,9],set:[1,5,10,14],set_titl:10,set_xlabel:10,set_ylabel:10,sever:[1,4],shape:[1,4,5,6,8,10],share:1,show:[1,5,6,9,10],shown:10,sigmoid:6,similar:[5,10],simpl:[2,3,7,8,11],singl:[1,4],site:[10,14],situat:4,size:1,skl2onnx:[5,10,14],sklearn:[5,7,10,14],small:5,snippet:1,solver:10,some:9,sourc:[1,2,3,4,5,6,7,8,9,10],spars:5,specif:[1,7,14],specifi:[1,14],speed:10,sphinx:[2,3,4,5,6,7,8,9,10],stabl:10,start:[4,5,10],statu:[1,10],step:[4,5,10],stop:10,store:[1,8,9],str:1,string:1,structur:1,suit:1,sum:10,summari:13,support:[1,9],supports_devic:1,system:8,tag:0,take:[4,5],target:[5,10,14],tensor:[1,4,5,6],tensor_typ:8,termin:1,test:[1,5,8,10],test_sigmoid:6,than:[1,4,8,14],thei:1,them:[5,10],thi:[1,3,4,5,6,8,9,10,14],thread:1,three:4,thu:1,tid:9,time:[1,3,4,5,6,7,8,9,10],timeit:10,timer:10,to_dict:5,tool:[8,14],topolog:1,total:[3,4,5,6,7,8,9,10,11],tpng:8,track:7,train:[2,4,7,11],train_test_split:[5,10,14],tree:10,trt:10,tsk:10,tutori:13,type:[1,4,5,6,8],unexpect:[4,5],unless:1,unus:1,usabl:1,usag:1,use:[1,3,5,8,10,14],use_deterministic_comput:1,used:[1,7,14],useful:[1,7],user:1,uses:5,using:[1,3,4],usual:[1,14],valu:[1,5],variabl:5,vector:[4,5,6],verbos:1,veri:[2,5,9,11],verif:1,version:[1,7,8,9],vlog:1,wai:[8,14],want:1,warn:[1,4],webservic:10,what:[9,10],when:7,whether:1,which:[1,4,5,7,8,14],within:1,without:[3,14],work:1,wrap:1,write:[5,10,14],write_dot:8,x_ortvalu:1,x_test:[5,10,14],x_test_dict:5,x_train:[5,10,14],x_train_dict:5,y_ortvalu:1,y_test:[5,10,14],y_train:[5,10,14],you:[1,14],your:4,zip:2},titles:["ONNX Runtime","API Summary","Gallery of examples","ONNX Runtime Backend for ONNX","Common errors with onnxruntime","Train, convert and predict with ONNX Runtime","Load and predict with ONNX Runtime and a very simple model","Metadata","Draw a pipeline","Profile the execution of a simple model","Train, convert and predict with ONNX Runtime","Computation times","Gallery of examples","Python Bindings for ONNX Runtime","Tutorial"],titleterms:{"export":14,api:1,backend:[1,3],benchmark:10,bind:13,chang:0,common:4,comput:11,convers:[5,10],convert:[5,10,14],dataset:1,devic:1,draw:8,error:4,exampl:[1,2],execut:9,favorit:14,format:[5,8,10,14],framework:14,galleri:2,iobind:1,json:8,load:[1,6,14],logist:10,metadata:7,model:[1,6,8,9,14],onnx:[0,3,5,6,8,10,13,14],onnxruntim:4,ortvalu:1,pipelin:[5,8],predict:[5,6,10],probabl:10,profil:9,python:13,randomforest:10,regress:10,retriev:8,run:[1,14],runtim:[0,3,5,6,10,13,14],simpl:[6,9],step:14,summari:1,time:11,train:[5,10,14],tutori:14,using:14,veri:6,your:14}}) \ No newline at end of file +Search.setIndex({docnames:["api_summary","auto_examples/index","auto_examples/plot_backend","auto_examples/plot_common_errors","auto_examples/plot_convert_pipeline_vectorizer","auto_examples/plot_load_and_predict","auto_examples/plot_metadata","auto_examples/plot_pipeline","auto_examples/plot_profiling","auto_examples/plot_train_convert_predict","auto_examples/sg_execution_times","examples_md","index","tutorial"],envversion:{"sphinx.domains.c":2,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":4,"sphinx.domains.index":1,"sphinx.domains.javascript":2,"sphinx.domains.math":2,"sphinx.domains.python":3,"sphinx.domains.rst":2,"sphinx.domains.std":2,"sphinx.ext.intersphinx":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["api_summary.rst","auto_examples/index.rst","auto_examples/plot_backend.rst","auto_examples/plot_common_errors.rst","auto_examples/plot_convert_pipeline_vectorizer.rst","auto_examples/plot_load_and_predict.rst","auto_examples/plot_metadata.rst","auto_examples/plot_pipeline.rst","auto_examples/plot_profiling.rst","auto_examples/plot_train_convert_predict.rst","auto_examples/sg_execution_times.rst","examples_md.rst","index.rst","tutorial.rst"],objects:{"onnxruntime.IOBinding":[[0,1,1,"","bind_cpu_input"],[0,1,1,"","bind_input"],[0,1,1,"","bind_ortvalue_input"],[0,1,1,"","bind_ortvalue_output"],[0,1,1,"","bind_output"],[0,1,1,"","copy_outputs_to_cpu"],[0,1,1,"","get_outputs"]],"onnxruntime.InferenceSession":[[0,1,1,"","disable_fallback"],[0,1,1,"","enable_fallback"],[0,1,1,"","end_profiling"],[0,1,1,"","get_inputs"],[0,1,1,"","get_modelmeta"],[0,1,1,"","get_outputs"],[0,1,1,"","get_overridable_initializers"],[0,1,1,"","get_profiling_start_time_ns"],[0,1,1,"","get_provider_options"],[0,1,1,"","get_providers"],[0,1,1,"","get_session_options"],[0,1,1,"","io_binding"],[0,1,1,"","run"],[0,1,1,"","run_with_iobinding"],[0,1,1,"","run_with_ort_values"],[0,1,1,"","set_providers"]],"onnxruntime.ModelMetadata":[[0,2,1,"","custom_metadata_map"],[0,2,1,"","description"],[0,2,1,"","domain"],[0,2,1,"","graph_description"],[0,2,1,"","graph_name"],[0,2,1,"","producer_name"],[0,2,1,"","version"]],"onnxruntime.NodeArg":[[0,2,1,"","name"],[0,2,1,"","shape"],[0,2,1,"","type"]],"onnxruntime.OrtValue":[[0,1,1,"","as_sparse_tensor"],[0,1,1,"","data_ptr"],[0,1,1,"","data_type"],[0,1,1,"","device_name"],[0,1,1,"","has_value"],[0,1,1,"","is_sparse_tensor"],[0,1,1,"","is_tensor"],[0,1,1,"","is_tensor_sequence"],[0,1,1,"","numpy"],[0,1,1,"","ort_value_from_sparse_tensor"],[0,1,1,"","ortvalue_from_numpy"],[0,1,1,"","ortvalue_from_shape_and_type"],[0,1,1,"","shape"]],"onnxruntime.RunOptions":[[0,2,1,"","log_severity_level"],[0,2,1,"","log_verbosity_level"],[0,2,1,"","logid"],[0,2,1,"","only_execute_path_to_fetches"],[0,2,1,"","terminate"]],"onnxruntime.SessionOptions":[[0,1,1,"","add_free_dimension_override_by_denotation"],[0,1,1,"","add_free_dimension_override_by_name"],[0,1,1,"","add_initializer"],[0,1,1,"","add_session_config_entry"],[0,2,1,"","enable_cpu_mem_arena"],[0,2,1,"","enable_mem_pattern"],[0,2,1,"","enable_mem_reuse"],[0,2,1,"","enable_profiling"],[0,2,1,"","execution_mode"],[0,2,1,"","execution_order"],[0,1,1,"","get_session_config_entry"],[0,2,1,"","graph_optimization_level"],[0,2,1,"","inter_op_num_threads"],[0,2,1,"","intra_op_num_threads"],[0,2,1,"","log_severity_level"],[0,2,1,"","log_verbosity_level"],[0,2,1,"","logid"],[0,2,1,"","optimized_model_filepath"],[0,2,1,"","profile_file_prefix"],[0,1,1,"","register_custom_ops_library"],[0,2,1,"","use_deterministic_compute"]],"onnxruntime.SparseTensor":[[0,1,1,"","as_blocksparse_view"],[0,1,1,"","as_coo_view"],[0,1,1,"","as_csrc_view"],[0,1,1,"","data_type"],[0,1,1,"","dense_shape"],[0,1,1,"","device_name"],[0,1,1,"","format"],[0,1,1,"","sparse_coo_from_numpy"],[0,1,1,"","sparse_csr_from_numpy"],[0,1,1,"","to_cuda"],[0,1,1,"","values"]],"onnxruntime.backend":[[0,3,1,"","is_compatible"],[0,3,1,"","prepare"],[0,3,1,"","run"],[0,3,1,"","supports_device"]],"onnxruntime.datasets":[[0,3,1,"","get_example"]],onnxruntime:[[0,0,1,"","IOBinding"],[0,0,1,"","InferenceSession"],[0,0,1,"","ModelMetadata"],[0,0,1,"","NodeArg"],[0,0,1,"","OrtDevice"],[0,0,1,"","OrtValue"],[0,0,1,"","RunOptions"],[0,0,1,"","SessionOptions"],[0,0,1,"","SparseTensor"],[0,3,1,"","get_device"]]},objnames:{"0":["py","class","Python class"],"1":["py","method","Python method"],"2":["py","property","Python property"],"3":["py","function","Python function"]},objtypes:{"0":"py:class","1":"py:method","2":"py:property","3":"py:function"},terms:{"0":[0,2,3,4,5,6,7,8,9,10,13],"00":10,"0002686927327886224":3,"000857":9,"000869":9,"000873":9,"000874":9,"000876":9,"000881":9,"0008813192099997735":9,"000883":9,"0008830492349999729":9,"000884":9,"000885":9,"000895":9,"000899":9,"000907":9,"00091":9,"000912":9,"000913":9,"000914":9,"000915":9,"000916":9,"000921":9,"000922":9,"000928":9,"000934":9,"00094":9,"000941":9,"000948":9,"000966":9,"000967":9,"000972":9,"000977":9,"000983":9,"000992":9,"00101":9,"00107":9,"00108":9,"0010817126199989956":9,"00111":9,"0024466365575790405":3,"00402":9,"00404":9,"00409":9,"005":[6,10],"00597":9,"00599":9,"00606":9,"007":[8,10],"009":[3,10],"01":[8,9],"0116":6,"013":[5,10],"013000461272895336":9,"014":[2,10],"02":9,"021566055715084076":3,"027834143489599228":3,"03":10,"03678159e":9,"03936365991830826":9,"04_17":8,"05":[3,9],"05698008090257645":9,"0636":9,"0637":9,"0639":9,"07":3,"07e":9,"09":8,"098":9,"0982":9,"0987":9,"0x7feaf2025c10":9,"0x7feafe274ac0":7,"1":[0,2,3,4,6,7,8,9],"10":9,"100":9,"100n":0,"11":8,"13":9,"133":9,"14":9,"15":9,"159":[9,10],"16":8,"167":9,"168":9,"1833212822675705":9,"196":[7,10],"2":[0,2,3,4,6,7,8,9],"20":9,"201":9,"202":9,"203":9,"22":[4,9,10],"23":10,"236":9,"237":9,"240":8,"25":[8,9],"25e":9,"271":9,"3":[0,2,3,5,6,7,8,9],"30":9,"30004554e":9,"305":9,"3089":8,"339":9,"34":9,"35":9,"36":8,"370":10,"374":9,"375":9,"38e":9,"3c59201b940f410fa29dc71ea9d5767d":6,"3g":9,"4":[0,3,5,7,8,9,13],"40":9,"42990368e":9,"45":9,"46e":9,"5":[0,3,5,7,8,9],"50":9,"5047166":5,"5055595":5,"50677085":5,"5097179":5,"51":9,"5178277":5,"5184905":5,"52279866":5,"5249817":5,"525905":5,"5320551":5,"53635114":5,"5369593":5,"5392329":5,"5398089":5,"54673976":5,"548968":5,"55":8,"550723":5,"5522731":5,"55390376":5,"5549751":5,"56":8,"5622808":5,"5627599":5,"56360227":5,"5688669":5,"56964463":5,"5735331":5,"5743989":5,"5819309":5,"5826889":5,"5833795":5,"5842683":5,"58536506":5,"59407187":5,"59544575":5,"6":[3,7,8,9],"60552883":5,"60617851e":9,"60848683":5,"6108959":5,"62443805":5,"6270167988259345e":3,"6312441":5,"6324704":5,"63349843":5,"63380575":5,"6382853":5,"63900065":5,"63964766":5,"6423601":5,"64378905":5,"65169865":5,"65232253":5,"6620137":5,"6746977":5,"68858314":5,"69634616":5,"69650024":5,"69800366e":9,"7":[7,8],"708999":5,"71":8,"71247685":5,"715":9,"7161434":5,"717":9,"72":9,"7210646":5,"7223234":5,"7300966":5,"787709464906584e":3,"8":[4,9],"8036782741546631":9,"83321386e":9,"8492364688427188e":9,"84923705e":9,"87":4,"9":[8,9],"9209977605173356":4,"92e":9,"93636566e":9,"9429903030395508":9,"9505997896194458":3,"95951945e":9,"9595235901069827e":9,"9606178402900696":9,"966":[4,10],"9671264999914226e":9,"97e":9,"9974970817565918":3,"9997311234474182":3,"9999999999999366":4,"boolean":0,"byte":[0,3],"case":[0,4,9],"class":3,"default":0,"do":[4,6,9],"float":[0,3,4,5],"function":[0,4],"import":[2,3,4,5,6,7,8,9,13],"int":[0,4],"new":0,"public":0,"return":[0,3,8,9],"static":0,"switch":2,"throw":0,"true":[0,4,8,9],"try":[2,3,4],"while":0,A:0,And:9,At:13,But:4,By:0,For:[0,12],If:0,In:[0,4,13],It:[0,3,5,6,13],Its:0,NOT:0,No:0,On:0,That:7,The:[0,2,3,4,5,8,9,13],Then:[7,9],There:[7,13],These:0,To:0,With:6,about:[0,4],absolut:0,access:0,accessor:0,across:0,actual:[0,3,4],add_free_dimension_override_by_denot:0,add_free_dimension_override_by_nam:0,add_initi:0,add_session_config_entri:0,addit:0,address:0,after:0,aka:12,all:[0,1,3],alloc:0,allow:0,alreadi:0,also:[0,2,5],altern:4,alwai:0,am:4,among:3,an:[0,3,4,5,7,9,13],ani:[0,3],anoth:0,api:[2,12],appear:9,append:[0,9],appli:0,applic:13,ar:[0,8,9,13],arena:0,arg0:0,arg1:0,arg:[0,8],argument:0,arr_on_cpu:0,arrai:[0,2,3,5,8,9],array_equ:0,as_blocksparse_view:0,as_coo_view:0,as_csrc_view:0,as_fram:4,as_sparse_tensor:0,associ:0,assum:0,astyp:[5,9,13],auto_exampl:10,auto_examples_jupyt:1,auto_examples_python:1,av:9,avail:[0,5],averag:9,ax:9,axesimag:7,back:0,backend:[1,10],bad:3,basic:0,batch:[9,13],becaus:[0,4],befor:[7,8],being:0,below:0,better:9,between:[0,2,9],bind:0,bind_cpu_input:0,bind_input:0,bind_ortvalue_input:0,bind_ortvalue_output:0,bind_output:0,block_sparse_indic:0,blockspars:0,blue:9,boston:4,both:0,bound:0,briefli:13,buffer:0,buffer_ptr:0,build:0,c:[0,9],c_ort_devic:0,california:4,call:[0,4],can:[0,2,3,4,8,13],cannot:[0,3],capabl:0,capi:[0,2,3,4],cat:8,categori:4,chang:[0,13],change_ir_vers:8,check:0,chenta:7,choos:0,chosen:0,click:[2,3,4,5,6,7,8,9],clr:[9,13],cmu:4,code:[0,1,2,3,4,5,6,7,8,9,13],col:0,common:[1,4,9,10,13],commonli:13,compar:[0,4,9],comparison:[0,9],compat:0,compil:[0,2],compos:13,comput:[0,2,4,5,8,9,13],config:0,configur:0,conform:0,confus:[4,9],confusion_matrix:9,consist:[4,9],construct:0,constructor:0,consum:0,contain:[0,6,8],content:[0,7],contigu:0,convert:[1,6,7,10],convert_sklearn:[4,9,13],coo:0,coo_indic:0,coordin:0,copi:0,copy_outputs_to_cpu:0,correspond:0,could:4,count:0,cpu:[0,2,13],cpuexecutionprovid:0,cr:0,creat:[0,4,13],creation:0,cross:0,csr:0,cuda:0,cudaexecutionprovid:0,current:0,curv:9,custom:0,custom_metadata_map:[0,6],d:[0,9],data:[3,4,9,13],data_ptr:0,data_typ:[0,4,7,9,13],data_url:4,datafram:[4,9],dataset:[2,3,4,5,6,7,8,9,13],datset:[4,9],deal:0,debug:0,decreas:0,decrement:0,def:[8,9],defin:[0,13],definit:[0,5],demonstr:[4,5,7,9],denot:0,dens:0,dense_shap:0,depend:[0,2,13],deploi:6,deprec:4,describ:[0,13],descript:[0,6],detail:[4,13],determinist:0,devic:2,device_id:0,device_nam:0,device_typ:0,df:9,dict:0,dictionari:[0,4],dictionarytyp:4,dictvector:4,did:0,differ:[7,9],dim:7,dim_valu:7,dimens:[0,2,3],directli:[0,2],disabl:0,disable_fallback:0,discourag:4,discrep:4,discuss:0,displai:7,dit:0,doc_str:6,docstr:7,document:[0,4],doe:[0,3,8],domain:[0,6,7],don:0,dot:7,doubl:[3,4],download:[0,1,2,3,4,5,6,7,8,9],draw:[1,10],dtype:[2,3,5,8],due:[0,3],dur:8,dynam:0,e:[0,2,3,4],each:0,easi:13,easier:2,edu:4,educ:4,either:[0,2,3],elem_typ:7,element:0,element_typ:0,els:0,enabl:[0,8],enable_cpu_mem_arena:0,enable_fallback:0,enable_mem_pattern:0,enable_mem_reus:0,enable_profil:[0,8],end:[0,4,9],end_profil:[0,8],engin:12,ensembl:[4,9],entri:0,enumer:0,equal:0,error:[0,1,10],etc:0,ethic:4,everi:9,ex:0,exactli:0,exampl:[2,3,4,5,6,7,8,9,12],example1:[5,7,8],example2:3,except:[2,3,4],exchang:12,execut:[0,1,9,10],execution_mod:0,execution_ord:0,exit:0,expect:[2,3,4],experi:9,explain:4,explicitli:0,expos:0,extend:2,extens:0,f:[4,8,9,13],facilit:0,factori:0,fail:[0,3,4],failur:0,fall:0,fallback:0,fals:[0,4],famou:13,fatal:0,favorit:3,fct:9,featur:0,feature_extract:4,feed:[0,3],fetch:[0,4],fetch_california_h:4,fetch_openml:4,few:0,fid:7,file:[0,8,10],filenam:[0,8],first:[0,3,4,9,13],fit:[4,9,13],fix:[2,3],float32:[0,2,3,5,8,9,13],float64:3,float_data:7,float_input:[2,3,4,9,13],floattensortyp:[4,9,13],focus:12,follow:[0,2,3,4],forest:9,format:[0,2,3,6,8],framework:[2,3],free:0,from:[0,2,3,4,5,6,7,8,9,13],full:[2,3,4,5,6,7,8,9],func:4,further:4,futur:0,futurewarn:4,g:0,gain:0,galleri:[2,3,4,5,6,7,8,9,12],gc:0,gced:0,gener:[0,1,2,3,4,5,6,7,8,9],get:[0,9,13],get_available_provid:[3,4,5,6,8,9,13],get_devic:[0,2],get_exampl:[0,2,3,5,6,7,8],get_input:[0,3,4,5,8,9,13],get_modelmeta:[0,6],get_output:[0,3,4,5,9,13],get_overridable_initi:0,get_profiling_start_time_n:0,get_provid:0,get_provider_opt:0,get_session_config_entri:0,get_session_opt:0,getopnodeproduc:7,getpydotgraph:7,github:[5,12],given:0,global:9,goe:3,got:[2,3],gpu:[0,2,13],gracefulli:0,gradientboostingregressor:4,graph:[0,7],graph_descript:0,graph_nam:[0,6],graph_optimization_level:0,green:9,ha:[0,4,9],handl:3,has_valu:0,have:0,header:4,held:0,here:[0,2,3,4,5,6,7,8,9,13],high:13,higher:3,hold:0,home:4,homogen:0,host:0,hous:4,house_pric:4,how:[0,2,5,6,7,8,9],hstack:4,http:4,i:[4,9],id:0,ident:9,identifi:0,im:9,imag:7,implement:[0,2],imread:7,imshow:7,includ:[0,4,7],increment:0,index:[0,2,3],indic:[0,2,3],individu:0,infer:0,inferenc:0,inferencesess:[0,3,4,5,6,8,9,13],info:0,inform:[0,12],initi:[0,7],initial_typ:[4,9,13],inner:0,inner_indic:0,inner_ndic:0,inp:4,input:[0,2,3,4,5,7,9],input_dict_ort_valu:0,input_fe:0,input_nam:[0,3,5,8,9,13],input_ort_valu:0,input_shap:5,input_typ:5,input_valu:0,insensit:0,inst:9,instal:0,instanc:[0,6],instanti:0,instead:[3,4],int64:[0,3,4],int64tensortyp:4,integ:0,inter_op_num_thread:0,interest:0,interpret:8,intra_op_num_thread:0,introduc:0,invalid:[2,3],invalid_argu:[2,3,4],invalidargu:[2,3,4],invoc:0,io:0,io_bind:0,ipynb:[2,3,4,5,6,7,8,9],ir_vers:[6,7,8],iri:[3,9,13],is_compat:0,is_sparse_tensor:0,is_tensor:0,is_tensor_sequ:0,issu:[0,4],its:[0,4,5,7,9,13],json:8,jupyt:[1,2,3,4,5,6,7,8,9],keep:6,kei:0,kernel:0,kind:3,kwarg:0,label:[2,3,9],label_nam:[9,13],learn:[4,5,6,9,13],legend:9,len:9,length:0,let:[0,2,5,6,8,9],level:[0,13],lib:4,libari:0,librari:0,linear:0,linear_model:[9,13],list:[0,13],ll:13,load:[1,2,3,4,6,7,8,9,10],load_boston:4,load_iri:[9,13],load_model_format:0,local:4,log:0,log_severity_level:0,log_verbosity_level:0,logger:0,logi:9,logid:0,logist:[2,3,6],logisticregress:[9,13],logreg_iri:[2,3,6,9,13],look:[3,4,7,9],loop:9,lr:7,ma:9,machin:[4,5,9,13],maco:0,mai:0,maintain:4,make:2,make_pipelin:4,map:[0,4],math:0,matplotlib:[7,9],matrix:[4,9],max:9,mb:10,mean:0,measur:9,mechan:0,memori:0,messag:7,meta:6,metadata:[0,1,10],metadata_prop:6,method:0,metric:[4,9],mi:9,min:9,minut:[2,3,4,5,6,7,8,9],misspel:3,mkl:0,mode:0,model:[1,2,3,4,6,9,10,12],model_loading_arrai:8,model_select:[4,9,13],model_vers:6,modelproto:[0,7],modul:[4,9],monotonic_n:0,more:[0,12,13],most:7,ms:12,msg:4,mul:7,mul_1:[7,8],multipl:[2,3],must:0,n:9,n_estim:9,n_tree:9,name:[0,2,3,4,5,7,8,9,13],nanosecond:0,nativ:0,necessarili:3,need:[0,8,9],net_draw:7,network:12,neural:12,nfor:9,nnz:0,node:[0,7],node_produc:7,non:0,none:[0,3,4,8,9,13],notebook:[1,2,3,4,5,6,7,8,9],np:[0,2,4],nrow:9,number:[0,3,9],numer:0,nummpi:0,numpi:[0,2,3,4,5,8,9,13],numpy_obj:0,o:7,object:[0,7,9],observ:4,obtain:0,one:[0,4,7,9,13],ones:4,onli:[0,3],only_execute_path_to_fetch:0,onnx:[0,1,3,6,8,10],onnx_model:8,onnx_model_str:8,onnxml:6,onnxmltool:[6,13],onnxruntim:[0,1,2,4,5,6,7,8,9,10,12,13],onnxruntime_profile__2022:8,onnxruntime_pybind11_st:[0,2,3,4],onnxruntimeerror:[2,3,4],onx:[4,9,13],op:0,op_typ:7,open:[4,7,8,9,12,13],oper:13,oppos:9,opset:8,opset_import:[7,8],optim:[0,13],optimized_model_filepath:0,option:[3,8],order:0,origin:4,ort:0,ort_devic:0,ort_output:0,ort_value_from_sparse_tensor:0,ortsparseformat:0,ortvalue_from_numpi:0,ortvalue_from_shape_and_typ:0,os:7,other:[0,2,3,7,9,13],otherwis:0,out:[2,3,4,5,6,7,8,9],outer:0,outer_indic:0,outer_ndic:0,output:[0,3,4,5,7,9,13],output_label:9,output_nam:[0,3,5],output_shap:5,output_typ:5,over:0,own:0,ownership:0,packag:[0,2,4,7],pair:0,panda:[4,9],parallel:0,param:0,paramet:0,parsefromstr:7,part:0,particular:0,particularli:0,path:0,path_or_byt:0,pattern:0,pd:4,perfectli:9,perform:[0,12,13],ph:8,pid:8,pipe:4,pipelin:[1,10,13],pipeline_vector:4,place:0,platform:0,pleas:[2,3,12],plot:9,plot_backend:[2,10],plot_common_error:[3,10],plot_convert_pipeline_vector:[4,10],plot_load_and_predict:[5,10],plot_metadata:[6,10],plot_pipelin:[7,10],plot_profil:[8,10],plot_train_convert_predict:[9,10],plt:7,png:7,pointer:0,pprint:[8,9],pre:0,preced:0,precis:0,pred:[4,9],pred_onx:[4,9,13],predict:[0,1,2,3,8,10,13],predict_proba:9,prefix:0,prepar:[0,2],present:0,price:4,primit:0,print:[2,3,4,5,6,7,8,9,13],prob_nam:9,prob_rt:9,prob_sklearn:9,proba:2,probabili:9,probabl:[2,3],problem:4,produc:[0,3,6],producer_nam:[0,6,7],producer_vers:6,product:6,prof_fil:8,profil:[0,1,10],profile_file_prefix:0,project:[0,12],properti:0,protobuf:7,provid:[0,3,4,5,6,8,9,13],provider_opt:0,purpos:4,put:0,py:[2,3,4,5,6,7,8,9,10],pydot_graph:7,pyplot:7,python3:4,python:[0,1,2,3,4,5,6,7,8,9],queri:0,r2_score:4,r:[3,8],rais:3,random:[5,9],randomforestclassifi:9,rang:9,rank:3,rankdir:7,rather:13,raw:9,raw_df:4,rb:[7,8],re:[0,3,5,8],read:[0,7],read_csv:4,readi:0,refer:[0,4],regist:0,register_custom_ops_librari:0,regress:[2,3,6],regular:[0,4],relat:6,relev:9,remov:4,rep:2,repeat:9,replac:3,represent:0,request:0,requir:0,reset:0,resid:0,result:[0,8],retriev:[0,4,5,9],reus:0,rf:9,rf_iri:9,rf_iris_:9,roc:9,row:[0,4],rt:[3,4,5,6,8,9,13],run:[2,3,4,5,6,7,8,9],run_log_severity_level:0,run_opt:0,run_with_iobind:0,run_with_ort_valu:0,runner:4,runtim:[0,1,6,8,10],runtimeerror:[2,3,4],s:[0,2,4,5,6,7,8,9],same:[2,3,9],save:[0,9],save_model_format:0,scenario:[0,4,9,13],scienc:4,scikit:[4,6,9,13],score:12,script:[2,3,4,5,6,7,8,9],se:0,second:[2,3,4,5,6,7,8,9],see:[0,5,6,8,9,12,13],self:0,sep:4,seq:4,sequenc:0,sequencetyp:4,sequenti:0,serial:0,serializetostr:[4,8,9,13],servic:13,sess:[0,3,4,5,6,8,9,13],sess_opt:0,sess_predict:9,sess_predict_proba:9,sess_predict_proba_loop:9,sess_predict_proba_rf:9,sess_profil:8,sess_tim:8,session:[0,8],session_initi:8,session_log_severity_level:0,sessionopt:8,set:[0,4,9,13],set_provid:0,set_titl:9,set_xlabel:9,set_ylabel:9,sever:[0,3],shape:[0,3,4,5,7,9],share:0,should:0,show:[0,4,5,8,9],sigmoid:5,similar:[4,9],simpl:[1,2,6,7,10],singl:[0,3],site:[4,13],situat:3,size:0,skiprow:4,skl2onnx:[4,9,13],sklearn:[4,6,9,13],small:4,snippet:0,so:0,some:[0,8],sourc:[0,1,2,3,4,5,6,7,8,9],spars:[0,4],sparse_coo_from_numpi:0,sparse_csr_from_numpi:0,sparse_tensor:0,special:4,specif:[0,6,13],specifi:[0,13],speed:9,sphinx:[1,2,3,4,5,6,7,8,9],start:[0,3,4,9],stat:4,statu:0,step:[3,4,9],storag:0,store:[0,7,8],str:0,string:0,strongli:4,structur:0,studi:4,suit:0,sum:9,summari:12,suppli:0,suppor:0,support:[0,8],supports_devic:0,system:7,t:[0,4],take:[3,4],target:[4,9,13],tensor:[0,3,4,5],tensor_typ:7,termin:0,test:[0,4,7,9],test_sigmoid:5,than:[0,3,7,13],thei:0,them:[0,4,9],therefor:4,thi:[0,2,3,4,5,7,8,9,13],those:0,thread:0,three:3,thu:0,tid:8,time:[0,2,3,4,5,6,7,8,9],timeit:9,timer:[0,9],to_cuda:0,to_dict:4,tool:[7,13],topolog:0,total:[2,3,4,5,6,7,8,9,10],tpng:7,track:6,train:[1,3,6,10],train_test_split:[4,9,13],tree:9,trt:9,ts:8,tsk:9,tupl:0,tutori:12,twice:0,type:[0,3,4,5,7],un:8,underli:0,unexpect:[3,4],unless:[0,4],unus:0,us:[0,2,3,4,6,7,9],usabl:0,usag:0,use_deterministic_comput:0,user:0,usual:[0,13],util:4,valid:0,valu:[0,4],variabl:4,vector:[3,4,5],verbos:0,veri:[1,4,8,10],verif:0,version:[0,6,7,8],vlog:0,w:7,wa:[2,6],wai:[7,13],want:0,warn:[0,3,4],wb:[4,9,13],we:[4,7,8,9,13],webservic:9,what:[8,9],when:[0,6],where:0,whether:0,which:[0,3,4,6,7,13],window:0,within:0,without:[2,13],work:0,would:0,wrap:0,write:[4,9,13],write_dot:7,x:[0,2,3,4,5,7,8,9,13],x_ortvalu:0,x_test:[4,9,13],x_test_dict:4,x_train:[4,9,13],x_train_dict:4,y:[0,4,5,7,9,13],y_ortvalu:0,y_test:[4,9,13],y_train:[4,9,13],you:[0,4,13],your:3,zero:0,zip:1},titles:["API Summary","Gallery of examples","ONNX Runtime Backend for ONNX","Common errors with onnxruntime","Train, convert and predict with ONNX Runtime","Load and predict with ONNX Runtime and a very simple model","Metadata","Draw a pipeline","Profile the execution of a simple model","Train, convert and predict with ONNX Runtime","Computation times","Gallery of examples","Python Bindings for ONNX Runtime","Tutorial"],titleterms:{"1":13,"2":13,"3":13,"class":0,"export":13,api:0,backend:[0,2],benchmark:9,bind:12,common:3,comput:10,convers:[4,9],convert:[4,9,13],data:0,dataset:0,devic:0,draw:7,error:3,exampl:[0,1],execut:8,favorit:13,format:[4,7,9,13],framework:13,galleri:1,intern:0,iobind:0,json:7,load:[0,5,13],logist:9,main:0,metadata:6,model:[0,5,7,8,13],modelmetadata:0,nodearg:0,onnx:[2,4,5,7,9,12,13],onnxruntim:3,option:0,ortdevic:0,ortvalu:0,pipelin:[4,7],predict:[4,5,9],probabl:9,profil:8,python:12,randomforest:9,regress:9,retriev:7,run:[0,13],runopt:0,runtim:[2,4,5,9,12,13],sessionopt:0,simpl:[5,8],sparsetensor:0,step:13,summari:0,time:10,train:[4,9,13],tutori:13,us:13,veri:5,your:13}}) \ No newline at end of file diff --git a/docs/api/python/sources/README.rst.txt b/docs/api/python/sources/README.rst.txt deleted file mode 100644 index 8d58e4bc0eab9..0000000000000 --- a/docs/api/python/sources/README.rst.txt +++ /dev/null @@ -1,75 +0,0 @@ -ONNX Runtime -============ - -ONNX Runtime is a performance-focused scoring engine for Open Neural Network Exchange (ONNX) models. -For more information on ONNX Runtime, please see `aka.ms/onnxruntime `_ or the `Github project `_. - - -Changes -------- - -1.7.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.7.0 - -1.6.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.6.0 - -1.5.3 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.5.3 - -1.5.2 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.5.2 - -1.5.1 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.5.1 - - -1.4.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.4.0 - -1.3.1 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.3.1 - -1.3.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.3.0 - -1.2.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.2.0 - -1.1.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.1.0 - -1.0.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v1.0.0 - -0.5.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v0.5.0 - -0.4.0 -^^^^^ - -Release Notes : https://github.com/Microsoft/onnxruntime/releases/tag/v0.4.0 diff --git a/docs/api/python/sources/api_summary.rst.txt b/docs/api/python/sources/api_summary.rst.txt index ce764dafce10d..0325cdd47fa97 100644 --- a/docs/api/python/sources/api_summary.rst.txt +++ b/docs/api/python/sources/api_summary.rst.txt @@ -11,6 +11,7 @@ in *ONNX Runtime*. OrtValue ========= + *ONNX Runtime* works with native Python data structures which are mapped into ONNX data formats : Numpy arrays (tensors), dictionaries (maps), and a list of Numpy arrays (sequences). The data backing these are on CPU. @@ -25,7 +26,7 @@ on a CUDA device: .. code-block:: python - #X is numpy array on cpu, create an OrtValue and place it on cuda device id = 0 + # X is numpy array on cpu, create an OrtValue and place it on cuda device id = 0 ortvalue = onnxruntime.OrtValue.ortvalue_from_numpy(X, 'cuda', 0) ortvalue.device_name() # 'cuda' ortvalue.shape() # shape of the numpy array X @@ -33,7 +34,7 @@ on a CUDA device: ortvalue.is_tensor() # 'True' np.array_equal(ortvalue.numpy(), X) # 'True' - #ortvalue can be provided as part of the input feed to a model + # ortvalue can be provided as part of the input feed to a model ses = onnxruntime.InferenceSession('model.onnx') res = sess.run(["Y"], {"X": ortvalue}) @@ -57,7 +58,7 @@ use IOBinding to put input on CUDA as the follows. .. code-block:: python - #X is numpy array on cpu + # X is numpy array on cpu session = onnxruntime.InferenceSession('model.onnx') io_binding = session.io_binding() # OnnxRuntime will copy the data over to the CUDA device if 'input' is consumed by nodes on the CUDA device @@ -72,7 +73,7 @@ The input data is on a device, users directly use the input. The output data is .. code-block:: python - #X is numpy array on cpu + # X is numpy array on cpu X_ortvalue = onnxruntime.OrtValue.ortvalue_from_numpy(X, 'cuda', 0) session = onnxruntime.InferenceSession('model.onnx') io_binding = session.io_binding() @@ -158,21 +159,76 @@ Load and run a model The main class *InferenceSession* wraps these functionalities in a single place. -.. autoclass:: onnxruntime.ModelMetadata - :members: +Main class +---------- .. autoclass:: onnxruntime.InferenceSession :members: + :inherited-members: -.. autoclass:: onnxruntime.NodeArg - :members: +Options +------- + +RunOptions +^^^^^^^^^^ .. autoclass:: onnxruntime.RunOptions :members: +SessionOptions +^^^^^^^^^^^^^^ + .. autoclass:: onnxruntime.SessionOptions :members: +Data +---- + +OrtValue +^^^^^^^^ + +.. autoclass:: onnxruntime.OrtValue + :members: + +SparseTensor +^^^^^^^^^^^^ + +.. autoclass:: onnxruntime.SparseTensor + :members: + +Devices +------- + +IOBinding +^^^^^^^^^ + +.. autoclass:: onnxruntime.IOBinding + :members: + +OrtDevice +^^^^^^^^^ + +.. autoclass:: onnxruntime.OrtDevice + :members: + +Internal classes +---------------- + +These classes cannot be instantiated by users but they are returned +by methods or functions of this libary. + +ModelMetadata +^^^^^^^^^^^^^ + +.. autoclass:: onnxruntime.ModelMetadata + :members: + +NodeArg +^^^^^^^ + +.. autoclass:: onnxruntime.NodeArg + :members: + Backend ======= diff --git a/docs/api/python/sources/auto_examples/plot_backend.rst.txt b/docs/api/python/sources/auto_examples/plot_backend.rst.txt index b2255d568439a..b273b7902120b 100644 --- a/docs/api/python/sources/auto_examples/plot_backend.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_backend.rst.txt @@ -29,7 +29,7 @@ to run predictions using this runtime. Let's use the API to compute the prediction of a simple logistic regression model. -.. GENERATED FROM PYTHON SOURCE LINES 17-35 +.. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: default @@ -39,46 +39,36 @@ of a simple logistic regression model. import onnxruntime.backend as backend from onnx import load - name = datasets.get_example("logreg_iris.onnx") - model = load(name) - - rep = backend.prepare(model, 'CPU') - x = np.array([[-1.0, -2.0]], dtype=np.float32) - try: - label, proba = rep.run(x) - print("label={}".format(label)) - print("probabilities={}".format(proba)) - except (RuntimeError, InvalidArgument) as e: - print(e) -.. rst-class:: sphx-glr-script-out - Out: - - .. code-block:: none - - [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: float_input for the following indices - index: 0 Got: 1 Expected: 3 - Please fix either the inputs or the model. - - - -.. GENERATED FROM PYTHON SOURCE LINES 36-38 +.. GENERATED FROM PYTHON SOURCE LINES 24-26 The device depends on how the package was compiled, GPU or CPU. -.. GENERATED FROM PYTHON SOURCE LINES 38-41 +.. GENERATED FROM PYTHON SOURCE LINES 26-41 .. code-block:: default from onnxruntime import get_device - print(get_device()) + device = get_device() + + name = datasets.get_example("logreg_iris.onnx") + model = load(name) + + rep = backend.prepare(model, device) + x = np.array([[-1.0, -2.0]], dtype=np.float32) + try: + label, proba = rep.run(x) + print("label={}".format(label)) + print("probabilities={}".format(proba)) + except (RuntimeError, InvalidArgument) as e: + print(e) @@ -90,7 +80,9 @@ GPU or CPU. .. code-block:: none - CPU + [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: float_input for the following indices + index: 0 Got: 1 Expected: 3 + Please fix either the inputs or the model. @@ -105,7 +97,7 @@ without using *onnx*. .. code-block:: default - rep = backend.prepare(name, 'CPU') + rep = backend.prepare(name, device) x = np.array([[-1.0, -2.0]], dtype=np.float32) try: label, proba = rep.run(x) @@ -140,7 +132,7 @@ with the same API. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 0.019 seconds) + **Total running time of the script:** ( 0 minutes 0.014 seconds) .. _sphx_glr_download_auto_examples_plot_backend.py: diff --git a/docs/api/python/sources/auto_examples/plot_common_errors.rst.txt b/docs/api/python/sources/auto_examples/plot_common_errors.rst.txt index bbe26555a3763..871563380fa54 100644 --- a/docs/api/python/sources/auto_examples/plot_common_errors.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_common_errors.rst.txt @@ -41,7 +41,7 @@ a vector of dimension 2 and returns a class among three. from onnxruntime.datasets import get_example example2 = get_example("logreg_iris.onnx") - sess = rt.InferenceSession(example2) + sess = rt.InferenceSession(example2, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name output_name = sess.get_outputs()[0].name @@ -302,7 +302,7 @@ is higher than expects but produces a warning. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 0.018 seconds) + **Total running time of the script:** ( 0 minutes 0.009 seconds) .. _sphx_glr_download_auto_examples_plot_common_errors.py: diff --git a/docs/api/python/sources/auto_examples/plot_convert_pipeline_vectorizer.rst.txt b/docs/api/python/sources/auto_examples/plot_convert_pipeline_vectorizer.rst.txt index 75c95d8f6449d..8aaf14206515b 100644 --- a/docs/api/python/sources/auto_examples/plot_convert_pipeline_vectorizer.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_convert_pipeline_vectorizer.rst.txt @@ -53,6 +53,49 @@ The first step consists in retrieving the boston datset. +.. rst-class:: sphx-glr-script-out + + Out: + + .. code-block:: none + + /home/runner/.local/lib/python3.8/site-packages/sklearn/utils/deprecation.py:87: FutureWarning: Function load_boston is deprecated; `load_boston` is deprecated in 1.0 and will be removed in 1.2. + + The Boston housing prices dataset has an ethical problem. You can refer to + the documentation of this function for further details. + + The scikit-learn maintainers therefore strongly discourage the use of this + dataset unless the purpose of the code is to study and educate about + ethical issues in data science and machine learning. + + In this special case, you can fetch the dataset from the original + source:: + + import pandas as pd + import numpy as np + + + data_url = "http://lib.stat.cmu.edu/datasets/boston" + raw_df = pd.read_csv(data_url, sep="\s+", skiprows=22, header=None) + data = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]]) + target = raw_df.values[1::2, 2] + + Alternative datasets include the California housing dataset (i.e. + :func:`~sklearn.datasets.fetch_california_housing`) and the Ames housing + dataset. You can load the datasets as follows:: + + from sklearn.datasets import fetch_california_housing + housing = fetch_california_housing() + + for the California housing dataset and:: + + from sklearn.datasets import fetch_openml + housing = fetch_openml(name="house_prices", as_frame=True) + + for the Ames housing dataset. + + warnings.warn(msg, category=FutureWarning) + @@ -114,7 +157,7 @@ and we show the confusion matrix. .. code-block:: none - 0.848444978558249 + 0.9209977605173356 @@ -161,7 +204,7 @@ its input and output. import onnxruntime as rt from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument - sess = rt.InferenceSession("pipeline_vectorize.onnx") + sess = rt.InferenceSession("pipeline_vectorize.onnx", providers=rt.get_available_providers()) import numpy inp, out = sess.get_inputs()[0], sess.get_outputs()[0] @@ -252,7 +295,7 @@ We compare them to the model's ones. .. code-block:: none - 0.9999999999999528 + 0.9999999999999366 @@ -265,7 +308,7 @@ that explains the small discrepencies. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 1.592 seconds) + **Total running time of the script:** ( 0 minutes 0.966 seconds) .. _sphx_glr_download_auto_examples_plot_convert_pipeline_vectorizer.py: diff --git a/docs/api/python/sources/auto_examples/plot_dl_keras.rst.txt b/docs/api/python/sources/auto_examples/plot_dl_keras.rst.txt deleted file mode 100644 index 8e759fea5393e..0000000000000 --- a/docs/api/python/sources/auto_examples/plot_dl_keras.rst.txt +++ /dev/null @@ -1,198 +0,0 @@ - -.. DO NOT EDIT. -.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -.. "auto_examples\plot_dl_keras.py" -.. LINE NUMBERS ARE GIVEN BELOW. - -.. only:: html - - .. note:: - :class: sphx-glr-download-link-note - - Click :ref:`here ` - to download the full example code - -.. rst-class:: sphx-glr-example-title - -.. _sphx_glr_auto_examples_plot_dl_keras.py: - - -.. _l-example-backend-api-tensorflow: - -ONNX Runtime for Keras -====================== - -The following demonstrates how to compute the predictions -of a pretrained deep learning model obtained from -`keras `_ -with *onnxruntime*. The conversion requires -`keras `_, -`tensorflow `_, -`keras-onnx `_, -`onnxmltools `_ -but then only *onnxruntime* is required -to compute the predictions. - -.. GENERATED FROM PYTHON SOURCE LINES 22-32 - -.. code-block:: default - - import os - if not os.path.exists('dense121.onnx'): - from keras.applications.densenet import DenseNet121 - model = DenseNet121(include_top=True, weights='imagenet') - - from keras2onnx import convert_keras - onx = convert_keras(model, 'dense121.onnx') - with open("dense121.onnx", "wb") as f: - f.write(onx.SerializeToString()) - - - -.. rst-class:: sphx-glr-script-out - -.. code-block:: pytb - - Traceback (most recent call last): - File "C:\xadupre\microsoft_xadupre\onnxruntime\docs\python\examples\plot_dl_keras.py", line 28, in - onx = convert_keras(model, 'dense121.onnx') - File "C:\xadupre\microsoft_xadupre\keras-onnx\keras2onnx\main.py", line 82, in convert_keras - tf_graph = build_layer_output_from_model(model, output_dict, input_names, - File "C:\xadupre\microsoft_xadupre\keras-onnx\keras2onnx\_parser_tf.py", line 308, in build_layer_output_from_model - graph = model.outputs[0].graph - AttributeError: 'KerasTensor' object has no attribute 'graph' - - - - -.. GENERATED FROM PYTHON SOURCE LINES 33-34 - -Let's load an image (source: wikipedia). - -.. GENERATED FROM PYTHON SOURCE LINES 34-43 - -.. code-block:: default - - - from keras.preprocessing.image import array_to_img, img_to_array, load_img - img = load_img('Sannosawa1.jpg') - ximg = img_to_array(img) - - import matplotlib.pyplot as plt - plt.imshow(ximg / 255) - plt.axis('off') - - -.. GENERATED FROM PYTHON SOURCE LINES 44-45 - -Let's load the model with onnxruntime. - -.. GENERATED FROM PYTHON SOURCE LINES 45-60 - -.. code-block:: default - - import onnxruntime as rt - from onnxruntime.capi.onnxruntime_pybind11_state import InvalidGraph - - try: - sess = rt.InferenceSession('dense121.onnx') - ok = True - except (InvalidGraph, TypeError, RuntimeError) as e: - # Probably a mismatch between onnxruntime and onnx version. - print(e) - ok = False - - if ok: - print("The model expects input shape:", sess.get_inputs()[0].shape) - print("image shape:", ximg.shape) - - -.. GENERATED FROM PYTHON SOURCE LINES 61-62 - -Let's resize the image. - -.. GENERATED FROM PYTHON SOURCE LINES 62-73 - -.. code-block:: default - - - if ok: - from skimage.transform import resize - import numpy - - ximg224 = resize(ximg / 255, (224, 224, 3), anti_aliasing=True) - ximg = ximg224[numpy.newaxis, :, :, :] - ximg = ximg.astype(numpy.float32) - - print("new shape:", ximg.shape) - - -.. GENERATED FROM PYTHON SOURCE LINES 74-75 - -Let's compute the output. - -.. GENERATED FROM PYTHON SOURCE LINES 75-83 - -.. code-block:: default - - - if ok: - input_name = sess.get_inputs()[0].name - res = sess.run(None, {input_name: ximg}) - prob = res[0] - print(prob.ravel()[:10]) # Too big to be displayed. - - - -.. GENERATED FROM PYTHON SOURCE LINES 84-85 - -Let's get more comprehensive results. - -.. GENERATED FROM PYTHON SOURCE LINES 85-95 - -.. code-block:: default - - - if ok: - from keras.applications.densenet import decode_predictions - decoded = decode_predictions(prob) - - import pandas - df = pandas.DataFrame(decoded[0], columns=["class_id", "name", "P"]) - print(df) - - - - -.. rst-class:: sphx-glr-timing - - **Total running time of the script:** ( 0 minutes 6.417 seconds) - - -.. _sphx_glr_download_auto_examples_plot_dl_keras.py: - - -.. only :: html - - .. container:: sphx-glr-footer - :class: sphx-glr-footer-example - - - - .. container:: sphx-glr-download sphx-glr-download-python - - :download:`Download Python source code: plot_dl_keras.py ` - - - - .. container:: sphx-glr-download sphx-glr-download-jupyter - - :download:`Download Jupyter notebook: plot_dl_keras.ipynb ` - - -.. only:: html - - .. rst-class:: sphx-glr-signature - - `Gallery generated by Sphinx-Gallery `_ diff --git a/docs/api/python/sources/auto_examples/plot_load_and_predict.rst.txt b/docs/api/python/sources/auto_examples/plot_load_and_predict.rst.txt index eee7c4064f758..880209ef5fb5b 100644 --- a/docs/api/python/sources/auto_examples/plot_load_and_predict.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_load_and_predict.rst.txt @@ -54,7 +54,7 @@ The model is available on github `onnx...test_sigmoid + .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 0.244 seconds) + **Total running time of the script:** ( 0 minutes 0.196 seconds) .. _sphx_glr_download_auto_examples_plot_pipeline.py: diff --git a/docs/api/python/sources/auto_examples/plot_profiling.rst.txt b/docs/api/python/sources/auto_examples/plot_profiling.rst.txt index c45a358030010..b5042b610ddd2 100644 --- a/docs/api/python/sources/auto_examples/plot_profiling.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_profiling.rst.txt @@ -67,7 +67,7 @@ Let's load a very simple model and compute some prediction. example1 = get_example("mul_1.onnx") onnx_model = change_ir_version(example1) onnx_model_str = onnx_model.SerializeToString() - sess = rt.InferenceSession(onnx_model_str) + sess = rt.InferenceSession(onnx_model_str, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) @@ -103,7 +103,7 @@ before running the predictions. options = rt.SessionOptions() options.enable_profiling = True - sess_profile = rt.InferenceSession(onnx_model_str, options) + sess_profile = rt.InferenceSession(onnx_model_str, options, providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32) @@ -122,7 +122,7 @@ before running the predictions. .. code-block:: none - onnxruntime_profile__2021-03-04_18-40-00.json + onnxruntime_profile__2022-01-04_17-09-55.json @@ -156,20 +156,20 @@ Let's see what it contains. [{'args': {}, 'cat': 'Session', - 'dur': 101, + 'dur': 56, 'name': 'model_loading_array', 'ph': 'X', - 'pid': 77, - 'tid': 77, - 'ts': 3}, + 'pid': 3089, + 'tid': 3089, + 'ts': 1}, {'args': {}, 'cat': 'Session', - 'dur': 227, + 'dur': 240, 'name': 'session_initialization', 'ph': 'X', - 'pid': 77, - 'tid': 77, - 'ts': 134}] + 'pid': 3089, + 'tid': 3089, + 'ts': 71}] @@ -177,7 +177,7 @@ Let's see what it contains. .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 0 minutes 0.010 seconds) + **Total running time of the script:** ( 0 minutes 0.007 seconds) .. _sphx_glr_download_auto_examples_plot_profiling.py: diff --git a/docs/api/python/sources/auto_examples/plot_train_convert_predict.rst.txt b/docs/api/python/sources/auto_examples/plot_train_convert_predict.rst.txt index 354281587abe5..1eee02ac44ada 100644 --- a/docs/api/python/sources/auto_examples/plot_train_convert_predict.rst.txt +++ b/docs/api/python/sources/auto_examples/plot_train_convert_predict.rst.txt @@ -77,14 +77,6 @@ Then we fit a model. .. code-block:: none - /opt/miniconda/lib/python3.7/site-packages/sklearn/linear_model/_logistic.py:765: ConvergenceWarning: lbfgs failed to converge (status=1): - STOP: TOTAL NO. of ITERATIONS REACHED LIMIT. - - Increase the number of iterations (max_iter) or scale the data as shown in: - https://scikit-learn.org/stable/modules/preprocessing.html - Please also refer to the documentation for alternative solver options: - https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression - extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG) LogisticRegression() @@ -114,9 +106,9 @@ and we show the confusion matrix. .. code-block:: none - [[10 0 0] - [ 0 14 0] - [ 0 1 13]] + [[13 0 0] + [ 0 10 1] + [ 0 0 14]] @@ -161,7 +153,7 @@ its input and output. import onnxruntime as rt - sess = rt.InferenceSession("logreg_iris.onnx") + sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers()) print("input name='{}' and shape={}".format( sess.get_inputs()[0].name, sess.get_inputs()[0].shape)) @@ -210,9 +202,9 @@ We compute the predictions. .. code-block:: none - [[10 0 0] - [ 0 15 0] - [ 0 0 13]] + [[13 0 0] + [ 0 10 0] + [ 0 0 15]] @@ -247,9 +239,9 @@ scikit-learn. .. code-block:: none - [[4.15987711e-03 8.54898335e-01 1.40941788e-01] - [9.44228260e-01 5.57707615e-02 9.78002823e-07] - [5.17324282e-02 8.88396143e-01 5.98714288e-02]] + [[2.95951945e-05 5.69800366e-02 9.42990368e-01] + [1.84923705e-05 3.93636566e-02 9.60617851e-01] + [1.30004554e-02 8.03678159e-01 1.83321386e-01]] @@ -280,9 +272,9 @@ The probabilies appear to be .. code-block:: none - [{0: 0.0041598789393901825, 1: 0.8548984527587891, 2: 0.14094172418117523}, - {0: 0.9442282915115356, 1: 0.055770788341760635, 2: 9.78002844931325e-07}, - {0: 0.05173242464661598, 1: 0.888396143913269, 2: 0.05987146869301796}] + [{0: 2.9595235901069827e-05, 1: 0.05698008090257645, 2: 0.9429903030395508}, + {0: 1.8492364688427188e-05, 1: 0.03936365991830826, 2: 0.9606178402900696}, + {0: 0.013000461272895336, 1: 0.8036782741546631, 2: 0.1833212822675705}] @@ -322,11 +314,11 @@ Let's benchmark. .. code-block:: none Execution time for clr.predict - Average 8.56e-05 min=7.72e-05 max=0.000101 + Average 4.38e-05 min=4.25e-05 max=6.07e-05 Execution time for ONNX Runtime - Average 5.02e-05 min=4.61e-05 max=6.17e-05 + Average 1.97e-05 min=1.92e-05 max=2.46e-05 - 5.0215695519000296e-05 + 1.9671264999914226e-05 @@ -369,11 +361,11 @@ as opposed to a batch of prediction. .. code-block:: none Execution time for clr.predict - Average 0.00723 min=0.00694 max=0.00837 + Average 0.00404 min=0.00402 max=0.00409 Execution time for sess_predict - Average 0.00156 min=0.00152 max=0.00166 + Average 0.000881 min=0.000874 max=0.000912 - 0.0015644603711552918 + 0.0008813192099997735 @@ -406,11 +398,11 @@ Let's do the same for the probabilities. .. code-block:: none Execution time for predict_proba - Average 0.0108 min=0.0104 max=0.0115 + Average 0.00599 min=0.00597 max=0.00606 Execution time for sess_predict_proba - Average 0.0017 min=0.00163 max=0.00188 + Average 0.000883 min=0.000876 max=0.000916 - 0.0016972313076257703 + 0.0008830492349999729 @@ -457,7 +449,7 @@ We compare. .. code-block:: default - sess = rt.InferenceSession("rf_iris.onnx") + sess = rt.InferenceSession("rf_iris.onnx", providers=rt.get_available_providers()) def sess_predict_proba_rf(x): return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] @@ -479,11 +471,11 @@ We compare. .. code-block:: none Execution time for predict_proba - Average 1.25 min=1.23 max=1.26 + Average 0.717 min=0.715 max=0.72 Execution time for sess_predict_proba - Average 0.00274 min=0.00245 max=0.00442 + Average 0.00108 min=0.00107 max=0.00111 - 0.0027408220106735826 + 0.0010817126199989956 @@ -506,7 +498,7 @@ Let's see with different number of trees. onx = convert_sklearn(rf, initial_types=initial_type) with open("rf_iris_%d.onnx" % n_trees, "wb") as f: f.write(onx.SerializeToString()) - sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees) + sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees, providers=rt.get_available_providers()) def sess_predict_proba_loop(x): return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0] tsk = speed("loop(X_test, rf.predict_proba, 100)", number=5, repeat=5) @@ -525,9 +517,10 @@ Let's see with different number of trees. -.. image:: /auto_examples/images/sphx_glr_plot_train_convert_predict_001.png - :alt: Speed comparison between scikit-learn and ONNX Runtime For a random forest on Iris dataset - :class: sphx-glr-single-img +.. image-sg:: /auto_examples/images/sphx_glr_plot_train_convert_predict_001.png + :alt: Speed comparison between scikit-learn and ONNX Runtime For a random forest on Iris dataset + :srcset: /auto_examples/images/sphx_glr_plot_train_convert_predict_001.png + :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out @@ -537,44 +530,44 @@ Let's see with different number of trees. .. code-block:: none 5 - Average 0.11 min=0.107 max=0.118 - Average 0.00169 min=0.00161 max=0.00177 + Average 0.0637 min=0.0636 max=0.0639 + Average 0.000869 min=0.000857 max=0.000899 10 - Average 0.167 min=0.165 max=0.169 - Average 0.0017 min=0.00165 max=0.00179 + Average 0.0982 min=0.098 max=0.0987 + Average 0.000884 min=0.000873 max=0.00091 15 - Average 0.228 min=0.227 max=0.231 - Average 0.0017 min=0.00167 max=0.00172 + Average 0.133 min=0.133 max=0.133 + Average 0.000895 min=0.000885 max=0.000921 20 - Average 0.291 min=0.286 max=0.296 - Average 0.00175 min=0.00173 max=0.00176 + Average 0.168 min=0.167 max=0.168 + Average 0.000915 min=0.000907 max=0.00094 25 - Average 0.346 min=0.342 max=0.35 - Average 0.00174 min=0.00172 max=0.00181 + Average 0.202 min=0.201 max=0.203 + Average 0.000921 min=0.000913 max=0.000948 30 - Average 0.407 min=0.404 max=0.41 - Average 0.0018 min=0.00174 max=0.0019 + Average 0.236 min=0.236 max=0.237 + Average 0.000922 min=0.000914 max=0.000948 35 - Average 0.463 min=0.459 max=0.467 - Average 0.0018 min=0.00176 max=0.00187 + Average 0.271 min=0.271 max=0.271 + Average 0.000941 min=0.000928 max=0.000967 40 - Average 0.531 min=0.521 max=0.556 - Average 0.0018 min=0.00179 max=0.00183 + Average 0.305 min=0.305 max=0.305 + Average 0.000948 min=0.000934 max=0.000977 45 - Average 0.582 min=0.577 max=0.597 - Average 0.00187 min=0.00185 max=0.00189 + Average 0.34 min=0.339 max=0.34 + Average 0.000983 min=0.000972 max=0.00101 50 - Average 0.642 min=0.64 max=0.645 - Average 0.00188 min=0.00185 max=0.00196 + Average 0.375 min=0.374 max=0.375 + Average 0.000972 min=0.000966 max=0.000992 - + .. rst-class:: sphx-glr-timing - **Total running time of the script:** ( 5 minutes 52.417 seconds) + **Total running time of the script:** ( 3 minutes 22.159 seconds) .. _sphx_glr_download_auto_examples_plot_train_convert_predict.py: diff --git a/docs/api/python/sources/auto_examples/sg_execution_times.rst.txt b/docs/api/python/sources/auto_examples/sg_execution_times.rst.txt index a4f6acba3905f..12734e94e72c0 100644 --- a/docs/api/python/sources/auto_examples/sg_execution_times.rst.txt +++ b/docs/api/python/sources/auto_examples/sg_execution_times.rst.txt @@ -5,22 +5,22 @@ Computation times ================= -**05:52.417** total execution time for **auto_examples** files: +**03:23.370** total execution time for **auto_examples** files: +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_train_convert_predict.py` (``plot_train_convert_predict.py``) | 05:52.417 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_train_convert_predict.py` (``plot_train_convert_predict.py``) | 03:22.159 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_backend.py` (``plot_backend.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_convert_pipeline_vectorizer.py` (``plot_convert_pipeline_vectorizer.py``) | 00:00.966 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_common_errors.py` (``plot_common_errors.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_pipeline.py` (``plot_pipeline.py``) | 00:00.196 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_convert_pipeline_vectorizer.py` (``plot_convert_pipeline_vectorizer.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_backend.py` (``plot_backend.py``) | 00:00.014 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_load_and_predict.py` (``plot_load_and_predict.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_load_and_predict.py` (``plot_load_and_predict.py``) | 00:00.013 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_metadata.py` (``plot_metadata.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_common_errors.py` (``plot_common_errors.py``) | 00:00.009 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_pipeline.py` (``plot_pipeline.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_profiling.py` (``plot_profiling.py``) | 00:00.007 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ -| :ref:`sphx_glr_auto_examples_plot_profiling.py` (``plot_profiling.py``) | 00:00.000 | 0.0 MB | +| :ref:`sphx_glr_auto_examples_plot_metadata.py` (``plot_metadata.py``) | 00:00.005 | 0.0 MB | +-------------------------------------------------------------------------------------------------------------+-----------+--------+ diff --git a/docs/api/python/sources/examples_md.rst.txt b/docs/api/python/sources/examples_md.rst.txt index 2c0ca6b4e019f..b3426e824efd5 100644 --- a/docs/api/python/sources/examples_md.rst.txt +++ b/docs/api/python/sources/examples_md.rst.txt @@ -5,7 +5,7 @@ Gallery of examples =================== - The first series of examples briefly goes into the main + This series of examples briefly goes into the main feature *ONNX Runtime* implements. Each of them run in a few seconds and relies on machine learned models trained with `scikit-learn `_. @@ -22,14 +22,3 @@ auto_examples/plot_convert_pipeline_vectorizer auto_examples/plot_metadata auto_examples/plot_profiling - - The second series is about deep learning. - Once converted to *ONNX*, the predictions can be - computed with *onnxruntime* without having any - dependencies on the framework used to train the model. - - .. toctree:: - :maxdepth: 1 - :caption: Contents: - - auto_examples/plot_dl_keras diff --git a/docs/api/python/sources/tutorial.rst.txt b/docs/api/python/sources/tutorial.rst.txt index d00a378cfeedc..fccca9cbd1451 100644 --- a/docs/api/python/sources/tutorial.rst.txt +++ b/docs/api/python/sources/tutorial.rst.txt @@ -82,7 +82,7 @@ for this machine learning model. import numpy import onnxruntime as rt - sess = rt.InferenceSession("logreg_iris.onnx") + sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers()) input_name = sess.get_inputs()[0].name pred_onx = sess.run(None, {input_name: X_test.astype(numpy.float32)})[0] print(pred_onx) @@ -97,7 +97,7 @@ by specifying its name into a list. import numpy import onnxruntime as rt - sess = rt.InferenceSession("logreg_iris.onnx") + sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers()) 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] diff --git a/docs/api/python/static/basic.css b/docs/api/python/static/basic.css index be19270e4a241..603f6a8798e7f 100644 --- a/docs/api/python/static/basic.css +++ b/docs/api/python/static/basic.css @@ -130,7 +130,7 @@ ul.search li a { font-weight: bold; } -ul.search li div.context { +ul.search li p.context { color: #888; margin: 2px 0 0 30px; text-align: left; @@ -277,25 +277,25 @@ p.rubric { font-weight: bold; } -img.align-left, .figure.align-left, object.align-left { +img.align-left, figure.align-left, .figure.align-left, object.align-left { clear: left; float: left; margin-right: 1em; } -img.align-right, .figure.align-right, object.align-right { +img.align-right, figure.align-right, .figure.align-right, object.align-right { clear: right; float: right; margin-left: 1em; } -img.align-center, .figure.align-center, object.align-center { +img.align-center, figure.align-center, .figure.align-center, object.align-center { display: block; margin-left: auto; margin-right: auto; } -img.align-default, .figure.align-default { +img.align-default, figure.align-default, .figure.align-default { display: block; margin-left: auto; margin-right: auto; @@ -319,7 +319,8 @@ img.align-default, .figure.align-default { /* -- sidebars -------------------------------------------------------------- */ -div.sidebar { +div.sidebar, +aside.sidebar { margin: 0 0 0.5em 1em; border: 1px solid #ddb; padding: 7px; @@ -377,12 +378,14 @@ div.body p.centered { /* -- content of sidebars/topics/admonitions -------------------------------- */ div.sidebar > :last-child, +aside.sidebar > :last-child, div.topic > :last-child, div.admonition > :last-child { margin-bottom: 0; } div.sidebar::after, +aside.sidebar::after, div.topic::after, div.admonition::after, blockquote::after { @@ -455,20 +458,22 @@ td > :last-child { /* -- figures --------------------------------------------------------------- */ -div.figure { +div.figure, figure { margin: 0.5em; padding: 0.5em; } -div.figure p.caption { +div.figure p.caption, figcaption { padding: 0.3em; } -div.figure p.caption span.caption-number { +div.figure p.caption span.caption-number, +figcaption span.caption-number { font-style: italic; } -div.figure p.caption span.caption-text { +div.figure p.caption span.caption-text, +figcaption span.caption-text { } /* -- field list styles ----------------------------------------------------- */ @@ -503,6 +508,63 @@ table.hlist td { vertical-align: top; } +/* -- object description styles --------------------------------------------- */ + +.sig { + font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; +} + +.sig-name, code.descname { + background-color: transparent; + font-weight: bold; +} + +.sig-name { + font-size: 1.1em; +} + +code.descname { + font-size: 1.2em; +} + +.sig-prename, code.descclassname { + background-color: transparent; +} + +.optional { + font-size: 1.3em; +} + +.sig-paren { + font-size: larger; +} + +.sig-param.n { + font-style: italic; +} + +/* C++ specific styling */ + +.sig-inline.c-texpr, +.sig-inline.cpp-texpr { + font-family: unset; +} + +.sig.c .k, .sig.c .kt, +.sig.cpp .k, .sig.cpp .kt { + color: #0033B3; +} + +.sig.c .m, +.sig.cpp .m { + color: #1750EB; +} + +.sig.c .s, .sig.c .sc, +.sig.cpp .s, .sig.cpp .sc { + color: #067D17; +} + /* -- other body styles ----------------------------------------------------- */ @@ -629,14 +691,6 @@ dl.glossary dt { font-size: 1.1em; } -.optional { - font-size: 1.3em; -} - -.sig-paren { - font-size: larger; -} - .versionmodified { font-style: italic; } @@ -677,8 +731,9 @@ dl.glossary dt { .classifier:before { font-style: normal; - margin: 0.5em; + margin: 0 0.5em; content: ":"; + display: inline-block; } abbr, acronym { @@ -765,8 +820,12 @@ div.code-block-caption code { table.highlighttable td.linenos, span.linenos, -div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */ - user-select: none; +div.highlight span.gp { /* gp: Generic.Prompt */ + user-select: none; + -webkit-user-select: text; /* Safari fallback only */ + -webkit-user-select: none; /* Chrome/Safari */ + -moz-user-select: none; /* Firefox */ + -ms-user-select: none; /* IE10+ */ } div.code-block-caption span.caption-number { @@ -781,16 +840,6 @@ div.literal-block-wrapper { margin: 1em 0; } -code.descname { - background-color: transparent; - font-weight: bold; - font-size: 1.2em; -} - -code.descclassname { - background-color: transparent; -} - code.xref, a code { background-color: transparent; font-weight: bold; diff --git a/docs/api/python/static/doctools.js b/docs/api/python/static/doctools.js index 61ac9d266f95d..8cbf1b161a652 100644 --- a/docs/api/python/static/doctools.js +++ b/docs/api/python/static/doctools.js @@ -301,12 +301,14 @@ var Documentation = { window.location.href = prevHref; return false; } + break; case 39: // right var nextHref = $('link[rel="next"]').prop('href'); if (nextHref) { window.location.href = nextHref; return false; } + break; } } }); diff --git a/docs/api/python/static/documentation_options.js b/docs/api/python/static/documentation_options.js index a752120bb7d79..b5bc969fa9035 100644 --- a/docs/api/python/static/documentation_options.js +++ b/docs/api/python/static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '1.7.0', + VERSION: '1.11.0', LANGUAGE: 'en', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/docs/api/python/static/pygments.css b/docs/api/python/static/pygments.css index 582d5c3adaddb..631bc92ffa57b 100644 --- a/docs/api/python/static/pygments.css +++ b/docs/api/python/static/pygments.css @@ -1,10 +1,5 @@ -pre { line-height: 125%; } -td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } -span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; } -td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } -span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } .highlight .hll { background-color: #ffffcc } -.highlight { background: #f8f8f8; } +.highlight { background: #f8f8f8; } .highlight .c { color: #408080; font-style: italic } /* Comment */ .highlight .err { border: 1px solid #FF0000 } /* Error */ .highlight .k { color: #008000; font-weight: bold } /* Keyword */ diff --git a/docs/api/python/static/searchtools.js b/docs/api/python/static/searchtools.js index 1a90152eb0efd..002e9c4a20fb4 100644 --- a/docs/api/python/static/searchtools.js +++ b/docs/api/python/static/searchtools.js @@ -282,7 +282,10 @@ var Search = { complete: function(jqxhr, textstatus) { var data = jqxhr.responseText; if (data !== '' && data !== undefined) { - listItem.append(Search.makeSearchSummary(data, searchterms, hlterms)); + var summary = Search.makeSearchSummary(data, searchterms, hlterms); + if (summary) { + listItem.append(summary); + } } Search.output.append(listItem); setTimeout(function() { @@ -325,7 +328,9 @@ var Search = { var results = []; for (var prefix in objects) { - for (var name in objects[prefix]) { + for (var iMatch = 0; iMatch != objects[prefix].length; ++iMatch) { + var match = objects[prefix][iMatch]; + var name = match[4]; var fullname = (prefix ? prefix + '.' : '') + name; var fullnameLower = fullname.toLowerCase() if (fullnameLower.indexOf(object) > -1) { @@ -339,7 +344,6 @@ var Search = { } else if (parts[parts.length - 1].indexOf(object) > -1) { score += Scorer.objPartialMatch; } - var match = objects[prefix][name]; var objname = objnames[match[1]][2]; var title = titles[match[0]]; // If more than one term searched for, we require other words to be @@ -498,6 +502,9 @@ var Search = { */ makeSearchSummary : function(htmlText, keywords, hlwords) { var text = Search.htmlToText(htmlText); + if (text == "") { + return null; + } var textLower = text.toLowerCase(); var start = 0; $.each(keywords, function() { @@ -509,7 +516,7 @@ var Search = { var excerpt = ((start > 0) ? '...' : '') + $.trim(text.substr(start, 240)) + ((start + 240 - text.length) ? '...' : ''); - var rv = $('
      ').text(excerpt); + var rv = $('

      ').text(excerpt); $.each(hlwords, function() { rv = rv.highlightText(this, 'highlighted'); }); diff --git a/docs/api/python/static/gallery-binder.css b/docs/api/python/static/sg_gallery-binder.css similarity index 100% rename from docs/api/python/static/gallery-binder.css rename to docs/api/python/static/sg_gallery-binder.css diff --git a/docs/api/python/static/gallery-dataframe.css b/docs/api/python/static/sg_gallery-dataframe.css similarity index 100% rename from docs/api/python/static/gallery-dataframe.css rename to docs/api/python/static/sg_gallery-dataframe.css diff --git a/docs/api/python/static/gallery-rendered-html.css b/docs/api/python/static/sg_gallery-rendered-html.css similarity index 100% rename from docs/api/python/static/gallery-rendered-html.css rename to docs/api/python/static/sg_gallery-rendered-html.css diff --git a/docs/api/python/static/gallery.css b/docs/api/python/static/sg_gallery.css similarity index 98% rename from docs/api/python/static/gallery.css rename to docs/api/python/static/sg_gallery.css index 848774f4c5494..5fdf7f2498f8e 100644 --- a/docs/api/python/static/gallery.css +++ b/docs/api/python/static/sg_gallery.css @@ -145,7 +145,7 @@ div.sphx-glr-download a:hover { background-color: #d5d57e; } -.sphx-glr-example-title > :target::before { +.sphx-glr-example-title:target::before { display: block; content: ""; margin-top: -50px; diff --git a/docs/api/python/static/underscore-1.12.0.js b/docs/api/python/static/underscore-1.13.1.js similarity index 94% rename from docs/api/python/static/underscore-1.12.0.js rename to docs/api/python/static/underscore-1.13.1.js index 3af6352e61313..ffd77af9648a4 100644 --- a/docs/api/python/static/underscore-1.12.0.js +++ b/docs/api/python/static/underscore-1.13.1.js @@ -1,19 +1,19 @@ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define('underscore', factory) : - (global = global || self, (function () { + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, (function () { var current = global._; var exports = global._ = factory(); exports.noConflict = function () { global._ = current; return exports; }; }())); }(this, (function () { - // Underscore.js 1.12.0 + // Underscore.js 1.13.1 // https://underscorejs.org - // (c) 2009-2020 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + // (c) 2009-2021 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors // Underscore may be freely distributed under the MIT license. // Current version. - var VERSION = '1.12.0'; + var VERSION = '1.13.1'; // Establish the root object, `window` (`self`) in the browser, `global` // on the server, or `this` in some virtual machines. We use `self` @@ -170,7 +170,7 @@ var isArray = nativeIsArray || tagTester('Array'); // Internal function to check whether `key` is an own property name of `obj`. - function has(obj, key) { + function has$1(obj, key) { return obj != null && hasOwnProperty.call(obj, key); } @@ -181,7 +181,7 @@ (function() { if (!isArguments(arguments)) { isArguments = function(obj) { - return has(obj, 'callee'); + return has$1(obj, 'callee'); }; } }()); @@ -268,7 +268,7 @@ // Constructor is a special case. var prop = 'constructor'; - if (has(obj, prop) && !keys.contains(prop)) keys.push(prop); + if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop); while (nonEnumIdx--) { prop = nonEnumerableProps[nonEnumIdx]; @@ -284,7 +284,7 @@ if (!isObject(obj)) return []; if (nativeKeys) return nativeKeys(obj); var keys = []; - for (var key in obj) if (has(obj, key)) keys.push(key); + for (var key in obj) if (has$1(obj, key)) keys.push(key); // Ahem, IE < 9. if (hasEnumBug) collectNonEnumProps(obj, keys); return keys; @@ -318,24 +318,24 @@ // If Underscore is called as a function, it returns a wrapped object that can // be used OO-style. This wrapper holds altered versions of all functions added // through `_.mixin`. Wrapped objects may be chained. - function _(obj) { - if (obj instanceof _) return obj; - if (!(this instanceof _)) return new _(obj); + function _$1(obj) { + if (obj instanceof _$1) return obj; + if (!(this instanceof _$1)) return new _$1(obj); this._wrapped = obj; } - _.VERSION = VERSION; + _$1.VERSION = VERSION; // Extracts the result from a wrapped and chained object. - _.prototype.value = function() { + _$1.prototype.value = function() { return this._wrapped; }; // Provide unwrapping proxies for some methods used in engine operations // such as arithmetic and JSON stringification. - _.prototype.valueOf = _.prototype.toJSON = _.prototype.value; + _$1.prototype.valueOf = _$1.prototype.toJSON = _$1.prototype.value; - _.prototype.toString = function() { + _$1.prototype.toString = function() { return String(this._wrapped); }; @@ -370,8 +370,8 @@ // Internal recursive comparison function for `_.isEqual`. function deepEq(a, b, aStack, bStack) { // Unwrap any wrapped objects. - if (a instanceof _) a = a._wrapped; - if (b instanceof _) b = b._wrapped; + if (a instanceof _$1) a = a._wrapped; + if (b instanceof _$1) b = b._wrapped; // Compare `[[Class]]` names. var className = toString.call(a); if (className !== toString.call(b)) return false; @@ -463,7 +463,7 @@ while (length--) { // Deep compare each member key = _keys[length]; - if (!(has(b, key) && eq(a[key], b[key], aStack, bStack))) return false; + if (!(has$1(b, key) && eq(a[key], b[key], aStack, bStack))) return false; } } // Remove the first object from the stack of traversed objects. @@ -642,15 +642,15 @@ // Normalize a (deep) property `path` to array. // Like `_.iteratee`, this function can be customized. - function toPath(path) { + function toPath$1(path) { return isArray(path) ? path : [path]; } - _.toPath = toPath; + _$1.toPath = toPath$1; // Internal wrapper for `_.toPath` to enable minification. // Similar to `cb` for `_.iteratee`. - function toPath$1(path) { - return _.toPath(path); + function toPath(path) { + return _$1.toPath(path); } // Internal function to obtain a nested property in `obj` along `path`. @@ -668,19 +668,19 @@ // `undefined`, return `defaultValue` instead. // The `path` is normalized through `_.toPath`. function get(object, path, defaultValue) { - var value = deepGet(object, toPath$1(path)); + var value = deepGet(object, toPath(path)); return isUndefined(value) ? defaultValue : value; } // Shortcut function for checking if an object has a given property directly on // itself (in other words, not on a prototype). Unlike the internal `has` // function, this public version can also traverse nested properties. - function has$1(obj, path) { - path = toPath$1(path); + function has(obj, path) { + path = toPath(path); var length = path.length; for (var i = 0; i < length; i++) { var key = path[i]; - if (!has(obj, key)) return false; + if (!has$1(obj, key)) return false; obj = obj[key]; } return !!length; @@ -703,7 +703,7 @@ // Creates a function that, when passed an object, will traverse that object’s // properties down the given `path`, specified as an array of keys or indices. function property(path) { - path = toPath$1(path); + path = toPath(path); return function(obj) { return deepGet(obj, path); }; @@ -747,12 +747,12 @@ function iteratee(value, context) { return baseIteratee(value, context, Infinity); } - _.iteratee = iteratee; + _$1.iteratee = iteratee; // The function we call internally to generate a callback. It invokes // `_.iteratee` if overridden, otherwise `baseIteratee`. function cb(value, context, argCount) { - if (_.iteratee !== iteratee) return _.iteratee(value, context); + if (_$1.iteratee !== iteratee) return _$1.iteratee(value, context); return baseIteratee(value, context, argCount); } @@ -840,7 +840,7 @@ // By default, Underscore uses ERB-style template delimiters. Change the // following template settings to use alternative delimiters. - var templateSettings = _.templateSettings = { + var templateSettings = _$1.templateSettings = { evaluate: /<%([\s\S]+?)%>/g, interpolate: /<%=([\s\S]+?)%>/g, escape: /<%-([\s\S]+?)%>/g @@ -868,13 +868,20 @@ return '\\' + escapes[match]; } + // In order to prevent third-party code injection through + // `_.templateSettings.variable`, we test it against the following regular + // expression. It is intentionally a bit more liberal than just matching valid + // identifiers, but still prevents possible loopholes through defaults or + // destructuring assignment. + var bareIdentifier = /^\s*(\w|\$)+\s*$/; + // JavaScript micro-templating, similar to John Resig's implementation. // Underscore templating handles arbitrary delimiters, preserves whitespace, // and correctly escapes quotes within interpolated code. // NB: `oldSettings` only exists for backwards compatibility. function template(text, settings, oldSettings) { if (!settings && oldSettings) settings = oldSettings; - settings = defaults({}, settings, _.templateSettings); + settings = defaults({}, settings, _$1.templateSettings); // Combine delimiters into one regular expression via alternation. var matcher = RegExp([ @@ -903,8 +910,17 @@ }); source += "';\n"; - // If a variable is not specified, place data values in local scope. - if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + var argument = settings.variable; + if (argument) { + // Insure against third-party code injection. (CVE-2021-23358) + if (!bareIdentifier.test(argument)) throw new Error( + 'variable is not a bare identifier: ' + argument + ); + } else { + // If a variable is not specified, place data values in local scope. + source = 'with(obj||{}){\n' + source + '}\n'; + argument = 'obj'; + } source = "var __t,__p='',__j=Array.prototype.join," + "print=function(){__p+=__j.call(arguments,'');};\n" + @@ -912,18 +928,17 @@ var render; try { - render = new Function(settings.variable || 'obj', '_', source); + render = new Function(argument, '_', source); } catch (e) { e.source = source; throw e; } var template = function(data) { - return render.call(this, data, _); + return render.call(this, data, _$1); }; // Provide the compiled source as a convenience for precompilation. - var argument = settings.variable || 'obj'; template.source = 'function(' + argument + '){\n' + source + '}'; return template; @@ -933,7 +948,7 @@ // is invoked with its parent as context. Returns the value of the final // child, or `fallback` if any child is undefined. function result(obj, path, fallback) { - path = toPath$1(path); + path = toPath(path); var length = path.length; if (!length) { return isFunction$1(fallback) ? fallback.call(obj) : fallback; @@ -959,7 +974,7 @@ // Start chaining a wrapped Underscore object. function chain(obj) { - var instance = _(obj); + var instance = _$1(obj); instance._chain = true; return instance; } @@ -993,7 +1008,7 @@ return bound; }); - partial.placeholder = _; + partial.placeholder = _$1; // Create a function bound to a given object (assigning `this`, and arguments, // optionally). @@ -1012,7 +1027,7 @@ var isArrayLike = createSizePropertyCheck(getLength); // Internal implementation of a recursive `flatten` function. - function flatten(input, depth, strict, output) { + function flatten$1(input, depth, strict, output) { output = output || []; if (!depth && depth !== 0) { depth = Infinity; @@ -1025,7 +1040,7 @@ if (isArrayLike(value) && (isArray(value) || isArguments$1(value))) { // Flatten current level of array or arguments object. if (depth > 1) { - flatten(value, depth - 1, strict, output); + flatten$1(value, depth - 1, strict, output); idx = output.length; } else { var j = 0, len = value.length; @@ -1042,7 +1057,7 @@ // are the method names to be bound. Useful for ensuring that all callbacks // defined on an object belong to it. var bindAll = restArguments(function(obj, keys) { - keys = flatten(keys, false, false); + keys = flatten$1(keys, false, false); var index = keys.length; if (index < 1) throw new Error('bindAll must be passed function names'); while (index--) { @@ -1057,7 +1072,7 @@ var memoize = function(key) { var cache = memoize.cache; var address = '' + (hasher ? hasher.apply(this, arguments) : key); - if (!has(cache, address)) cache[address] = func.apply(this, arguments); + if (!has$1(cache, address)) cache[address] = func.apply(this, arguments); return cache[address]; }; memoize.cache = {}; @@ -1074,7 +1089,7 @@ // Defers a function, scheduling it to run after the current call stack has // cleared. - var defer = partial(delay, _, 1); + var defer = partial(delay, _$1, 1); // Returns a function, that, when invoked, will only be triggered at most once // during a given window of time. Normally, the throttled function will run @@ -1420,7 +1435,7 @@ if (isFunction$1(path)) { func = path; } else { - path = toPath$1(path); + path = toPath(path); contextPath = path.slice(0, -1); path = path[path.length - 1]; } @@ -1562,7 +1577,7 @@ // Groups the object's values by a criterion. Pass either a string attribute // to group by, or a function that returns the criterion. var groupBy = group(function(result, value, key) { - if (has(result, key)) result[key].push(value); else result[key] = [value]; + if (has$1(result, key)) result[key].push(value); else result[key] = [value]; }); // Indexes the object's values by a criterion, similar to `_.groupBy`, but for @@ -1575,7 +1590,7 @@ // either a string attribute to count by, or a function that returns the // criterion. var countBy = group(function(result, value, key) { - if (has(result, key)) result[key]++; else result[key] = 1; + if (has$1(result, key)) result[key]++; else result[key] = 1; }); // Split a collection into two arrays: one whose elements all pass the given @@ -1618,7 +1633,7 @@ keys = allKeys(obj); } else { iteratee = keyInObj; - keys = flatten(keys, false, false); + keys = flatten$1(keys, false, false); obj = Object(obj); } for (var i = 0, length = keys.length; i < length; i++) { @@ -1636,7 +1651,7 @@ iteratee = negate(iteratee); if (keys.length > 1) context = keys[1]; } else { - keys = map(flatten(keys, false, false), String); + keys = map(flatten$1(keys, false, false), String); iteratee = function(value, key) { return !contains(keys, key); }; @@ -1681,14 +1696,14 @@ // Flatten out an array, either recursively (by default), or up to `depth`. // Passing `true` or `false` as `depth` means `1` or `Infinity`, respectively. - function flatten$1(array, depth) { - return flatten(array, depth, false); + function flatten(array, depth) { + return flatten$1(array, depth, false); } // Take the difference between one array and a number of other arrays. // Only the elements present in just the first array will remain. var difference = restArguments(function(array, rest) { - rest = flatten(rest, true, true); + rest = flatten$1(rest, true, true); return filter(array, function(value){ return !contains(rest, value); }); @@ -1734,7 +1749,7 @@ // Produce an array that contains the union: each distinct element from all of // the passed-in arrays. var union = restArguments(function(arrays) { - return uniq(flatten(arrays, true, true)); + return uniq(flatten$1(arrays, true, true)); }); // Produce an array that contains every item shared between all the @@ -1821,26 +1836,26 @@ // Helper function to continue chaining intermediate results. function chainResult(instance, obj) { - return instance._chain ? _(obj).chain() : obj; + return instance._chain ? _$1(obj).chain() : obj; } // Add your own custom functions to the Underscore object. function mixin(obj) { each(functions(obj), function(name) { - var func = _[name] = obj[name]; - _.prototype[name] = function() { + var func = _$1[name] = obj[name]; + _$1.prototype[name] = function() { var args = [this._wrapped]; push.apply(args, arguments); - return chainResult(this, func.apply(_, args)); + return chainResult(this, func.apply(_$1, args)); }; }); - return _; + return _$1; } // Add all mutator `Array` functions to the wrapper. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { var method = ArrayProto[name]; - _.prototype[name] = function() { + _$1.prototype[name] = function() { var obj = this._wrapped; if (obj != null) { method.apply(obj, arguments); @@ -1855,7 +1870,7 @@ // Add all accessor `Array` functions to the wrapper. each(['concat', 'join', 'slice'], function(name) { var method = ArrayProto[name]; - _.prototype[name] = function() { + _$1.prototype[name] = function() { var obj = this._wrapped; if (obj != null) obj = method.apply(obj, arguments); return chainResult(this, obj); @@ -1909,12 +1924,12 @@ clone: clone, tap: tap, get: get, - has: has$1, + has: has, mapObject: mapObject, identity: identity, constant: constant, noop: noop, - toPath: toPath, + toPath: toPath$1, property: property, propertyOf: propertyOf, matcher: matcher, @@ -1997,7 +2012,7 @@ tail: rest, drop: rest, compact: compact, - flatten: flatten$1, + flatten: flatten, without: without, uniq: uniq, unique: uniq, @@ -2011,17 +2026,17 @@ range: range, chunk: chunk, mixin: mixin, - 'default': _ + 'default': _$1 }; // Default Export // Add all of the Underscore functions to the wrapper object. - var _$1 = mixin(allExports); + var _ = mixin(allExports); // Legacy Node.js API. - _$1._ = _$1; + _._ = _; - return _$1; + return _; }))); -//# sourceMappingURL=underscore.js.map +//# sourceMappingURL=underscore-umd.js.map diff --git a/docs/api/python/static/underscore-1.3.1.js b/docs/api/python/static/underscore-1.3.1.js deleted file mode 100644 index 208d4cd890c31..0000000000000 --- a/docs/api/python/static/underscore-1.3.1.js +++ /dev/null @@ -1,999 +0,0 @@ -// Underscore.js 1.3.1 -// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore is freely distributable under the MIT license. -// Portions of Underscore are inspired or borrowed from Prototype, -// Oliver Steele's Functional, and John Resig's Micro-Templating. -// For all details and documentation: -// http://documentcloud.github.com/underscore - -(function() { - - // Baseline setup - // -------------- - - // Establish the root object, `window` in the browser, or `global` on the server. - var root = this; - - // Save the previous value of the `_` variable. - var previousUnderscore = root._; - - // Establish the object that gets returned to break out of a loop iteration. - var breaker = {}; - - // Save bytes in the minified (but not gzipped) version: - var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; - - // Create quick reference variables for speed access to core prototypes. - var slice = ArrayProto.slice, - unshift = ArrayProto.unshift, - toString = ObjProto.toString, - hasOwnProperty = ObjProto.hasOwnProperty; - - // All **ECMAScript 5** native function implementations that we hope to use - // are declared here. - var - nativeForEach = ArrayProto.forEach, - nativeMap = ArrayProto.map, - nativeReduce = ArrayProto.reduce, - nativeReduceRight = ArrayProto.reduceRight, - nativeFilter = ArrayProto.filter, - nativeEvery = ArrayProto.every, - nativeSome = ArrayProto.some, - nativeIndexOf = ArrayProto.indexOf, - nativeLastIndexOf = ArrayProto.lastIndexOf, - nativeIsArray = Array.isArray, - nativeKeys = Object.keys, - nativeBind = FuncProto.bind; - - // Create a safe reference to the Underscore object for use below. - var _ = function(obj) { return new wrapper(obj); }; - - // Export the Underscore object for **Node.js**, with - // backwards-compatibility for the old `require()` API. If we're in - // the browser, add `_` as a global object via a string identifier, - // for Closure Compiler "advanced" mode. - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = _; - } - exports._ = _; - } else { - root['_'] = _; - } - - // Current version. - _.VERSION = '1.3.1'; - - // Collection Functions - // -------------------- - - // The cornerstone, an `each` implementation, aka `forEach`. - // Handles objects with the built-in `forEach`, arrays, and raw objects. - // Delegates to **ECMAScript 5**'s native `forEach` if available. - var each = _.each = _.forEach = function(obj, iterator, context) { - if (obj == null) return; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (var i = 0, l = obj.length; i < l; i++) { - if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) return; - } - } else { - for (var key in obj) { - if (_.has(obj, key)) { - if (iterator.call(context, obj[key], key, obj) === breaker) return; - } - } - } - }; - - // Return the results of applying the iterator to each element. - // Delegates to **ECMAScript 5**'s native `map` if available. - _.map = _.collect = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); - each(obj, function(value, index, list) { - results[results.length] = iterator.call(context, value, index, list); - }); - if (obj.length === +obj.length) results.length = obj.length; - return results; - }; - - // **Reduce** builds up a single result from a list of values, aka `inject`, - // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. - _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; - if (obj == null) obj = []; - if (nativeReduce && obj.reduce === nativeReduce) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); - } - each(obj, function(value, index, list) { - if (!initial) { - memo = value; - initial = true; - } else { - memo = iterator.call(context, memo, value, index, list); - } - }); - if (!initial) throw new TypeError('Reduce of empty array with no initial value'); - return memo; - }; - - // The right-associative version of reduce, also known as `foldr`. - // Delegates to **ECMAScript 5**'s native `reduceRight` if available. - _.reduceRight = _.foldr = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; - if (obj == null) obj = []; - if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); - } - var reversed = _.toArray(obj).reverse(); - if (context && !initial) iterator = _.bind(iterator, context); - return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator); - }; - - // Return the first value which passes a truth test. Aliased as `detect`. - _.find = _.detect = function(obj, iterator, context) { - var result; - any(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) { - result = value; - return true; - } - }); - return result; - }; - - // Return all the elements that pass a truth test. - // Delegates to **ECMAScript 5**'s native `filter` if available. - // Aliased as `select`. - _.filter = _.select = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); - each(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) results[results.length] = value; - }); - return results; - }; - - // Return all the elements for which a truth test fails. - _.reject = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - each(obj, function(value, index, list) { - if (!iterator.call(context, value, index, list)) results[results.length] = value; - }); - return results; - }; - - // Determine whether all of the elements match a truth test. - // Delegates to **ECMAScript 5**'s native `every` if available. - // Aliased as `all`. - _.every = _.all = function(obj, iterator, context) { - var result = true; - if (obj == null) return result; - if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); - each(obj, function(value, index, list) { - if (!(result = result && iterator.call(context, value, index, list))) return breaker; - }); - return result; - }; - - // Determine if at least one element in the object matches a truth test. - // Delegates to **ECMAScript 5**'s native `some` if available. - // Aliased as `any`. - var any = _.some = _.any = function(obj, iterator, context) { - iterator || (iterator = _.identity); - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); - each(obj, function(value, index, list) { - if (result || (result = iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - // Determine if a given value is included in the array or object using `===`. - // Aliased as `contains`. - _.include = _.contains = function(obj, target) { - var found = false; - if (obj == null) return found; - if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; - found = any(obj, function(value) { - return value === target; - }); - return found; - }; - - // Invoke a method (with arguments) on every item in a collection. - _.invoke = function(obj, method) { - var args = slice.call(arguments, 2); - return _.map(obj, function(value) { - return (_.isFunction(method) ? method || value : value[method]).apply(value, args); - }); - }; - - // Convenience version of a common use case of `map`: fetching a property. - _.pluck = function(obj, key) { - return _.map(obj, function(value){ return value[key]; }); - }; - - // Return the maximum element or (element-based computation). - _.max = function(obj, iterator, context) { - if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj); - if (!iterator && _.isEmpty(obj)) return -Infinity; - var result = {computed : -Infinity}; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - computed >= result.computed && (result = {value : value, computed : computed}); - }); - return result.value; - }; - - // Return the minimum element (or element-based computation). - _.min = function(obj, iterator, context) { - if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj); - if (!iterator && _.isEmpty(obj)) return Infinity; - var result = {computed : Infinity}; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - computed < result.computed && (result = {value : value, computed : computed}); - }); - return result.value; - }; - - // Shuffle an array. - _.shuffle = function(obj) { - var shuffled = [], rand; - each(obj, function(value, index, list) { - if (index == 0) { - shuffled[0] = value; - } else { - rand = Math.floor(Math.random() * (index + 1)); - shuffled[index] = shuffled[rand]; - shuffled[rand] = value; - } - }); - return shuffled; - }; - - // Sort the object's values by a criterion produced by an iterator. - _.sortBy = function(obj, iterator, context) { - return _.pluck(_.map(obj, function(value, index, list) { - return { - value : value, - criteria : iterator.call(context, value, index, list) - }; - }).sort(function(left, right) { - var a = left.criteria, b = right.criteria; - return a < b ? -1 : a > b ? 1 : 0; - }), 'value'); - }; - - // Groups the object's values by a criterion. Pass either a string attribute - // to group by, or a function that returns the criterion. - _.groupBy = function(obj, val) { - var result = {}; - var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; - each(obj, function(value, index) { - var key = iterator(value, index); - (result[key] || (result[key] = [])).push(value); - }); - return result; - }; - - // Use a comparator function to figure out at what index an object should - // be inserted so as to maintain order. Uses binary search. - _.sortedIndex = function(array, obj, iterator) { - iterator || (iterator = _.identity); - var low = 0, high = array.length; - while (low < high) { - var mid = (low + high) >> 1; - iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid; - } - return low; - }; - - // Safely convert anything iterable into a real, live array. - _.toArray = function(iterable) { - if (!iterable) return []; - if (iterable.toArray) return iterable.toArray(); - if (_.isArray(iterable)) return slice.call(iterable); - if (_.isArguments(iterable)) return slice.call(iterable); - return _.values(iterable); - }; - - // Return the number of elements in an object. - _.size = function(obj) { - return _.toArray(obj).length; - }; - - // Array Functions - // --------------- - - // Get the first element of an array. Passing **n** will return the first N - // values in the array. Aliased as `head`. The **guard** check allows it to work - // with `_.map`. - _.first = _.head = function(array, n, guard) { - return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; - }; - - // Returns everything but the last entry of the array. Especcialy useful on - // the arguments object. Passing **n** will return all the values in - // the array, excluding the last N. The **guard** check allows it to work with - // `_.map`. - _.initial = function(array, n, guard) { - return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); - }; - - // Get the last element of an array. Passing **n** will return the last N - // values in the array. The **guard** check allows it to work with `_.map`. - _.last = function(array, n, guard) { - if ((n != null) && !guard) { - return slice.call(array, Math.max(array.length - n, 0)); - } else { - return array[array.length - 1]; - } - }; - - // Returns everything but the first entry of the array. Aliased as `tail`. - // Especially useful on the arguments object. Passing an **index** will return - // the rest of the values in the array from that index onward. The **guard** - // check allows it to work with `_.map`. - _.rest = _.tail = function(array, index, guard) { - return slice.call(array, (index == null) || guard ? 1 : index); - }; - - // Trim out all falsy values from an array. - _.compact = function(array) { - return _.filter(array, function(value){ return !!value; }); - }; - - // Return a completely flattened version of an array. - _.flatten = function(array, shallow) { - return _.reduce(array, function(memo, value) { - if (_.isArray(value)) return memo.concat(shallow ? value : _.flatten(value)); - memo[memo.length] = value; - return memo; - }, []); - }; - - // Return a version of the array that does not contain the specified value(s). - _.without = function(array) { - return _.difference(array, slice.call(arguments, 1)); - }; - - // Produce a duplicate-free version of the array. If the array has already - // been sorted, you have the option of using a faster algorithm. - // Aliased as `unique`. - _.uniq = _.unique = function(array, isSorted, iterator) { - var initial = iterator ? _.map(array, iterator) : array; - var result = []; - _.reduce(initial, function(memo, el, i) { - if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) { - memo[memo.length] = el; - result[result.length] = array[i]; - } - return memo; - }, []); - return result; - }; - - // Produce an array that contains the union: each distinct element from all of - // the passed-in arrays. - _.union = function() { - return _.uniq(_.flatten(arguments, true)); - }; - - // Produce an array that contains every item shared between all the - // passed-in arrays. (Aliased as "intersect" for back-compat.) - _.intersection = _.intersect = function(array) { - var rest = slice.call(arguments, 1); - return _.filter(_.uniq(array), function(item) { - return _.every(rest, function(other) { - return _.indexOf(other, item) >= 0; - }); - }); - }; - - // Take the difference between one array and a number of other arrays. - // Only the elements present in just the first array will remain. - _.difference = function(array) { - var rest = _.flatten(slice.call(arguments, 1)); - return _.filter(array, function(value){ return !_.include(rest, value); }); - }; - - // Zip together multiple lists into a single array -- elements that share - // an index go together. - _.zip = function() { - var args = slice.call(arguments); - var length = _.max(_.pluck(args, 'length')); - var results = new Array(length); - for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i); - return results; - }; - - // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), - // we need this function. Return the position of the first occurrence of an - // item in an array, or -1 if the item is not included in the array. - // Delegates to **ECMAScript 5**'s native `indexOf` if available. - // If the array is large and already in sort order, pass `true` - // for **isSorted** to use binary search. - _.indexOf = function(array, item, isSorted) { - if (array == null) return -1; - var i, l; - if (isSorted) { - i = _.sortedIndex(array, item); - return array[i] === item ? i : -1; - } - if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item); - for (i = 0, l = array.length; i < l; i++) if (i in array && array[i] === item) return i; - return -1; - }; - - // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. - _.lastIndexOf = function(array, item) { - if (array == null) return -1; - if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item); - var i = array.length; - while (i--) if (i in array && array[i] === item) return i; - return -1; - }; - - // Generate an integer Array containing an arithmetic progression. A port of - // the native Python `range()` function. See - // [the Python documentation](http://docs.python.org/library/functions.html#range). - _.range = function(start, stop, step) { - if (arguments.length <= 1) { - stop = start || 0; - start = 0; - } - step = arguments[2] || 1; - - var len = Math.max(Math.ceil((stop - start) / step), 0); - var idx = 0; - var range = new Array(len); - - while(idx < len) { - range[idx++] = start; - start += step; - } - - return range; - }; - - // Function (ahem) Functions - // ------------------ - - // Reusable constructor function for prototype setting. - var ctor = function(){}; - - // Create a function bound to a given object (assigning `this`, and arguments, - // optionally). Binding with arguments is also known as `curry`. - // Delegates to **ECMAScript 5**'s native `Function.bind` if available. - // We check for `func.bind` first, to fail fast when `func` is undefined. - _.bind = function bind(func, context) { - var bound, args; - if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - if (!_.isFunction(func)) throw new TypeError; - args = slice.call(arguments, 2); - return bound = function() { - if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments))); - ctor.prototype = func.prototype; - var self = new ctor; - var result = func.apply(self, args.concat(slice.call(arguments))); - if (Object(result) === result) return result; - return self; - }; - }; - - // Bind all of an object's methods to that object. Useful for ensuring that - // all callbacks defined on an object belong to it. - _.bindAll = function(obj) { - var funcs = slice.call(arguments, 1); - if (funcs.length == 0) funcs = _.functions(obj); - each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); - return obj; - }; - - // Memoize an expensive function by storing its results. - _.memoize = function(func, hasher) { - var memo = {}; - hasher || (hasher = _.identity); - return function() { - var key = hasher.apply(this, arguments); - return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); - }; - }; - - // Delays a function for the given number of milliseconds, and then calls - // it with the arguments supplied. - _.delay = function(func, wait) { - var args = slice.call(arguments, 2); - return setTimeout(function(){ return func.apply(func, args); }, wait); - }; - - // Defers a function, scheduling it to run after the current call stack has - // cleared. - _.defer = function(func) { - return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); - }; - - // Returns a function, that, when invoked, will only be triggered at most once - // during a given window of time. - _.throttle = function(func, wait) { - var context, args, timeout, throttling, more; - var whenDone = _.debounce(function(){ more = throttling = false; }, wait); - return function() { - context = this; args = arguments; - var later = function() { - timeout = null; - if (more) func.apply(context, args); - whenDone(); - }; - if (!timeout) timeout = setTimeout(later, wait); - if (throttling) { - more = true; - } else { - func.apply(context, args); - } - whenDone(); - throttling = true; - }; - }; - - // Returns a function, that, as long as it continues to be invoked, will not - // be triggered. The function will be called after it stops being called for - // N milliseconds. - _.debounce = function(func, wait) { - var timeout; - return function() { - var context = this, args = arguments; - var later = function() { - timeout = null; - func.apply(context, args); - }; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - }; - }; - - // Returns a function that will be executed at most one time, no matter how - // often you call it. Useful for lazy initialization. - _.once = function(func) { - var ran = false, memo; - return function() { - if (ran) return memo; - ran = true; - return memo = func.apply(this, arguments); - }; - }; - - // Returns the first function passed as an argument to the second, - // allowing you to adjust arguments, run code before and after, and - // conditionally execute the original function. - _.wrap = function(func, wrapper) { - return function() { - var args = [func].concat(slice.call(arguments, 0)); - return wrapper.apply(this, args); - }; - }; - - // Returns a function that is the composition of a list of functions, each - // consuming the return value of the function that follows. - _.compose = function() { - var funcs = arguments; - return function() { - var args = arguments; - for (var i = funcs.length - 1; i >= 0; i--) { - args = [funcs[i].apply(this, args)]; - } - return args[0]; - }; - }; - - // Returns a function that will only be executed after being called N times. - _.after = function(times, func) { - if (times <= 0) return func(); - return function() { - if (--times < 1) { return func.apply(this, arguments); } - }; - }; - - // Object Functions - // ---------------- - - // Retrieve the names of an object's properties. - // Delegates to **ECMAScript 5**'s native `Object.keys` - _.keys = nativeKeys || function(obj) { - if (obj !== Object(obj)) throw new TypeError('Invalid object'); - var keys = []; - for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; - return keys; - }; - - // Retrieve the values of an object's properties. - _.values = function(obj) { - return _.map(obj, _.identity); - }; - - // Return a sorted list of the function names available on the object. - // Aliased as `methods` - _.functions = _.methods = function(obj) { - var names = []; - for (var key in obj) { - if (_.isFunction(obj[key])) names.push(key); - } - return names.sort(); - }; - - // Extend a given object with all the properties in passed-in object(s). - _.extend = function(obj) { - each(slice.call(arguments, 1), function(source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - }); - return obj; - }; - - // Fill in a given object with default properties. - _.defaults = function(obj) { - each(slice.call(arguments, 1), function(source) { - for (var prop in source) { - if (obj[prop] == null) obj[prop] = source[prop]; - } - }); - return obj; - }; - - // Create a (shallow-cloned) duplicate of an object. - _.clone = function(obj) { - if (!_.isObject(obj)) return obj; - return _.isArray(obj) ? obj.slice() : _.extend({}, obj); - }; - - // Invokes interceptor with the obj, and then returns obj. - // The primary purpose of this method is to "tap into" a method chain, in - // order to perform operations on intermediate results within the chain. - _.tap = function(obj, interceptor) { - interceptor(obj); - return obj; - }; - - // Internal recursive comparison function. - function eq(a, b, stack) { - // Identical objects are equal. `0 === -0`, but they aren't identical. - // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. - if (a === b) return a !== 0 || 1 / a == 1 / b; - // A strict comparison is necessary because `null == undefined`. - if (a == null || b == null) return a === b; - // Unwrap any wrapped objects. - if (a._chain) a = a._wrapped; - if (b._chain) b = b._wrapped; - // Invoke a custom `isEqual` method if one is provided. - if (a.isEqual && _.isFunction(a.isEqual)) return a.isEqual(b); - if (b.isEqual && _.isFunction(b.isEqual)) return b.isEqual(a); - // Compare `[[Class]]` names. - var className = toString.call(a); - if (className != toString.call(b)) return false; - switch (className) { - // Strings, numbers, dates, and booleans are compared by value. - case '[object String]': - // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is - // equivalent to `new String("5")`. - return a == String(b); - case '[object Number]': - // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for - // other numeric values. - return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); - case '[object Date]': - case '[object Boolean]': - // Coerce dates and booleans to numeric primitive values. Dates are compared by their - // millisecond representations. Note that invalid dates with millisecond representations - // of `NaN` are not equivalent. - return +a == +b; - // RegExps are compared by their source patterns and flags. - case '[object RegExp]': - return a.source == b.source && - a.global == b.global && - a.multiline == b.multiline && - a.ignoreCase == b.ignoreCase; - } - if (typeof a != 'object' || typeof b != 'object') return false; - // Assume equality for cyclic structures. The algorithm for detecting cyclic - // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. - var length = stack.length; - while (length--) { - // Linear search. Performance is inversely proportional to the number of - // unique nested structures. - if (stack[length] == a) return true; - } - // Add the first object to the stack of traversed objects. - stack.push(a); - var size = 0, result = true; - // Recursively compare objects and arrays. - if (className == '[object Array]') { - // Compare array lengths to determine if a deep comparison is necessary. - size = a.length; - result = size == b.length; - if (result) { - // Deep compare the contents, ignoring non-numeric properties. - while (size--) { - // Ensure commutative equality for sparse arrays. - if (!(result = size in a == size in b && eq(a[size], b[size], stack))) break; - } - } - } else { - // Objects with different constructors are not equivalent. - if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; - // Deep compare objects. - for (var key in a) { - if (_.has(a, key)) { - // Count the expected number of properties. - size++; - // Deep compare each member. - if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break; - } - } - // Ensure that both objects contain the same number of properties. - if (result) { - for (key in b) { - if (_.has(b, key) && !(size--)) break; - } - result = !size; - } - } - // Remove the first object from the stack of traversed objects. - stack.pop(); - return result; - } - - // Perform a deep comparison to check if two objects are equal. - _.isEqual = function(a, b) { - return eq(a, b, []); - }; - - // Is a given array, string, or object empty? - // An "empty" object has no enumerable own-properties. - _.isEmpty = function(obj) { - if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; - for (var key in obj) if (_.has(obj, key)) return false; - return true; - }; - - // Is a given value a DOM element? - _.isElement = function(obj) { - return !!(obj && obj.nodeType == 1); - }; - - // Is a given value an array? - // Delegates to ECMA5's native Array.isArray - _.isArray = nativeIsArray || function(obj) { - return toString.call(obj) == '[object Array]'; - }; - - // Is a given variable an object? - _.isObject = function(obj) { - return obj === Object(obj); - }; - - // Is a given variable an arguments object? - _.isArguments = function(obj) { - return toString.call(obj) == '[object Arguments]'; - }; - if (!_.isArguments(arguments)) { - _.isArguments = function(obj) { - return !!(obj && _.has(obj, 'callee')); - }; - } - - // Is a given value a function? - _.isFunction = function(obj) { - return toString.call(obj) == '[object Function]'; - }; - - // Is a given value a string? - _.isString = function(obj) { - return toString.call(obj) == '[object String]'; - }; - - // Is a given value a number? - _.isNumber = function(obj) { - return toString.call(obj) == '[object Number]'; - }; - - // Is the given value `NaN`? - _.isNaN = function(obj) { - // `NaN` is the only value for which `===` is not reflexive. - return obj !== obj; - }; - - // Is a given value a boolean? - _.isBoolean = function(obj) { - return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; - }; - - // Is a given value a date? - _.isDate = function(obj) { - return toString.call(obj) == '[object Date]'; - }; - - // Is the given value a regular expression? - _.isRegExp = function(obj) { - return toString.call(obj) == '[object RegExp]'; - }; - - // Is a given value equal to null? - _.isNull = function(obj) { - return obj === null; - }; - - // Is a given variable undefined? - _.isUndefined = function(obj) { - return obj === void 0; - }; - - // Has own property? - _.has = function(obj, key) { - return hasOwnProperty.call(obj, key); - }; - - // Utility Functions - // ----------------- - - // Run Underscore.js in *noConflict* mode, returning the `_` variable to its - // previous owner. Returns a reference to the Underscore object. - _.noConflict = function() { - root._ = previousUnderscore; - return this; - }; - - // Keep the identity function around for default iterators. - _.identity = function(value) { - return value; - }; - - // Run a function **n** times. - _.times = function (n, iterator, context) { - for (var i = 0; i < n; i++) iterator.call(context, i); - }; - - // Escape a string for HTML interpolation. - _.escape = function(string) { - return (''+string).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/'); - }; - - // Add your own custom functions to the Underscore object, ensuring that - // they're correctly added to the OOP wrapper as well. - _.mixin = function(obj) { - each(_.functions(obj), function(name){ - addToWrapper(name, _[name] = obj[name]); - }); - }; - - // Generate a unique integer id (unique within the entire client session). - // Useful for temporary DOM ids. - var idCounter = 0; - _.uniqueId = function(prefix) { - var id = idCounter++; - return prefix ? prefix + id : id; - }; - - // By default, Underscore uses ERB-style template delimiters, change the - // following template settings to use alternative delimiters. - _.templateSettings = { - evaluate : /<%([\s\S]+?)%>/g, - interpolate : /<%=([\s\S]+?)%>/g, - escape : /<%-([\s\S]+?)%>/g - }; - - // When customizing `templateSettings`, if you don't want to define an - // interpolation, evaluation or escaping regex, we need one that is - // guaranteed not to match. - var noMatch = /.^/; - - // Within an interpolation, evaluation, or escaping, remove HTML escaping - // that had been previously added. - var unescape = function(code) { - return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'"); - }; - - // JavaScript micro-templating, similar to John Resig's implementation. - // Underscore templating handles arbitrary delimiters, preserves whitespace, - // and correctly escapes quotes within interpolated code. - _.template = function(str, data) { - var c = _.templateSettings; - var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + - 'with(obj||{}){__p.push(\'' + - str.replace(/\\/g, '\\\\') - .replace(/'/g, "\\'") - .replace(c.escape || noMatch, function(match, code) { - return "',_.escape(" + unescape(code) + "),'"; - }) - .replace(c.interpolate || noMatch, function(match, code) { - return "'," + unescape(code) + ",'"; - }) - .replace(c.evaluate || noMatch, function(match, code) { - return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('"; - }) - .replace(/\r/g, '\\r') - .replace(/\n/g, '\\n') - .replace(/\t/g, '\\t') - + "');}return __p.join('');"; - var func = new Function('obj', '_', tmpl); - if (data) return func(data, _); - return function(data) { - return func.call(this, data, _); - }; - }; - - // Add a "chain" function, which will delegate to the wrapper. - _.chain = function(obj) { - return _(obj).chain(); - }; - - // The OOP Wrapper - // --------------- - - // If Underscore is called as a function, it returns a wrapped object that - // can be used OO-style. This wrapper holds altered versions of all the - // underscore functions. Wrapped objects may be chained. - var wrapper = function(obj) { this._wrapped = obj; }; - - // Expose `wrapper.prototype` as `_.prototype` - _.prototype = wrapper.prototype; - - // Helper function to continue chaining intermediate results. - var result = function(obj, chain) { - return chain ? _(obj).chain() : obj; - }; - - // A method to easily add functions to the OOP wrapper. - var addToWrapper = function(name, func) { - wrapper.prototype[name] = function() { - var args = slice.call(arguments); - unshift.call(args, this._wrapped); - return result(func.apply(_, args), this._chain); - }; - }; - - // Add all of the Underscore functions to the wrapper object. - _.mixin(_); - - // Add all mutator Array functions to the wrapper. - each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { - var method = ArrayProto[name]; - wrapper.prototype[name] = function() { - var wrapped = this._wrapped; - method.apply(wrapped, arguments); - var length = wrapped.length; - if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0]; - return result(wrapped, this._chain); - }; - }); - - // Add all accessor Array functions to the wrapper. - each(['concat', 'join', 'slice'], function(name) { - var method = ArrayProto[name]; - wrapper.prototype[name] = function() { - return result(method.apply(this._wrapped, arguments), this._chain); - }; - }); - - // Start chaining a wrapped Underscore object. - wrapper.prototype.chain = function() { - this._chain = true; - return this; - }; - - // Extracts the result from a wrapped and chained object. - wrapper.prototype.value = function() { - return this._wrapped; - }; - -}).call(this); diff --git a/docs/api/python/static/underscore.js b/docs/api/python/static/underscore.js index 166240ef2dd73..cf177d4285ab5 100644 --- a/docs/api/python/static/underscore.js +++ b/docs/api/python/static/underscore.js @@ -1,6 +1,6 @@ -!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define("underscore",r):(n=n||self,function(){var t=n._,e=n._=r();e.noConflict=function(){return n._=t,e}}())}(this,(function(){ -// Underscore.js 1.12.0 +!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define("underscore",r):(n="undefined"!=typeof globalThis?globalThis:n||self,function(){var t=n._,e=n._=r();e.noConflict=function(){return n._=t,e}}())}(this,(function(){ +// Underscore.js 1.13.1 // https://underscorejs.org -// (c) 2009-2020 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors +// (c) 2009-2021 Jeremy Ashkenas, Julian Gonggrijp, and DocumentCloud and Investigative Reporters & Editors // Underscore may be freely distributed under the MIT license. -var n="1.12.0",r="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||Function("return this")()||{},t=Array.prototype,e=Object.prototype,u="undefined"!=typeof Symbol?Symbol.prototype:null,o=t.push,i=t.slice,a=e.toString,f=e.hasOwnProperty,c="undefined"!=typeof ArrayBuffer,l="undefined"!=typeof DataView,s=Array.isArray,p=Object.keys,v=Object.create,h=c&&ArrayBuffer.isView,y=isNaN,g=isFinite,d=!{toString:null}.propertyIsEnumerable("toString"),b=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],m=Math.pow(2,53)-1;function j(n,r){return r=null==r?n.length-1:+r,function(){for(var t=Math.max(arguments.length-r,0),e=Array(t),u=0;u=0&&t<=m}}function $(n){return function(r){return null==r?void 0:r[n]}}var G=$("byteLength"),H=J(G),Q=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;var X=c?function(n){return h?h(n)&&!q(n):H(n)&&Q.test(a.call(n))}:K(!1),Y=$("length");function Z(n,r){r=function(n){for(var r={},t=n.length,e=0;e":">",'"':""","'":"'","`":"`"},Kn=Ln(Cn),Jn=Ln(_n(Cn)),$n=tn.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},Gn=/(.)^/,Hn={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Qn=/\\|'|\r|\n|\u2028|\u2029/g;function Xn(n){return"\\"+Hn[n]}var Yn=0;function Zn(n,r,t,e,u){if(!(e instanceof r))return n.apply(t,u);var o=Mn(n.prototype),i=n.apply(o,u);return _(i)?i:o}var nr=j((function(n,r){var t=nr.placeholder,e=function(){for(var u=0,o=r.length,i=Array(o),a=0;a1)er(a,r-1,t,e),u=e.length;else for(var f=0,c=a.length;f0&&(t=r.apply(this,arguments)),n<=1&&(r=null),t}}var cr=nr(fr,2);function lr(n,r,t){r=qn(r,t);for(var e,u=nn(n),o=0,i=u.length;o0?0:u-1;o>=0&&o0?a=o>=0?o:Math.max(o+f,a):f=o>=0?Math.min(o+1,f):o+f+1;else if(t&&o&&f)return e[o=t(e,u)]===u?o:-1;if(u!=u)return(o=r(i.call(e,a,f),C))>=0?o+a:-1;for(o=n>0?a:f-1;o>=0&&o0?0:i-1;for(u||(e=r[o?o[a]:a],a+=n);a>=0&&a=3;return r(n,Fn(t,u,4),e,o)}}var wr=_r(1),Ar=_r(-1);function xr(n,r,t){var e=[];return r=qn(r,t),mr(n,(function(n,t,u){r(n,t,u)&&e.push(n)})),e}function Sr(n,r,t){r=qn(r,t);for(var e=!tr(n)&&nn(n),u=(e||n).length,o=0;o=0}var Er=j((function(n,r,t){var e,u;return D(r)?u=r:(r=Nn(r),e=r.slice(0,-1),r=r[r.length-1]),jr(n,(function(n){var o=u;if(!o){if(e&&e.length&&(n=In(n,e)),null==n)return;o=n[r]}return null==o?o:o.apply(n,t)}))}));function Br(n,r){return jr(n,Rn(r))}function Nr(n,r,t){var e,u,o=-1/0,i=-1/0;if(null==r||"number"==typeof r&&"object"!=typeof n[0]&&null!=n)for(var a=0,f=(n=tr(n)?n:jn(n)).length;ao&&(o=e);else r=qn(r,t),mr(n,(function(n,t,e){((u=r(n,t,e))>i||u===-1/0&&o===-1/0)&&(o=n,i=u)}));return o}function Ir(n,r,t){if(null==r||t)return tr(n)||(n=jn(n)),n[Wn(n.length-1)];var e=tr(n)?En(n):jn(n),u=Y(e);r=Math.max(Math.min(r,u),0);for(var o=u-1,i=0;i1&&(e=Fn(e,r[1])),r=an(n)):(e=Pr,r=er(r,!1,!1),n=Object(n));for(var u=0,o=r.length;u1&&(t=r[1])):(r=jr(er(r,!1,!1),String),e=function(n,t){return!Mr(r,t)}),qr(n,e,t)}));function Wr(n,r,t){return i.call(n,0,Math.max(0,n.length-(null==r||t?1:r)))}function zr(n,r,t){return null==n||n.length<1?null==r||t?void 0:[]:null==r||t?n[0]:Wr(n,n.length-r)}function Lr(n,r,t){return i.call(n,null==r||t?1:r)}var Cr=j((function(n,r){return r=er(r,!0,!0),xr(n,(function(n){return!Mr(r,n)}))})),Kr=j((function(n,r){return Cr(n,r)}));function Jr(n,r,t,e){A(r)||(e=t,t=r,r=!1),null!=t&&(t=qn(t,e));for(var u=[],o=[],i=0,a=Y(n);ir?(e&&(clearTimeout(e),e=null),a=c,i=n.apply(u,o),e||(u=o=null)):e||!1===t.trailing||(e=setTimeout(f,l)),i};return c.cancel=function(){clearTimeout(e),a=0,e=u=o=null},c},debounce:function(n,r,t){var e,u,o=function(r,t){e=null,t&&(u=n.apply(r,t))},i=j((function(i){if(e&&clearTimeout(e),t){var a=!e;e=setTimeout(o,r),a&&(u=n.apply(this,i))}else e=or(o,r,this,i);return u}));return i.cancel=function(){clearTimeout(e),e=null},i},wrap:function(n,r){return nr(r,n)},negate:ar,compose:function(){var n=arguments,r=n.length-1;return function(){for(var t=r,e=n[r].apply(this,arguments);t--;)e=n[t].call(this,e);return e}},after:function(n,r){return function(){if(--n<1)return r.apply(this,arguments)}},before:fr,once:cr,findKey:lr,findIndex:pr,findLastIndex:vr,sortedIndex:hr,indexOf:gr,lastIndexOf:dr,find:br,detect:br,findWhere:function(n,r){return br(n,Dn(r))},each:mr,forEach:mr,map:jr,collect:jr,reduce:wr,foldl:wr,inject:wr,reduceRight:Ar,foldr:Ar,filter:xr,select:xr,reject:function(n,r,t){return xr(n,ar(qn(r)),t)},every:Sr,all:Sr,some:Or,any:Or,contains:Mr,includes:Mr,include:Mr,invoke:Er,pluck:Br,where:function(n,r){return xr(n,Dn(r))},max:Nr,min:function(n,r,t){var e,u,o=1/0,i=1/0;if(null==r||"number"==typeof r&&"object"!=typeof n[0]&&null!=n)for(var a=0,f=(n=tr(n)?n:jn(n)).length;ae||void 0===t)return 1;if(t=0&&t<=m}}function J(n){return function(r){return null==r?void 0:r[n]}}var G=J("byteLength"),H=K(G),Q=/\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;var X=c?function(n){return h?h(n)&&!q(n):H(n)&&Q.test(a.call(n))}:C(!1),Y=J("length");function Z(n,r){r=function(n){for(var r={},t=n.length,e=0;e":">",'"':""","'":"'","`":"`"},Cn=Ln($n),Kn=Ln(_n($n)),Jn=tn.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},Gn=/(.)^/,Hn={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},Qn=/\\|'|\r|\n|\u2028|\u2029/g;function Xn(n){return"\\"+Hn[n]}var Yn=/^\s*(\w|\$)+\s*$/;var Zn=0;function nr(n,r,t,e,u){if(!(e instanceof r))return n.apply(t,u);var o=Mn(n.prototype),i=n.apply(o,u);return _(i)?i:o}var rr=j((function(n,r){var t=rr.placeholder,e=function(){for(var u=0,o=r.length,i=Array(o),a=0;a1)ur(a,r-1,t,e),u=e.length;else for(var f=0,c=a.length;f0&&(t=r.apply(this,arguments)),n<=1&&(r=null),t}}var lr=rr(cr,2);function sr(n,r,t){r=qn(r,t);for(var e,u=nn(n),o=0,i=u.length;o0?0:u-1;o>=0&&o0?a=o>=0?o:Math.max(o+f,a):f=o>=0?Math.min(o+1,f):o+f+1;else if(t&&o&&f)return e[o=t(e,u)]===u?o:-1;if(u!=u)return(o=r(i.call(e,a,f),$))>=0?o+a:-1;for(o=n>0?a:f-1;o>=0&&o0?0:i-1;for(u||(e=r[o?o[a]:a],a+=n);a>=0&&a=3;return r(n,Fn(t,u,4),e,o)}}var Ar=wr(1),xr=wr(-1);function Sr(n,r,t){var e=[];return r=qn(r,t),jr(n,(function(n,t,u){r(n,t,u)&&e.push(n)})),e}function Or(n,r,t){r=qn(r,t);for(var e=!er(n)&&nn(n),u=(e||n).length,o=0;o=0}var Br=j((function(n,r,t){var e,u;return D(r)?u=r:(r=Nn(r),e=r.slice(0,-1),r=r[r.length-1]),_r(n,(function(n){var o=u;if(!o){if(e&&e.length&&(n=In(n,e)),null==n)return;o=n[r]}return null==o?o:o.apply(n,t)}))}));function Nr(n,r){return _r(n,Rn(r))}function Ir(n,r,t){var e,u,o=-1/0,i=-1/0;if(null==r||"number"==typeof r&&"object"!=typeof n[0]&&null!=n)for(var a=0,f=(n=er(n)?n:jn(n)).length;ao&&(o=e);else r=qn(r,t),jr(n,(function(n,t,e){((u=r(n,t,e))>i||u===-1/0&&o===-1/0)&&(o=n,i=u)}));return o}function Tr(n,r,t){if(null==r||t)return er(n)||(n=jn(n)),n[Wn(n.length-1)];var e=er(n)?En(n):jn(n),u=Y(e);r=Math.max(Math.min(r,u),0);for(var o=u-1,i=0;i1&&(e=Fn(e,r[1])),r=an(n)):(e=qr,r=ur(r,!1,!1),n=Object(n));for(var u=0,o=r.length;u1&&(t=r[1])):(r=_r(ur(r,!1,!1),String),e=function(n,t){return!Er(r,t)}),Ur(n,e,t)}));function zr(n,r,t){return i.call(n,0,Math.max(0,n.length-(null==r||t?1:r)))}function Lr(n,r,t){return null==n||n.length<1?null==r||t?void 0:[]:null==r||t?n[0]:zr(n,n.length-r)}function $r(n,r,t){return i.call(n,null==r||t?1:r)}var Cr=j((function(n,r){return r=ur(r,!0,!0),Sr(n,(function(n){return!Er(r,n)}))})),Kr=j((function(n,r){return Cr(n,r)}));function Jr(n,r,t,e){A(r)||(e=t,t=r,r=!1),null!=t&&(t=qn(t,e));for(var u=[],o=[],i=0,a=Y(n);ir?(e&&(clearTimeout(e),e=null),a=c,i=n.apply(u,o),e||(u=o=null)):e||!1===t.trailing||(e=setTimeout(f,l)),i};return c.cancel=function(){clearTimeout(e),a=0,e=u=o=null},c},debounce:function(n,r,t){var e,u,o,i,a,f=function(){var c=zn()-u;r>c?e=setTimeout(f,r-c):(e=null,t||(i=n.apply(a,o)),e||(o=a=null))},c=j((function(c){return a=this,o=c,u=zn(),e||(e=setTimeout(f,r),t&&(i=n.apply(a,o))),i}));return c.cancel=function(){clearTimeout(e),e=o=a=null},c},wrap:function(n,r){return rr(r,n)},negate:fr,compose:function(){var n=arguments,r=n.length-1;return function(){for(var t=r,e=n[r].apply(this,arguments);t--;)e=n[t].call(this,e);return e}},after:function(n,r){return function(){if(--n<1)return r.apply(this,arguments)}},before:cr,once:lr,findKey:sr,findIndex:vr,findLastIndex:hr,sortedIndex:yr,indexOf:gr,lastIndexOf:br,find:mr,detect:mr,findWhere:function(n,r){return mr(n,Dn(r))},each:jr,forEach:jr,map:_r,collect:_r,reduce:Ar,foldl:Ar,inject:Ar,reduceRight:xr,foldr:xr,filter:Sr,select:Sr,reject:function(n,r,t){return Sr(n,fr(qn(r)),t)},every:Or,all:Or,some:Mr,any:Mr,contains:Er,includes:Er,include:Er,invoke:Br,pluck:Nr,where:function(n,r){return Sr(n,Dn(r))},max:Ir,min:function(n,r,t){var e,u,o=1/0,i=1/0;if(null==r||"number"==typeof r&&"object"!=typeof n[0]&&null!=n)for(var a=0,f=(n=er(n)?n:jn(n)).length;ae||void 0===t)return 1;if(t - - Tutorial — ONNX Runtime 1.7.0 documentation - - + + + Tutorial — ONNX Runtime 1.11.0 documentation + + - - - - - + + + + + @@ -37,7 +38,7 @@
      -
      +

      Tutorial

      ONNX Runtime provides an easy way to run machine learned models with high performance on CPU or GPU @@ -56,7 +57,7 @@

      Tutorial +

      Step 1: Train a model using your favorite framework

      We’ll use the famous iris datasets.

      <<<

      @@ -69,15 +70,15 @@

      Tutorialfrom sklearn.linear_model import LogisticRegression clr = LogisticRegression() clr.fit(X_train, y_train) -print(clr) +print(clr)

      >>>

          LogisticRegression()
       
      -
      - -
      + +

      Step 3: Load and run the model using ONNX Runtime

      We will use ONNX Runtime to compute the predictions for this machine learning model.

      -

      Note: The next release (ORT 1.10) will require explicitly setting -the providers parameter if you want to use execution providers other -than the default CPU provider (as opposed to the current behavior of -providers getting set/registered by default based on the build flags) when -instantiating InferenceSession. Following code assumes NVIDIA GPU is available, -you can specify other execution providers or don't include providers parameter -to use default CPU provider.

      <<<

      import numpy
      -import onnxruntime as rt
      +import onnxruntime as rt
       
      -sess = rt.InferenceSession("logreg_iris.onnx", providers=["CUDAExecutionProvider"])
      +sess = rt.InferenceSession(
      +    "logreg_iris.onnx", providers=rt.get_available_providers())
       input_name = sess.get_inputs()[0].name
      -pred_onx = sess.run(None, {input_name: X_test.astype(numpy.float32)})[0]
      -print(pred_onx)
      +pred_onx = sess.run(None, {input_name: X_test.astype(numpy.float32)})[0]
      +print(pred_onx)
       

      >>>

      -
      +
      @@ -187,7 +183,7 @@

      Related Topics

      Quick search

      @@ -209,7 +205,7 @@

      Quick search

      ©2018-2021, Microsoft. | - Powered by
      Sphinx 3.5.1 + Powered by Sphinx 4.3.2 & Alabaster 0.7.12 |