MCPcopy Create free account
hub / github.com/apple/coremltools / __init__

Method __init__

coremltools/models/_compiled_model.py:54–137  ·  view source on GitHub ↗

Loads a compiled Core ML model. Parameters ---------- path : str The path to a compiled model directory, ending in ``.mlmodelc``. compute_units : coremltools.ComputeUnit An enum with the following possible values: - `

(
        self,
        path: str,
        compute_units: _ComputeUnit = _ComputeUnit.ALL,
        function_name: _Optional[str] = None,
        optimization_hints: _Optional[dict] = None,
        asset: _Optional[_MLModelAsset] = None,
    )

Source from the content-addressed store, hash-verified

52 _verify_optimization_hint_input(optimization_hints)
53
54 def __init__(
55 self,
56 path: str,
57 compute_units: _ComputeUnit = _ComputeUnit.ALL,
58 function_name: _Optional[str] = None,
59 optimization_hints: _Optional[dict] = None,
60 asset: _Optional[_MLModelAsset] = None,
61 ):
62 """
63 Loads a compiled Core ML model.
64
65 Parameters
66 ----------
67 path : str
68 The path to a compiled model directory, ending in ``.mlmodelc``.
69
70 compute_units : coremltools.ComputeUnit
71 An enum with the following possible values:
72 - ``coremltools.ComputeUnit.ALL``: Use all compute units available, including the
73 neural engine.
74 - ``coremltools.ComputeUnit.CPU_ONLY``: Limit the model to only use the CPU.
75 - ``coremltools.ComputeUnit.CPU_AND_GPU``: Use both the CPU and GPU, but not the
76 neural engine.
77 - ``coremltools.ComputeUnit.CPU_AND_NE``: Use both the CPU and neural engine, but
78 not the GPU. Available only for macOS >= 13.0.
79
80 optimization_hints : dict or None
81 Keys are the names of the optimization hint: 'allowLowPrecisionAccumulationOnGPU', 'reshapeFrequency'
82 or 'specializationStrategy'.
83
84 - 'allowLowPrecisionAccumulationOnGPU' value must have ``bool`` type.
85 - 'reshapeFrequency' value must have ``coremltools.ReshapeFrequency`` type.
86 - 'specializationStrategy' must have``coremltools.SpecializationStrategy`` type.
87
88 asset : MLModelAsset or None
89 The model asset.
90
91 Examples
92 --------
93 .. sourcecode:: python
94
95 my_compiled_model = ct.models.CompiledMLModel("my_model_path.mlmodelc")
96 y = my_compiled_model.predict({"x": 3})
97
98 See Also
99 --------
100 predict
101 """
102 if function_name is None:
103 function_name = ""
104
105 self._init_check(
106 path=path,
107 asset=asset,
108 compute_units=compute_units,
109 function_name=function_name,
110 optimization_hints=optimization_hints,
111 )

Callers

nothing calls this directly

Calls 5

_init_checkMethod · 0.95
isinstanceFunction · 0.85
strClass · 0.50
copyMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected