43 struct make_tensor_view_ {
44 using shape_t = std::vector<std::size_t>;
46 using xt_no_ownership_t =
decltype(xt::no_ownership());
48 using type =
decltype(xt::adapt(std::declval<const T*>(),
49 std::declval<std::size_t>(),
50 std::declval<xt_no_ownership_t>(),
51 std::declval<shape_t>()));
58 using tensor_view =
typename make_tensor_view_<T>::type;
61 static tensor_view<T> make_tensor_view(
const T* data,
63 typename tensor_view<T>::shape_type shape) {
64 return xt::adapt(std::move(data), std::move(size), xt::no_ownership(), std::move(shape));
71 using signed_integral_base_types =
72 boost::mpl::list<std::int8_t, std::int16_t, std::int32_t, std::int64_t>;
74 using unsigned_integral_base_types =
75 boost::mpl::transform_view<signed_integral_base_types,
76 std::make_unsigned<boost::mpl::placeholders::_1>>;
78 using integral_base_types =
79 boost::mpl::joint_view<signed_integral_base_types, unsigned_integral_base_types>;
81 using fp_base_types = boost::mpl::list<float, double>;
83 using base_types = boost::mpl::joint_view<integral_base_types, fp_base_types>;
85 using tensor_view_types =
86 boost::mpl::transform_view<base_types, make_tensor_view_<boost::mpl::placeholders::_1>>;
89 using tensor_views = boost::make_variant_over<tensor_view_types>::type;
92 using named_tensor_views = std::unordered_map<std::string, tensor_views>;
100 inline std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs) {
101 return infer(inputs, {});
112 virtual std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs,
113 const ProtoStruct& extra) = 0;
118 std::string description;
120 enum : std::uint8_t {
121 k_label_type_tensor_value = 0,
122 k_label_type_tensor_axis = 1,
127 std::string description;
129 enum class data_types : std::uint8_t {
142 std::vector<int> shape;
143 std::vector<file> associated_files;
147 static boost::optional<data_types> string_to_data_type(
const std::string& str);
148 static const char* data_type_to_string(data_types data_type);
150 static data_types tensor_views_to_data_type(
const tensor_views& view);
156 std::string description;
157 std::vector<tensor_info> inputs;
158 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:100
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.