IVaps.helpers¶
Helper functions
Functions
|
Check successful conversion of ONNX model |
|
Convert pickle test data file to ONNX .pb files. |
|
Convenience function to quickly convert and save ONNX model with expected input/output settings |
|
Return mean of every S rows |
|
Return mean of every S rows for every delta |
|
Convenience function to execute ONNX inference with an optional post-inference function |
|
Standardize 2D array of variables |
- IVaps.helpers.check_conversion(model_path: str, onnx_model_path: str, framework: str, test_input_path: Optional[str] = None, tf_input_names: Optional[Sequence] = None, tf_output_names: Optional[Sequence] = None, log_path: Optional[str] = None)[source]¶
Check successful conversion of ONNX model
- Parameters
model_path (str) – Path to original saved model
onnx_model_path (str) – Path to converted ONNX model
framework (str) – Reference string for one of the implemented frameworks
test_input_path (str, default: None) – Path to folder with saved .pb test inputs
tf_input_names (Sequence, default: None) – Names of inputs for Tensorflow model, if applicable
tf_output_names (Sequence, default: None) – Names of outputs for Tensorflow model, if applicable
log_path (str, default: None) – Path to save test results
- Returns
True if model passses all checks
- Return type
bool
- IVaps.helpers.convert_data_to_pb(pickle_path: str, output_folder: str = 'test_data_set_0', is_input=True)[source]¶
Convert pickle test data file to ONNX .pb files.
- Parameters
pickle_path (str) – The path to your pickle file. The pickle file should contain a dictionary with the following format: { input_name_1: test_data_1, input_name_2: test_data_2, … }
output_folder (str, default: “test_data_set_0”) – The folder to store .pb files. The folder should be empty and its name starts with test_data_*.
- IVaps.helpers.convert_to_onnx(model, framework: str, dummy_input1=None, dummy_input2=None, output_path: Optional[str] = None, input_names: Tuple[str, str] = ('c_inputs', 'd_inputs'), output_names: Optional[Sequence] = None, tf_input_names: Optional[Sequence] = None, tf_output_names: Optional[Sequence] = None, target_opset: Optional[int] = None, **kwargs)[source]¶
Convenience function to quickly convert and save ONNX model with expected input/output settings
- Parameters
model (object) – fitted model object (or path to saved model in Tensorflow case)
framework (str) – Reference string for one of the implemented frameworks
dummy_input1 (list-like, default: None) – Dummy input for first model input used for type inference and passed into downstream conversion functions
dummy_input2 (list-like, default: None) – Dummy input for second model input (if applicable) used for type inference and passed into downstream conversion functions
output_path (str, default: None) – path to save ONNX model
input_names (Tuple[str, str], default: (“c_inputs”, “d_inputs”)) – input names to assign ONNX model
output_names (list-like, default: None) – output names for later ONNX inference; if None defaults to naming the outputs sequentially “output_1”, “output_2”, etc…
tf_input_names (list-like, default: None) – Input names for Tensorflow graph. Only required when converting from Tensorflow using a frozen graph or checkpoints.
tf_output_names (list-like, default: None) – Output names for Tensorflow graph. Only required when converting from Tensorflow using a frozen graph or checkpoints.
**kwargs (keyword arguments to be passed into mltools conversion function)
- Returns
Converted ONNX model or boolean flag indicating successful conversion, depending on specific framework.
- Return type
Object
- IVaps.helpers.run_onnx_session(inputs: Sequence[numpy.ndarray], sess: onnxruntime.capi.onnxruntime_inference_collection.InferenceSession, input_names: Sequence[str], label_names: Optional[Sequence[str]] = None, fcn=None, **kwargs)[source]¶
Convenience function to execute ONNX inference with an optional post-inference function
- Parameters
inputs (Sequence of array-likes) – ONNX inference inputs
sess (onnxruntime InferenceSession)
input_names (Sequence of strings) – Input names to assign to inputs
label_names (Sequence of strings, default: all outputs) – Specific outputs to return from inference
fcn (Object, default: None) – Vectorized function to pass inference outputs through
**kwargs (additional arguments to pass into fcn)
- Returns
Outputs of ONNX inference or post-inference function
- Return type
np.ndarray