From 66dba8e845143e7ff56a80339bd6fe055521dfed Mon Sep 17 00:00:00 2001 From: Kalle Raiskila Date: Sat, 22 Apr 2023 16:06:48 +0200 Subject: [PATCH] Add Reshape attribute parsing. 'allowzero' was added in ONNX-14. Not implemented - what to do about tensors with dimensions of size zero? --- src/nodes/reshape.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/nodes/reshape.h b/src/nodes/reshape.h index 644f500..4a7376a 100644 --- a/src/nodes/reshape.h +++ b/src/nodes/reshape.h @@ -6,6 +6,7 @@ class Reshape : public Node { Reshape() { op_name = "Reshape"; data=shape=reshaped=NULL; + allowzero=0; } // inputs const Tensor *data; @@ -13,6 +14,20 @@ class Reshape : public Node { // outputs const Tensor *reshaped; + int32_t allowzero; + + void parseAttributes( onnx::NodeProto &node ) + { + for( const auto& a : node.attribute() ) { + LOG(TRACE) << "Parsing attribute " << a.name() << std::endl; + if( a.name() == "allowzero" ) + allowzero = parse_attribute_int(a); + else + LOG(ERROR) << "Ignoring attribute " << a.name() << " for node TEMPLATE/" << onnx_name << std::endl; + } + } + + virtual void print_parameters(std::ostream &dst, bool decorate ) const override { data->print_tensor_as_const(dst, !decorate); @@ -56,6 +71,10 @@ class Reshape : public Node { ERROR("Reshaping to a run-time defined shape is not supported"); } + if( allowzero != 0) { + ERROR("Allowzero attribute set. What exactly are you expecting as the output here?"); + } + std::vector out_data_dim; int64_t *new_shape = (int64_t*)(shape->data_buffer); bool negative_shape_found=false;