45 struct make_tensor_view_ {
46 using shape_t = std::vector<std::size_t>;
48 using xt_no_ownership_t =
decltype(xt::no_ownership());
50 using type =
decltype(xt::adapt(std::declval<const T*>(),
51 std::declval<std::size_t>(),
52 std::declval<xt_no_ownership_t>(),
53 std::declval<shape_t>()));
60 using tensor_view =
typename make_tensor_view_<T>::type;
63 static tensor_view<T> make_tensor_view(
const T* data,
65 typename tensor_view<T>::shape_type shape) {
66 return xt::adapt(std::move(data), std::move(size), xt::no_ownership(), std::move(shape));
73 using signed_integral_base_types =
74 boost::mpl::list<std::int8_t, std::int16_t, std::int32_t, std::int64_t>;
76 using unsigned_integral_base_types =
77 boost::mpl::transform_view<signed_integral_base_types,
78 std::make_unsigned<boost::mpl::placeholders::_1>>;
80 using integral_base_types =
81 boost::mpl::joint_view<signed_integral_base_types, unsigned_integral_base_types>;
83 using fp_base_types = boost::mpl::list<float, double>;
85 using base_types = boost::mpl::joint_view<integral_base_types, fp_base_types>;
87 using tensor_view_types =
88 boost::mpl::transform_view<base_types, make_tensor_view_<boost::mpl::placeholders::_1>>;
91 using tensor_views = boost::make_variant_over<tensor_view_types>::type;
94 using named_tensor_views = std::unordered_map<std::string, tensor_views>;
102 inline std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs) {
103 return infer(inputs, {});
114 virtual std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs,
115 const ProtoStruct& extra) = 0;
120 std::string description;
122 enum : std::uint8_t {
123 k_label_type_tensor_value = 0,
124 k_label_type_tensor_axis = 1,
129 std::string description;
131 enum class data_types : std::uint8_t {
144 std::vector<int> shape;
145 std::vector<file> associated_files;
149 static boost::optional<data_types> string_to_data_type(
const std::string& str);
150 static const char* data_type_to_string(data_types data_type);
152 static data_types tensor_views_to_data_type(
const tensor_views& view);
158 std::string description;
159 std::vector<tensor_info> inputs;
160 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:102
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.