40 struct make_tensor_view_ {
41 using shape_t = std::vector<std::size_t>;
43 using xt_no_ownership_t =
decltype(xt::no_ownership());
45 using type =
decltype(xt::adapt(std::declval<const T*>(),
46 std::declval<std::size_t>(),
47 std::declval<xt_no_ownership_t>(),
48 std::declval<shape_t>()));
55 using tensor_view =
typename make_tensor_view_<T>::type;
58 static tensor_view<T> make_tensor_view(
const T* data,
60 typename tensor_view<T>::shape_type shape) {
61 return xt::adapt(std::move(data), std::move(size), xt::no_ownership(), std::move(shape));
68 using signed_integral_base_types =
69 boost::mpl::list<std::int8_t, std::int16_t, std::int32_t, std::int64_t>;
71 using unsigned_integral_base_types =
72 boost::mpl::transform_view<signed_integral_base_types,
73 std::make_unsigned<boost::mpl::placeholders::_1>>;
75 using integral_base_types =
76 boost::mpl::joint_view<signed_integral_base_types, unsigned_integral_base_types>;
78 using fp_base_types = boost::mpl::list<float, double>;
80 using base_types = boost::mpl::joint_view<integral_base_types, fp_base_types>;
82 using tensor_view_types =
83 boost::mpl::transform_view<base_types, make_tensor_view_<boost::mpl::placeholders::_1>>;
86 using tensor_views = boost::make_variant_over<tensor_view_types>::type;
89 using named_tensor_views = std::unordered_map<std::string, tensor_views>;
97 inline std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs) {
98 return infer(inputs, {});
109 virtual std::shared_ptr<named_tensor_views>
infer(
const named_tensor_views& inputs,
110 const AttributeMap& extra) = 0;
115 std::string description;
117 enum : std::uint8_t {
118 k_label_type_tensor_value = 0,
119 k_label_type_tensor_axis = 1,
124 std::string description;
126 enum class data_types : std::uint8_t {
139 std::vector<int> shape;
140 std::vector<file> associated_files;
144 static boost::optional<data_types> string_to_data_type(
const std::string& str);
145 static const char* data_type_to_string(data_types data_type);
147 static data_types tensor_views_to_data_type(
const tensor_views& view);
153 std::string description;
154 std::vector<tensor_info> inputs;
155 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:97
virtual std::shared_ptr< named_tensor_views > infer(const named_tensor_views &inputs, const AttributeMap &extra)=0
Runs the model against the input tensors and returns inference results as tensors.