CoreML integration for iOS.
Provides an Elixir API for Apple's CoreML framework via NIF calls. CoreML uses the Apple Neural Engine (ANE) for hardware-accelerated ML inference on iOS devices and simulators.
All NIF functions run on the dirty CPU scheduler.
Prerequisites
- iOS device or simulator
- CoreML model file (.mlmodel or .mlpackage)
Usage
# Load a model
:ok = Dala.ML.CoreML.load_model("/path/to/model.mlmodel", "my_model")
# Check if loaded
true = Dala.ML.CoreML.loaded?("my_model")
# Make prediction
{:ok, result_json} = Dala.ML.CoreML.predict("my_model", %{
"input": [1.0, 2.0, 3.0]
})
# Unload when done
:ok = Dala.ML.CoreML.unload_model("my_model")
Summary
Functions
Loads a CoreML model from the given path.
Checks if a model is loaded.
Lists all loaded model identifiers.
Makes a prediction using a loaded model.
Run prediction on an already-loaded model.
Unloads a previously loaded model.
Functions
Loads a CoreML model from the given path.
Parameters
model_path: Path to the .mlmodel or .mlpackage fileidentifier: A unique identifier for this model
Returns
:okon success{:error, reason}on failure:not_supportedon non-iOS platforms
Checks if a model is loaded.
Returns true if loaded, false otherwise.
Returns false on non-iOS platforms.
@spec loaded_models() :: [String.t()]
Lists all loaded model identifiers.
Makes a prediction using a loaded model.
Parameters
identifier: The model identifierinputs: A map of input names to values (numbers, strings, lists)
Returns
{:ok, result_json}on success{:error, reason}on failure:not_supportedon non-iOS platforms
@spec predict_with_loaded_model(String.t(), map()) :: {:ok, String.t()} | {:error, term()} | :not_supported
Run prediction on an already-loaded model.
Unlike load_model/2 + predict/2, this does NOT load the model.
The model must be loaded first via load_model/2.
@spec unload_model(String.t()) :: :ok | :not_supported
Unloads a previously loaded model.