Turi Create  4.0
neural_net_models_exporter.hpp
1 /* Copyright © 2018 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at
5  * https://opensource.org/licenses/BSD-3-Clause
6  */
7 #ifndef UNITY_TOOLKITS_COREML_EXPORT_NEURAL_NETS_MODELS_EXPORTER_HPP_
8 #define UNITY_TOOLKITS_COREML_EXPORT_NEURAL_NETS_MODELS_EXPORTER_HPP_
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 
14 #include <core/data/flexible_type/flexible_type.hpp>
15 #include <ml/neural_net/model_spec.hpp>
16 #include <toolkits/coreml_export/mlmodel_include.hpp>
17 #include <toolkits/coreml_export/mlmodel_wrapper.hpp>
18 
19 namespace turi {
20 
21 std::string iou_threshold_description(float default_value);
22 std::string confidence_threshold_description(float default_value);
23 
24 void set_threshold_array_feature(CoreML::Specification::FeatureDescription* feature_desc,
25  std::string name, std::string short_description,
26  const std::vector<size_t>& shape, float value);
27 
28 void set_array_feature(CoreML::Specification::FeatureDescription* feature_desc, std::string name,
29  std::string short_description, const std::vector<size_t>& shape);
30 
31 /**
32  * Wraps a trained object detector model_spec as a complete MLModel.
33  *
34  * \param nn_spec The NeuralNetwork to wrap, which must accept an input "image"
35  * with shape (3, image_height, image_width) and values in [0,1],
36  * output "confidence" with shape (num_predictions, num_classes),
37  * and "coordinates" with shape (num_predictions, 4).
38  * \todo Should model_spec include Model, not NeuralNetwork, so that the client
39  * is responsible for populating the inputs and outputs?
40  */
41 std::shared_ptr<coreml::MLModelWrapper> export_object_detector_model(
42  neural_net::pipeline_spec pipeline, size_t num_classes, size_t num_predictions,
43  flex_list class_labels, float confidence_threshold, float iou_threshold,
44  bool include_non_maximum_suppression, bool use_nms_layer, bool use_most_confident_class);
45 
46 /** Wraps a trained activity classifier model_spec as a complete MLModel. */
47 std::shared_ptr<coreml::MLModelWrapper> export_activity_classifier_model(
48  const neural_net::model_spec& nn_spec, size_t prediction_window,
49  const flex_list& features, size_t lstm_hidden_layer_size,
50  const flex_list& class_labels, const flex_string& target);
51 
52 /** Wraps a trained style transfer model_spec as a complete MLModel. */
53 std::shared_ptr<coreml::MLModelWrapper> export_style_transfer_model(
54  const neural_net::model_spec& nn_spec, size_t image_width,
55  size_t image_height, bool include_flexible_shape,
56  std::string content_feature, std::string style_feature, size_t num_styles);
57 
58 /** Wraps a trained drawing classifier model_spec as a complete MLModel. */
59 std::shared_ptr<coreml::MLModelWrapper> export_drawing_classifier_model(
60  const neural_net::model_spec& nn_spec, const flex_list& features,
61  const flex_list& class_labels, const flex_string& target);
62 
63 } // namespace turi
64 
65 #endif // UNITY_TOOLKITS_COREML_EXPORT_NEURAL_NETS_MODELS_EXPORTER_HPP_
std::shared_ptr< coreml::MLModelWrapper > export_object_detector_model(neural_net::pipeline_spec pipeline, size_t num_classes, size_t num_predictions, flex_list class_labels, float confidence_threshold, float iou_threshold, bool include_non_maximum_suppression, bool use_nms_layer, bool use_most_confident_class)
std::shared_ptr< coreml::MLModelWrapper > export_drawing_classifier_model(const neural_net::model_spec &nn_spec, const flex_list &features, const flex_list &class_labels, const flex_string &target)
std::shared_ptr< coreml::MLModelWrapper > export_activity_classifier_model(const neural_net::model_spec &nn_spec, size_t prediction_window, const flex_list &features, size_t lstm_hidden_layer_size, const flex_list &class_labels, const flex_string &target)
std::string flex_string
std::shared_ptr< coreml::MLModelWrapper > export_style_transfer_model(const neural_net::model_spec &nn_spec, size_t image_width, size_t image_height, bool include_flexible_shape, std::string content_feature, std::string style_feature, size_t num_styles)
std::vector< flexible_type > flex_list