Turi Create  4.0
utils.hpp
1 #ifndef TURI_ANNOTATIONS_UTILS_HPP
2 #define TURI_ANNOTATIONS_UTILS_HPP
3 
4 #include "build/format/cpp/annotate.pb.h"
5 #include "build/format/cpp/data.pb.h"
6 #include "build/format/cpp/message.pb.h"
7 #include "build/format/cpp/meta.pb.h"
8 
9 #include <toolkits/image_deep_feature_extractor/image_deep_feature_extractor_toolkit.hpp>
10 
11 #include <boost/regex.hpp>
12 #include <memory>
13 #include <core/data/sframe/gl_sarray.hpp>
14 #include <core/storage/sframe_interface/unity_sarray.hpp>
15 #include <vector>
16 
17 namespace annotate_spec = TuriCreate::Annotation::Specification;
18 
19 namespace turi {
20 namespace annotate {
21 
22 template <typename T>
23 typename std::enable_if<
24  std::is_same<T, annotate_spec::Annotations>::value>::type
25 populate_parcel(annotate_spec::Parcel &parcel, T message) {
26  parcel.mutable_annotations()->CopyFrom(message);
27 }
28 
29 template <typename T>
30 typename std::enable_if<std::is_same<T, annotate_spec::Data>::value>::type
31 populate_parcel(annotate_spec::Parcel &parcel, T message) {
32  parcel.mutable_data()->CopyFrom(message);
33 }
34 
35 template <typename T>
36 typename std::enable_if<std::is_same<T, annotate_spec::MetaData>::value>::type
37 populate_parcel(annotate_spec::Parcel &parcel, T message) {
38  parcel.mutable_metadata()->CopyFrom(message);
39 }
40 
41 template <typename T>
42 typename std::enable_if<
43  std::is_same<T, annotate_spec::ProgressMeta>::value>::type
44 populate_parcel(annotate_spec::Parcel &parcel, T message) {
45  parcel.mutable_progress()->CopyFrom(message);
46 }
47 
48 template <typename T>
49 typename std::enable_if<
50  std::is_same<T, annotate_spec::Similarity>::value>::type
51 populate_parcel(annotate_spec::Parcel &parcel, T message) {
52  parcel.mutable_similarity()->CopyFrom(message);
53 }
54 
55 float vectors_distance(const std::vector<double> &a,
56  const std::vector<double> &b);
57 
58 bool is_integer(std::string s);
59 
60 std::vector<flexible_type> similar_items(const gl_sarray &distances,
61  size_t index, size_t k);
62 
63 #ifdef __APPLE__
64 
65 image_deep_feature_extractor::image_deep_feature_extractor_toolkit
66 create_feature_extractor(std::string base_directory = "./");
67 
68 gl_sarray featurize_images(const gl_sarray &images,
69  std::string base_directory = "./");
70 #endif
71 
72 } // namespace annotate
73 } // namespace turi
74 
75 #endif