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

Method __init__

coremltools/models/model.py:369–584  ·  view source on GitHub ↗

Construct an MLModel from an ``.mlmodel``. Parameters ---------- model: str or Model_pb2 For an ML program (``mlprogram``), the model can be a path string (``.mlpackage``) or ``Model_pb2``. If it is a path string, it must point to a director

(
        self,
        model,
        is_temp_package=False,
        mil_program=None,
        skip_model_load=False,
        compute_units=_ComputeUnit.ALL,
        weights_dir=None,
        function_name=None,
        optimization_hints: _Optional[dict] = None,
    )

Source from the content-addressed store, hash-verified

367 """
368
369 def __init__(
370 self,
371 model,
372 is_temp_package=False,
373 mil_program=None,
374 skip_model_load=False,
375 compute_units=_ComputeUnit.ALL,
376 weights_dir=None,
377 function_name=None,
378 optimization_hints: _Optional[dict] = None,
379 ) -> None:
380 """
381 Construct an MLModel from an ``.mlmodel``.
382
383 Parameters
384 ----------
385 model: str or Model_pb2
386
387 For an ML program (``mlprogram``), the model can be a path string (``.mlpackage``) or ``Model_pb2``.
388 If it is a path string, it must point to a directory containing bundle
389 artifacts (such as ``weights.bin``).
390 If it is of type ``Model_pb2`` (spec), then you must also provide ``weights_dir`` if the model
391 has weights, because both the proto spec and the weights are
392 required to initialize and load the model.
393 The proto spec for an ``mlprogram``, unlike a neural network (``neuralnetwork``),
394 does not contain the weights; they are stored separately.
395 If the model does not have weights, you can provide an empty ``weights_dir``.
396
397 For non- ``mlprogram`` model types, the model can be a path string (``.mlmodel``)
398 or type ``Model_pb2``, such as a spec object.
399
400 is_temp_package: bool
401 Set to ``True`` if the input model package dir is temporary and can be deleted upon interpreter termination.
402
403 mil_program: coremltools.converters.mil.Program
404 Set to the MIL program object, if available.
405 It is available whenever an MLModel object is constructed using
406 the unified converter API `coremltools.convert() <https://apple.github.io/coremltools/source/coremltools.converters.convert.html>`_.
407
408 skip_model_load: bool
409 Set to ``True`` to prevent Core ML Tools from calling into the Core ML framework
410 to compile and load the model. In that case, the returned model object cannot
411 be used to make a prediction. This flag may be used to load a newer model
412 type on an older Mac, to inspect or load/save the spec.
413
414 Example: Loading an ML program model type on a macOS 11, since an ML program can be
415 compiled and loaded only from macOS12+.
416
417 Defaults to ``False``.
418
419 compute_units: coremltools.ComputeUnit
420 The set of processing units the model can use to make predictions.
421
422 An enum with four possible values:
423 - ``coremltools.ComputeUnit.ALL``: Use all compute units available, including the
424 neural engine.
425 - ``coremltools.ComputeUnit.CPU_ONLY``: Limit the model to only use the CPU.
426 - ``coremltools.ComputeUnit.CPU_AND_GPU``: Use both the CPU and GPU,

Callers

nothing calls this directly

Calls 15

_get_proxy_and_specMethod · 0.95
_is_multifunctionMethod · 0.95
isinstanceFunction · 0.85
TypeErrorClass · 0.85
_is_macosFunction · 0.85
_create_mlpackageFunction · 0.85
_FeatureDescriptionClass · 0.85
WhichOneofMethod · 0.80
_macos_versionFunction · 0.70

Tested by

no test coverage detected