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
//! 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!(
/// A compiled model asset.
///
/// `MLModelAsset` is an abstraction of a compiled model, which can be:
///
/// - `.mlmodelc` bundle on the file system
/// - In-memory model specification
///
/// It provides the unified interface to query the model description and to instantiate `MLModel`.
///
/// ```swift
/// // Creates an object.
/// let modelAsset = MLModelAsset(url: modelURL)
///
/// // Query the model description
/// let description = try await modelAsset.modelDescription
///
/// // Query the list of functions in the model asset.
/// let functionNames = try await modelAsset.functionNames
///
/// // Query the model description of a specific function.
/// let descriptionOfMyFunction = try await modelAsset.modelDescription(of: "MyFunction")
///
/// // Instantiate `MLModel` for "MyFunction".
/// let modelConfiguration = MLModelConfiguration()
/// modelConfiguration.functionName = "MyFunction"
/// let model = try await MLModel.load(asset: modelAsset, configuration: modelConfiguration)
/// ```
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/coreml/mlmodelasset?language=objc)
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MLModelAsset;
);
extern_conformance!(
unsafe impl NSObjectProtocol for MLModelAsset {}
);
impl MLModelAsset {
extern_methods!(
/// Construct a model asset from the contents of specification data.
///
/// - Parameters:
/// - specificationData: Contents of .mlmodel as a data blob.
/// - error: When the model asset creation fails error is populated with the reason for failure.
#[unsafe(method(modelAssetWithSpecificationData:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn modelAssetWithSpecificationData_error(
specification_data: &NSData,
) -> Result<Retained<Self>, Retained<NSError>>;
/// Construct a model asset from an ML Program specification by replacing blob file references with corresponding in-memory blobs.
///
/// An ML Program may use `BlobFileValue` syntax, which stores the blob data in external files and refers them by URL.
/// This factory method enables in-memory workflow for such models by using the specified in-memory blob data in place of the external files.
///
/// The format of in-memory blobs must be the same as the external files. The dictionary must contain all the reference URLs used in the specification.
///
/// - Parameters:
/// - specification: Contents of .mlmodel as a data blob.
/// - blobMapping: A dictionary with blob URL as the key and blob data as the value.
/// - error: When the model asset creation fails error is populated with the reason for failure.
#[unsafe(method(modelAssetWithSpecificationData:blobMapping:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn modelAssetWithSpecificationData_blobMapping_error(
specification_data: &NSData,
blob_mapping: &NSDictionary<NSURL, NSData>,
) -> Result<Retained<Self>, Retained<NSError>>;
/// Constructs a ModelAsset from a compiled model URL.
///
/// - Parameters:
/// - compiledModelURL: Location on the disk where the model asset is present.
/// - error: Errors if the model asset is not loadable.
///
/// - Returns: a model asset or nil if there is an error.
#[unsafe(method(modelAssetWithURL:error:_))]
#[unsafe(method_family = none)]
pub unsafe fn modelAssetWithURL_error(
compiled_model_url: &NSURL,
) -> Result<Retained<Self>, Retained<NSError>>;
#[cfg(all(feature = "MLModelDescription", feature = "block2"))]
/// The default model descripton.
///
/// Use this method to get the description of the model such as the feature descriptions, the model author, and other metadata.
///
/// For the multi-function model asset, this method vends the description for the default function. Use `modelDescription(for:)` to get the model description of other functions.
///
/// ```swift
/// let modelAsset = try MLModelAsset(url: modelURL)
/// let modelDescription = try await modelAsset.modelDescription()
/// print(modelDescription)
/// ```
#[unsafe(method(modelDescriptionWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn modelDescriptionWithCompletionHandler(
&self,
handler: &block2::DynBlock<dyn Fn(*mut MLModelDescription, *mut NSError)>,
);
#[cfg(all(feature = "MLModelDescription", feature = "block2"))]
/// The model descripton for a specified function.
///
/// Use this method to get the description of the model such as the feature descriptions, the model author, and other metadata.
///
/// ```swift
/// let modelAsset = try MLModelAsset(url: modelURL)
/// let modelDescription = try await modelAsset.modelDescription(of: "my_function")
/// print(modelDescription)
/// ```
#[unsafe(method(modelDescriptionOfFunctionNamed:completionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn modelDescriptionOfFunctionNamed_completionHandler(
&self,
function_name: &NSString,
handler: &block2::DynBlock<dyn Fn(*mut MLModelDescription, *mut NSError)>,
);
#[cfg(feature = "block2")]
/// The list of function names in the model asset.
///
/// Some model types (e.g. ML Program) supports multiple functions. Use this method to query the function names.
///
/// The method vends the empty array when the model doesn't use the multi-function configuration.
///
/// ```swift
/// let modelAsset = try MLModelAsset(url: modelURL)
/// let functionNames = try await modelAsset.functionNames
/// print(functionNames) // For example, ["my_function1", "my_function2"];
/// ```
#[unsafe(method(functionNamesWithCompletionHandler:))]
#[unsafe(method_family = none)]
pub unsafe fn functionNamesWithCompletionHandler(
&self,
handler: &block2::DynBlock<dyn Fn(*mut NSArray<NSString>, *mut NSError)>,
);
#[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>;
);
}