LEIP Models¶
- class models.Model(options: ModelOptions, framework: Framework, source_file: Optional[Union[str, PathLike]] = None)¶
Abstract class representing an ML model in a supported framework.
- Parameters
options (ModelOptions) –
framework (Framework) –
source_file (Union[str, PathLike]) –
- dict() dict ¶
Gives a serializable dict version of the model. This includes:
- options
The options used to load and configure the model.
- source_file
The name of the source file from which it was loaded, if any.
- source_file_md5_hash
An MD5 hash of the source file.
- source_file_size
Source file size in bytes.
- framework
The framework of the model.
- inputs
A list of input objects with names, shapes and types.
- outputs
A list of output objects with names, shapes and types.
- weights_count
The amount of tensors in the model.
- weights_size
The sum of sizes of all tensors in the model.
- weights_data_type
The data type(s) of the tensors in the model.
- Returns
Options and metrics as a dict.
- Return type
dict
- abstract infer(single_input: ndarray) Tuple[List[ndarray], float] ¶
Runs inference from a numpy array.
- Parameters
single_input (ndarray) – A numpy array that will be sent to the model. The array must be of the right type and shape.
- Returns
list – A list of all the outputs of the model.
float – Number of seconds inference took.
- Return type
Tuple[List[ndarray], float]
- abstract property inputs: List[models.tensors.TensorSpec]¶
Determines the inputs to the model.
- Returns
A list of input objects with names, shapes and types.
- Return type
list
- abstract property outputs: List[models.tensors.TensorSpec]¶
Determines the outputs of the model.
- Returns
A list of output objects with names, shapes and types.
- Return type
list
- abstract property weights: List[models.tensors.Tensor]¶
Determines the tensors of the model.
- Returns
A list of all the tensors in the model.
- Return type
list
- models.load_model(path: Union[str, PathLike], options: ModelOptions = ModelOptions(inference=InferenceOptions(context='cpu', host='localhost', port='50051'), input_names=[], output_names=[], input_shapes=[], remove_nodes=[], custom_objects=None, crc=None, metadata={}, processors_path=None, preprocessor=None, postprocessor=None, output_format='classifier', task_family='classification'), load_baseline_options_from_json: bool = True) Model ¶
Load a supported model from disk.
- Parameters
path (Union[str, PathLike]) – Directory or file path to the model files(s). Alternatively, the name of model which has already been installed on an LOR instance.
options (ModelOptions) – Options to configure the model. These may also come from a model_schema.json file in the same folder as the model files. Any options defined here override those in that file.
load_baseline_options_from_json (bool) – Indicates if model options should also be loaded from model_schema.json file.
- Returns
Loaded model object.
- Return type
- Raises
NotRecognizedModel – If a supported model was not found at the given path, or if the framework needed for it is not installed.
- leip.load_compilable_model(path: Union[str, PathLike], options: ModelOptions = ModelOptions(inference=InferenceOptions(context='cpu', host='localhost', port='50051'), input_names=[], output_names=[], input_shapes=[], remove_nodes=[], custom_objects=None, crc=None, metadata={}, processors_path=None, preprocessor=None, postprocessor=None, output_format='classifier', task_family='classification'), load_baseline_options_from_json: bool = True) CompilableModel ¶
Load a compilable model from disk.
- Parameters
path (Union[str, PathLike]) – Directory or file path to the model files(s).
options (ModelOptions) – Options to configure the model. These may also come from a model_schema.json file in the same folder as the model files. Any options defined here override those in that file.
load_baseline_options_from_json (bool) – Indicates if model options should also be loaded from model_schema.json file.
- Returns
Loaded model object.
- Return type
- Raises
NotRecognizedModel – If a supported model was not found at the given path, or if the framework needed for it is not installed.
- class leip.CompilableModel(options: ModelOptions, framework: Framework, source_file: Optional[Union[str, PathLike]] = None)¶
Abstract class representing a compilable ML model in a supported framework. This class adds additional methods on top of Model that are used when compiling or optimizing a model.
- Parameters
options (ModelOptions) –
framework (Framework) –
source_file (Union[str, PathLike]) –