Turi Create  4.0
image_feature_extractor.hpp
1 /* Copyright © 2017 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 https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef IMAGE_FEATURE_EXTRACTOR_HPP
7 #define IMAGE_FEATURE_EXTRACTOR_HPP
8 
9 #include <core/data/sframe/gl_sarray.hpp>
10 #include <toolkits/coreml_export/mlmodel_include.hpp>
11 
12 namespace turi {
13 namespace image_deep_feature_extractor {
14 
15 // Interface for classes that can transform an image into a vector of feature
16 // values for training purposes, as well as exporting this transformation to
17 // CoreML.
18 class image_feature_extractor {
19 public:
20  virtual ~image_feature_extractor() = default;
21 
22  // Returns a model specification that performs an equivalent computation when
23  // compiled by CoreML. The model must accept an image as input and produce a
24  // floating-point vector as output.
25  virtual const CoreML::Specification::Model& coreml_spec() const = 0;
26 
27  // Returns an SArray of flex_vec values, representing the features extracted
28  // from each corresponding flex_image in `images`. The extracted features must
29  // match what the compiled CoreML model would produce, but implementations are
30  // free to perform this computation in a more optimized fashion. The input
31  // SArray may also contain flex_string values, in which case each string is
32  // interpreted as a URL from which the image can be loaded.
33  virtual gl_sarray extract_features(gl_sarray images, bool verbose, size_t batch_size) const = 0;
34 };
35 
36 } // image_deep_feature_extractor
37 } // turi
38 
39 #endif // IMAGE_FEATURE_EXTRACTOR_HPP