1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #import <CoreML/CoreML.h> 16 17 #include <string> 18 #include <vector> 19 20 #include "mlmodel/format/Model.pb.h" 21 22 // Data for input/output tensors. 23 struct TensorData { 24 std::vector<float> data; 25 const std::string name; 26 std::vector<int> shape; // only required for input tensor. 27 }; 28 29 // Responsible for: 30 // - Compiling and constructing MLModel from a serialized MlModel 31 // protocol buffer. 32 // - Invoking predictions on the built model. 33 // Usage: Construct object, call Build() and Invoke() for inference. 34 @interface CoreMlExecutor : NSObject 35 36 - (bool)invokeWithInputs:(const std::vector<TensorData>&)inputs 37 outputs:(const std::vector<TensorData>&)outputs API_AVAILABLE(ios(11)); 38 39 - (NSURL*)saveModel:(CoreML::Specification::Model*)model API_AVAILABLE(ios(11)); 40 - (bool)build:(NSURL*)modelUrl API_AVAILABLE(ios(11)); 41 42 - (bool)cleanup; 43 44 @property MLModel* model API_AVAILABLE(ios(11)); 45 @property NSString* mlModelFilePath; 46 @property NSString* compiledModelFilePath; 47 @property(nonatomic, readonly) int coreMlVersion; 48 @end 49