Add to_string() method to ov::element::Type (#18697)
* Add to_string() method to ov::element::Type * Fixed Python legacy API * Fixed typo
This commit is contained in:
1 parent
29ca4b99c5
commit
e7cd113a47
15 files changed
+38
-30
No files matched your search
@@ -48,4 +48,5 @@ void regclass_pyngraph_Type(py::module m) {
|
||||
type.def_property_readonly("bitwidth", &ngraph::element::Type::bitwidth);
|
||||
type.def_property_readonly("is_real", &ngraph::element::Type::is_real);
|
||||
type.def("get_type_name", &ngraph::element::Type::get_type_name);
|
||||
type.def("to_string", &ngraph::element::Type::to_string);
|
||||
}
|
||||
@@ -78,6 +78,7 @@ void regclass_graph_Type(py::module m) {
|
||||
type.def_property_readonly("signed", &ov::element::Type::is_signed);
|
||||
type.def("is_quantized", &ov::element::Type::is_quantized);
|
||||
type.def_property_readonly("quantized", &ov::element::Type::is_quantized);
|
||||
type.def("to_string", &ov::element::Type::to_string);
|
||||
type.def("get_type_name", &ov::element::Type::get_type_name);
|
||||
type.def_property_readonly("type_name", &ov::element::Type::get_type_name);
|
||||
type.def("compatible",
|
||||
|
||||
@@ -243,12 +243,12 @@ def test_compress_model_transformation():
|
||||
node_constant = ov.opset8.constant(np.array([[0.0, 0.1, -0.1], [-2.5, 2.5, 3.0]], dtype=np.float32))
|
||||
node_ceil = ov.opset8.ceiling(node_constant)
|
||||
model = Model(node_ceil, [], "TestModel")
|
||||
elem_type = model.get_ordered_ops()[0].get_element_type().get_type_name()
|
||||
elem_type = model.get_ordered_ops()[0].get_element_type().to_string()
|
||||
assert elem_type == "f32"
|
||||
compress_model_transformation(model)
|
||||
|
||||
assert model is not None
|
||||
elem_type = model.get_ordered_ops()[0].get_element_type().get_type_name()
|
||||
elem_type = model.get_ordered_ops()[0].get_element_type().to_string()
|
||||
assert elem_type == "f16"
|
||||
|
||||
|
||||
|
||||
@@ -50,14 +50,14 @@ def _convert_inputs(cnn_network: IENetwork) -> None:
|
||||
|
||||
def apply_ng_type(output: DataPtr, ng_type: Type):
|
||||
ng_ie_supported_type_map = {
|
||||
Type.boolean.get_type_name(): "BOOL",
|
||||
Type.f32.get_type_name(): "FP32",
|
||||
Type.i8.get_type_name(): "I8",
|
||||
Type.i32.get_type_name(): "I32",
|
||||
Type.u8.get_type_name(): "U8",
|
||||
Type.boolean.to_string(): "BOOL",
|
||||
Type.f32.to_string(): "FP32",
|
||||
Type.i8.to_string(): "I8",
|
||||
Type.i32.to_string(): "I32",
|
||||
Type.u8.to_string(): "U8",
|
||||
}
|
||||
if ng_type.get_type_name() in ng_ie_supported_type_map:
|
||||
output.precision = ng_ie_supported_type_map[ng_type.get_type_name()]
|
||||
if ng_type.to_string() in ng_ie_supported_type_map:
|
||||
output.precision = ng_ie_supported_type_map[ng_type.to_string()]
|
||||
|
||||
|
||||
class Runtime(object):
|
||||
|
||||
@@ -114,6 +114,8 @@ public:
|
||||
constexpr operator Type_t() const {
|
||||
return m_type;
|
||||
}
|
||||
// Return element type in string representation
|
||||
std::string to_string() const;
|
||||
|
||||
private:
|
||||
Type_t m_type{Type_t::undefined};
|
||||
|
||||
@@ -34,7 +34,7 @@ static size_t _asIndex(const char* source, const element::Type& element_type) {
|
||||
return static_cast<size_t>(tmpBuff);
|
||||
}
|
||||
default: {
|
||||
OPENVINO_THROW("Unsupported input data type: ", element_type.get_type_name());
|
||||
OPENVINO_THROW("Unsupported input data type: ", element_type.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ std::pair<uint64_t, uint64_t> random_uniform(const uint64_t* out_shape,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
OPENVINO_THROW("Unsupported type of RandomUniform: ", elem_type.get_type_name());
|
||||
OPENVINO_THROW("Unsupported type of RandomUniform: ", elem_type.to_string());
|
||||
}
|
||||
if (++n == 0)
|
||||
++counter;
|
||||
|
||||
@@ -133,7 +133,7 @@ bool ov::op::v9::Eye::evaluate(const ov::HostTensorVector& outputs, const ov::Ho
|
||||
break;
|
||||
default:
|
||||
OPENVINO_THROW("Unsupported type of input `diagonal_index` in Eye operation: ",
|
||||
diagonal_index_data->get_element_type().get_type_name());
|
||||
diagonal_index_data->get_element_type().to_string());
|
||||
}
|
||||
} else {
|
||||
diagonal_index = 0;
|
||||
|
||||
@@ -50,10 +50,10 @@ void PSROIPooling::validate_and_infer_types() {
|
||||
const auto& coords_et = get_input_element_type(1);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
feat_maps_et.is_real(),
|
||||
"Feature maps' data type must be floating point. Got " + feat_maps_et.get_type_name());
|
||||
"Feature maps' data type must be floating point. Got " + feat_maps_et.to_string());
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
coords_et.is_real(),
|
||||
"Coords' data type must be floating point. Got " + coords_et.get_type_name());
|
||||
"Coords' data type must be floating point. Got " + coords_et.to_string());
|
||||
|
||||
OPENVINO_SUPPRESS_DEPRECATED_START
|
||||
const auto output_shapes = shape_infer(this, get_node_input_partial_shapes(*this));
|
||||
|
||||
@@ -103,7 +103,7 @@ void op::v8::RandomUniform::validate_and_infer_types() {
|
||||
", max value: ",
|
||||
max_val);
|
||||
} else {
|
||||
OPENVINO_THROW("Unsupported output type of RandomUniform: " + get_out_type().get_type_name());
|
||||
OPENVINO_THROW("Unsupported output type of RandomUniform: " + get_out_type().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ bool op::v8::RandomUniform::evaluate(const HostTensorVector& outputs, const Host
|
||||
out_shape = out_shape_uint64.data();
|
||||
} else {
|
||||
OPENVINO_THROW("Unsupported type of out shape in RandomUniform operation: " +
|
||||
inputs[0]->get_element_type().get_type_name());
|
||||
inputs[0]->get_element_type().to_string());
|
||||
}
|
||||
|
||||
element::Type_t t_out = get_out_type();
|
||||
@@ -180,7 +180,7 @@ bool op::v8::RandomUniform::evaluate(const HostTensorVector& outputs, const Host
|
||||
out = (char*)outputs[0]->get_data_ptr<const double>();
|
||||
break;
|
||||
default:
|
||||
OPENVINO_THROW("Unsupported type of RandomUniform: " + get_out_type().get_type_name());
|
||||
OPENVINO_THROW("Unsupported type of RandomUniform: " + get_out_type().to_string());
|
||||
}
|
||||
|
||||
auto state = ngraph::runtime::reference::random_uniform(out_shape,
|
||||
|
||||
@@ -28,16 +28,16 @@ void DetectionOutputBase::validate_base(const DetectionOutputBase::AttributesBas
|
||||
auto box_logits_et = get_input_element_type(0);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
box_logits_et.is_real(),
|
||||
"Box logits' data type must be floating point. Got " + box_logits_et.get_type_name());
|
||||
"Box logits' data type must be floating point. Got " + box_logits_et.to_string());
|
||||
auto class_preds_et = get_input_element_type(1);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
class_preds_et == box_logits_et,
|
||||
"Class predictions' data type must be the same as box logits type (" +
|
||||
box_logits_et.get_type_name() + "). Got " + class_preds_et.get_type_name());
|
||||
box_logits_et.to_string() + "). Got " + class_preds_et.to_string());
|
||||
auto proposals_et = get_input_element_type(2);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
proposals_et.is_real(),
|
||||
"Proposals' data type must be floating point. Got " + proposals_et.get_type_name());
|
||||
"Proposals' data type must be floating point. Got " + proposals_et.to_string());
|
||||
|
||||
if (get_input_size() == 5) {
|
||||
auto aux_class_preds_et = get_input_element_type(3);
|
||||
@@ -45,12 +45,12 @@ void DetectionOutputBase::validate_base(const DetectionOutputBase::AttributesBas
|
||||
aux_class_preds_et == class_preds_et,
|
||||
"Additional class predictions' data type must be the same as class "
|
||||
"predictions data type (" +
|
||||
class_preds_et.get_type_name() + "). Got " + aux_class_preds_et.get_type_name());
|
||||
class_preds_et.to_string() + "). Got " + aux_class_preds_et.to_string());
|
||||
auto aux_box_preds_et = get_input_element_type(4);
|
||||
NODE_VALIDATION_CHECK(this,
|
||||
aux_box_preds_et == box_logits_et,
|
||||
"Additional box predictions' data type must be the same as box logits data type (" +
|
||||
box_logits_et.get_type_name() + "). Got " + aux_box_preds_et.get_type_name());
|
||||
box_logits_et.to_string() + "). Got " + aux_box_preds_et.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ static std::string get_bounds_and_label_info(const ov::Output<ov::Node> output)
|
||||
|
||||
std::string pass::VisualizeTree::get_constant_value(std::shared_ptr<Node> node, size_t max_elements) {
|
||||
std::stringstream ss;
|
||||
ss << "{" << node->get_element_type().get_type_name() << "}";
|
||||
ss << "{" << node->get_element_type().to_string() << "}";
|
||||
ss << pretty_partial_shape(node->get_output_partial_shape(0));
|
||||
|
||||
if (const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(node))
|
||||
@@ -482,7 +482,7 @@ string pass::VisualizeTree::get_attributes(shared_ptr<Node> node) {
|
||||
for (const auto& input : node->inputs()) {
|
||||
label << "\\nin" << to_string(input.get_index()) << ": ";
|
||||
if (nvtot)
|
||||
label << "{" << input.get_element_type().get_type_name() << "}";
|
||||
label << "{" << input.get_element_type().to_string() << "}";
|
||||
if (nvtos)
|
||||
label << pretty_partial_shape(input.get_partial_shape());
|
||||
label << ": " << node->get_input_node_ptr(input.get_index())->get_name() << ": out"
|
||||
@@ -497,7 +497,7 @@ string pass::VisualizeTree::get_attributes(shared_ptr<Node> node) {
|
||||
if (nvtio)
|
||||
label << "\\nout" << to_string(output.get_index()) << ": ";
|
||||
if (nvtot)
|
||||
label << "{" << output.get_element_type().get_type_name() << "}";
|
||||
label << "{" << output.get_element_type().to_string() << "}";
|
||||
if (nvtos)
|
||||
label << pretty_partial_shape(output.get_partial_shape());
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ void PreStepsList::add_convert_impl(const element::Type& type) {
|
||||
// doesn't require shape or type propagation.
|
||||
return std::make_tuple(res, false);
|
||||
},
|
||||
"convert type (" + type.get_type_name() + ")");
|
||||
"convert type (" + type.to_string() + ")");
|
||||
}
|
||||
|
||||
void PreStepsList::add_resize_impl(ResizeAlgorithm alg, int dst_height, int dst_width) {
|
||||
@@ -656,7 +656,7 @@ void PostStepsList::add_convert_impl(const element::Type& type) {
|
||||
auto convert = std::make_shared<op::v0::Convert>(node, t);
|
||||
return std::make_tuple(Output<Node>(convert), true);
|
||||
},
|
||||
"convert type (" + type.get_type_name() + ")");
|
||||
"convert type (" + type.to_string() + ")");
|
||||
}
|
||||
|
||||
void PostStepsList::add_convert_layout_impl(const Layout& layout) {
|
||||
|
||||
@@ -190,6 +190,10 @@ size_t ov::element::Type::hash() const {
|
||||
}
|
||||
|
||||
std::string ov::element::Type::get_type_name() const {
|
||||
return to_string();
|
||||
}
|
||||
|
||||
std::string ov::element::Type::to_string() const {
|
||||
return get_type_info(m_type).m_type_name;
|
||||
}
|
||||
|
||||
@@ -295,7 +299,7 @@ Type fundamental_type_for(const Type& type) {
|
||||
} // namespace ov
|
||||
|
||||
std::ostream& ov::element::operator<<(std::ostream& out, const ov::element::Type& obj) {
|
||||
return out << obj.get_type_name();
|
||||
return out << obj.to_string();
|
||||
}
|
||||
|
||||
std::istream& ov::element::operator>>(std::istream& in, ov::element::Type& obj) {
|
||||
@@ -325,7 +329,7 @@ std::istream& ov::element::operator>>(std::istream& in, ov::element::Type& obj)
|
||||
return in;
|
||||
}
|
||||
for (auto&& type : Type::get_known_types()) {
|
||||
if (type->get_type_name() == str) {
|
||||
if (type->to_string() == str) {
|
||||
obj = *type;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ INFERENCE_ENGINE_1_0_DEPRECATED inline Precision convertPrecision(const ::ngraph
|
||||
case ::ngraph::element::Type_t::dynamic:
|
||||
return Precision(Precision::UNSPECIFIED);
|
||||
default:
|
||||
IE_THROW() << "Incorrect precision " << precision.get_type_name() << "!";
|
||||
IE_THROW() << "Incorrect precision " << precision.to_string() << "!";
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user