Skip to content

Commit d1bc0ce

Browse files
authored
RSDK-1150: Mlmodel data type logging (#479)
1 parent ed71092 commit d1bc0ce

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

src/viam/sdk/services/mlmodel.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ const char* MLModelService::tensor_info::data_type_to_string(const data_types da
100100
return nullptr;
101101
}
102102

103+
std::ostream& operator<<(std::ostream& os, MLModelService::tensor_info::data_types dt) {
104+
const char* str = MLModelService::tensor_info::data_type_to_string(dt);
105+
106+
if (str) {
107+
os << str;
108+
} else {
109+
// Cast to unsigned because uint8_t is unsigned char, and 0-9 are whitespace or non printing
110+
// characters
111+
os << static_cast<unsigned>(dt);
112+
}
113+
114+
return os;
115+
}
116+
103117
MLModelService::tensor_info::data_types MLModelService::tensor_info::tensor_views_to_data_type(
104118
const tensor_views& view) {
105119
class visitor : public boost::static_visitor<data_types> {

src/viam/sdk/services/mlmodel.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#pragma once
1616

17+
#include <iosfwd>
18+
1719
#include <boost/mpl/joint_view.hpp>
1820
#include <boost/mpl/list.hpp>
1921
#include <boost/mpl/transform_view.hpp>
@@ -177,5 +179,7 @@ struct API::traits<MLModelService> {
177179
static API api();
178180
};
179181

182+
std::ostream& operator<<(std::ostream&, MLModelService::tensor_info::data_types);
183+
180184
} // namespace sdk
181185
} // namespace viam

src/viam/sdk/services/private/mlmodel_server.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ ::grpc::Status MLModelServiceServer::Infer(
4848
const auto tensor_type = MLModelService::tensor_info::tensor_views_to_data_type(tensor);
4949
if (tensor_type != input.data_type) {
5050
std::ostringstream message;
51-
using ut = std::underlying_type<MLModelService::tensor_info::data_types>::type;
5251
message << "Tensor input `" << input.name << "` was the wrong type; expected type "
53-
<< static_cast<ut>(input.data_type) << " but got type "
54-
<< static_cast<ut>(tensor_type);
52+
<< input.data_type << " but got type " << tensor_type;
5553
return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str());
5654
}
5755
inputs.emplace(input.name, std::move(tensor));
@@ -74,11 +72,9 @@ ::grpc::Status MLModelServiceServer::Infer(
7472
MLModelService::tensor_info::tensor_views_to_data_type(tensor);
7573
if (tensor_type != input.data_type) {
7674
std::ostringstream message;
77-
using ut = std::underlying_type<MLModelService::tensor_info::data_types>::type;
7875
message << "Tensor input `" << input.name
79-
<< "` was the wrong type; expected type "
80-
<< static_cast<ut>(input.data_type) << " but got type "
81-
<< static_cast<ut>(tensor_type);
76+
<< "` was the wrong type; expected type " << input.data_type
77+
<< " but got type " << tensor_type;
8278
return helper.fail(::grpc::INVALID_ARGUMENT, message.str().c_str());
8379
}
8480
inputs.emplace(std::move(input.name), std::move(tensor));
@@ -122,12 +118,8 @@ ::grpc::Status MLModelServiceServer::Metadata(
122118
MLModelService::tensor_info::data_type_to_string(s.data_type);
123119
if (!string_for_data_type) {
124120
std::ostringstream message;
125-
message
126-
<< "Served MLModelService returned an unknown data type with value `"
127-
<< static_cast<
128-
std::underlying_type<MLModelService::tensor_info::data_types>::type>(
129-
s.data_type)
130-
<< "` in its metadata";
121+
message << "Served MLModelService returned an unknown data type with value `"
122+
<< s.data_type << "` in its metadata";
131123
return helper.fail(grpc::INTERNAL, message.str().c_str());
132124
}
133125
new_entry.set_data_type(string_for_data_type);

0 commit comments

Comments
 (0)