1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
use objc2_foundation::*;
use crate::*;
extern_class!(
/// MLModel
///
/// Construct a model and evaluate on a specific set of input features.
/// Inputs and outputs are accessed via the MLFeatureProvider protocol.
/// Returns a model or nil if there is an error.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodel?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MLModel;
);
extern_conformance!(
unsafe impl NSObjectProtocol for MLModel {}
);
impl MLModel {
extern_methods!(
#[cfg(feature = "MLModelDescription")]
/// A model holds a description of its required inputs and expected outputs.
#[unsafe(method(modelDescription))]
#[unsafe(method_family = none)]
pub unsafe fn modelDescription(&self) -> Retained<MLModelDescription>;
#[cfg(feature = "MLModelConfiguration")]
/// The load-time parameters used to instantiate this MLModel object.
#[unsafe(method(configuration))]
#[unsafe(method_family = none)]
pub unsafe fn configuration(&self) -> Retained<MLModelConfiguration>;
/// Construct a model with a default MLModelConfiguration object
#[unsafe(method(modelWithContentsOfURL:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn modelWithContentsOfURL_error(
url: &NSURL,
) -> Result<Retained<Self>, Retained<NSError>>;
#[cfg(feature = "MLModelConfiguration")]
/// Construct a model given the location of its on-disk representation. Returns nil on error.
#[unsafe(method(modelWithContentsOfURL:configuration:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn modelWithContentsOfURL_configuration_error(
url: &NSURL,
configuration: &MLModelConfiguration,
) -> Result<Retained<Self>, Retained<NSError>>;
#[cfg(all(feature = "MLModelConfiguration", feature = "block2"))]
/// Construct a model asynchronously given the location of its on-disk representation and configuration.
///
/// Model loading may take time when the model content is not immediately available (e.g. encrypted model). Use this factory method especially when the caller is on the main thread.
///
///
/// Parameter `url`: the location of its on-disk representation (.mlmodelc directory).
///
/// Parameter `configuration`: The model configuration
///
/// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
#[unsafe(method(loadContentsOfURL:configuration:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadContentsOfURL_configuration_completionHandler(
url: &NSURL,
configuration: &MLModelConfiguration,
handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
);
#[cfg(feature = "MLFeatureProvider")]
/// Run a prediction on a model synchronously.
///
/// This is a convenience overload method of `prediction(from:options:)` that uses the default prediction options.
///
/// - Parameters
/// - input: The input features to make a prediction from.
/// - error: The output parameter to be filled with error information on failure.
/// - Returns: The output features from the prediction.
#[unsafe(method(predictionFromFeatures:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_error(
&self,
input: &ProtocolObject<dyn MLFeatureProvider>,
) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
#[cfg(all(feature = "MLFeatureProvider", feature = "MLPredictionOptions"))]
/// Run a prediction on a model synchronously
///
/// - Parameters
/// - input: The input features to make a prediction from.
/// - options: Prediction options to modify how the prediction is run.
/// - error: The output parameter to be filled with error information on failure.
/// - Returns: The output features from the prediction.
#[unsafe(method(predictionFromFeatures:options:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_options_error(
&self,
input: &ProtocolObject<dyn MLFeatureProvider>,
options: &MLPredictionOptions,
) -> Result<Retained<ProtocolObject<dyn MLFeatureProvider>>, Retained<NSError>>;
#[cfg(all(feature = "MLFeatureProvider", feature = "block2"))]
/// Run a prediction on a model asynchronously.
///
/// This is a convenience overload method of `prediction(from:options:) async` that uses the default prediction options.
///
/// - Parameters
/// - input: The input features to make a prediction from.
/// - completionHandler: A block that will be invoked once the prediction has completed successfully or unsuccessfully. On success, it is invoked with a valid model output. On failure, it is invoked with a nil output and NSError
#[unsafe(method(predictionFromFeatures:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_completionHandler(
&self,
input: &ProtocolObject<dyn MLFeatureProvider>,
completion_handler: &block2::DynBlock<
dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
>,
);
#[cfg(all(
feature = "MLFeatureProvider",
feature = "MLPredictionOptions",
feature = "block2"
))]
/// Run a prediction on a model asynchronously.
///
/// - Parameters
/// - input: The input features to make a prediction from.
/// - options: Prediction options to modify how the prediction is run.
/// - completionHandler: A block that will be invoked once the prediction has completed successfully or unsuccessfully. On success, it is invoked with a valid model output. On failure, it is invoked with a nil output and NSError
#[unsafe(method(predictionFromFeatures:options:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn predictionFromFeatures_options_completionHandler(
&self,
input: &ProtocolObject<dyn MLFeatureProvider>,
options: &MLPredictionOptions,
completion_handler: &block2::DynBlock<
dyn Fn(*mut ProtocolObject<dyn MLFeatureProvider>, *mut NSError),
>,
);
#[cfg(feature = "MLBatchProvider")]
/// Batch prediction without explicit options
#[unsafe(method(predictionsFromBatch:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionsFromBatch_error(
&self,
input_batch: &ProtocolObject<dyn MLBatchProvider>,
) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;
#[cfg(all(feature = "MLBatchProvider", feature = "MLPredictionOptions"))]
/// Batch prediction with explicit options
#[unsafe(method(predictionsFromBatch:options:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn predictionsFromBatch_options_error(
&self,
input_batch: &ProtocolObject<dyn MLBatchProvider>,
options: &MLPredictionOptions,
) -> Result<Retained<ProtocolObject<dyn MLBatchProvider>>, Retained<NSError>>;
#[cfg(all(feature = "MLKey", feature = "MLParameterKey"))]
/// Provides value for the given parameter. Returns nil on error.
#[unsafe(method(parameterValueForKey:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn parameterValueForKey_error(
&self,
key: &MLParameterKey,
) -> Result<Retained<AnyObject>, Retained<NSError>>;
#[cfg(all(
feature = "MLModelAsset",
feature = "MLModelConfiguration",
feature = "block2"
))]
/// Construct a model asynchronously from a compiled model asset.
///
///
/// Parameter `asset`: Compiled model asset derived from in-memory or on-disk Core ML model
///
/// Parameter `configuration`: Model configuration that hold options for loading a model
///
/// Parameter `handler`: When the model load completes successfully or unsuccessfully, the completion handler is invoked with a valid MLModel instance or NSError object.
#[unsafe(method(loadModelAsset:configuration:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn loadModelAsset_configuration_completionHandler(
asset: &MLModelAsset,
configuration: &MLModelConfiguration,
handler: &block2::DynBlock<dyn Fn(*mut MLModel, *mut NSError)>,
);
);
}
/// Methods declared on superclass `NSObject`.
impl MLModel {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new() -> Retained<Self>;
);
}