|
23 | 23 | #include "core/providers/coreml/builders/helper.h"
|
24 | 24 | #include "core/providers/coreml/coreml_provider_factory.h"
|
25 | 25 | #include "core/providers/coreml/model/host_utils.h"
|
| 26 | +#include "core/providers/coreml/model/objc_str_utils.h" |
26 | 27 | #include "core/providers/coreml/shape_utils.h"
|
27 | 28 |
|
28 | 29 | // force the linker to create a dependency on the CoreML framework so that in MAUI usage we don't need
|
|
33 | 34 | using namespace onnxruntime::coreml;
|
34 | 35 |
|
35 | 36 | namespace {
|
36 |
| -// Converts a UTF8 const char* to an NSString. Throws on failure. |
37 |
| -NSString* _Nonnull Utf8StringToNSString(const char* utf8_str) { |
38 |
| - NSString* result = [NSString stringWithUTF8String:utf8_str]; |
39 |
| - ORT_ENFORCE(result != nil, "NSString conversion failed."); |
40 |
| - return result; |
41 |
| -} |
42 |
| - |
43 | 37 | /**
|
44 | 38 | * Computes the static output shape used to allocate the output tensor.
|
45 | 39 | * `inferred_shape` is the inferred shape known at model compile time. It may contain dynamic dimensions (-1).
|
@@ -165,7 +159,7 @@ Status CreateInputFeatureProvider(const std::unordered_map<std::string, OnnxTens
|
165 | 159 | (error != nil) ? MakeString(", error: ", [[error localizedDescription] UTF8String]) : "");
|
166 | 160 |
|
167 | 161 | MLFeatureValue* feature_value = [MLFeatureValue featureValueWithMultiArray:multi_array];
|
168 |
| - NSString* feature_name = Utf8StringToNSString(name.c_str()); |
| 162 | + NSString* feature_name = util::Utf8StringToNSString(name.c_str()); |
169 | 163 | feature_dictionary[feature_name] = feature_value;
|
170 | 164 | }
|
171 | 165 |
|
@@ -270,7 +264,7 @@ - (instancetype)initWithPath:(const std::string&)path
|
270 | 264 | logger:(const logging::Logger&)logger
|
271 | 265 | coreml_flags:(uint32_t)coreml_flags {
|
272 | 266 | if (self = [super init]) {
|
273 |
| - coreml_model_path_ = [NSString stringWithUTF8String:path.c_str()]; |
| 267 | + coreml_model_path_ = util::Utf8StringToNSString(path.c_str()); |
274 | 268 | logger_ = &logger;
|
275 | 269 | coreml_flags_ = coreml_flags;
|
276 | 270 | }
|
@@ -371,7 +365,7 @@ - (Status)predict:(const std::unordered_map<std::string, OnnxTensorData>&)inputs
|
371 | 365 |
|
372 | 366 | for (const auto& [output_name, output_tensor_info] : outputs) {
|
373 | 367 | MLFeatureValue* output_value =
|
374 |
| - [output_features featureValueForName:Utf8StringToNSString(output_name.c_str())]; |
| 368 | + [output_features featureValueForName:util::Utf8StringToNSString(output_name.c_str())]; |
375 | 369 |
|
376 | 370 | if (output_value == nil) {
|
377 | 371 | return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "output_features has no value for ", output_name);
|
|
0 commit comments