38 struct make_tensor_view_ {
39 using shape_t = std::vector<std::size_t>;
41 using xt_no_ownership_t =
decltype(xt::no_ownership());
43 using type =
decltype(xt::adapt(std::declval<const T*>(),
44 std::declval<std::size_t>(),
45 std::declval<xt_no_ownership_t>(),
46 std::declval<shape_t>()));
53 using tensor_view =
typename make_tensor_view_<T>::type;
56 static tensor_view<T> make_tensor_view(
const T* data,
58 typename tensor_view<T>::shape_type shape) {
59 return xt::adapt(std::move(data), std::move(size), xt::no_ownership(), std::move(shape));
66 using signed_integral_base_types =
67 boost::mpl::list<std::int8_t, std::int16_t, std::int32_t, std::int64_t>;
69 using unsigned_integral_base_types =
70 boost::mpl::transform_view<signed_integral_base_types,
71 std::make_unsigned<boost::mpl::placeholders::_1>>;
73 using integral_base_types =
74 boost::mpl::joint_view<signed_integral_base_types, unsigned_integral_base_types>;
76 using fp_base_types = boost::mpl::list<float, double>;
78 using base_types = boost::mpl::joint_view<integral_base_types, fp_base_types>;
80 using tensor_view_types =
81 boost::mpl::transform_view<base_types, make_tensor_view_<boost::mpl::placeholders::_1>>;
84 using tensor_views = boost::make_variant_over<tensor_view_types>::type;
87 using named_tensor_views = std::unordered_map<std::string, tensor_views>;
95 inline std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs) {
96 return infer(inputs, {});
107 virtual std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs,
108 const ProtoStruct& extra) = 0;
113 std::string description;
115 enum : std::uint8_t {
116 k_label_type_tensor_value = 0,
117 k_label_type_tensor_axis = 1,
122 std::string description;
124 enum class data_types : std::uint8_t {
137 std::vector<int> shape;
138 std::vector<file> associated_files;
142 static boost::optional<data_types> string_to_data_type(
const std::string& str);
143 static const char* data_type_to_string(data_types data_type);
145 static data_types tensor_views_to_data_type(
const tensor_views& view);
151 std::string description;
152 std::vector<tensor_info> inputs;
153 std::vector<tensor_info> outputs;
std::shared_ptr< named_tensor_views > infer(const named_tensor_views &inputs)
Runs the model against the input tensors and returns inference results as tensors.
Definition mlmodel.hpp:95
virtual std::shared_ptr< named_tensor_views > infer(const named_tensor_views &inputs, const ProtoStruct &extra)=0
Runs the model against the input tensors and returns inference results as tensors.