Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Convert Sequential model throws "Unsupported dimension type:... #659

@gurkan8941

Description

@gurkan8941

Hi,

I have a binary classification model with this architecture:
Built with tf.keras using tensorflow version 2.3.0

def create_model_architecture(input_dimension, layers=[96], act='relu', dr=[0.10], batch_size_value=None):
    model = Sequential()
    model.add(Input(shape=(input_dimension,), batch_size=batch_size_value))
    model.add(Dense(layers[0], activation=act))
    model.add(Dropout(dr[0]))
    # create output layer
    model.add(Dense(1, activation='sigmoid'))
    return model

Converting to ONNX (using latest version 1.7.0):

 keras_model_single_batch = create_model_architecture(113, batch_size_value=1)
 keras_model_single_batch.set_weights(trained_weights)
 onnx_model = keras2onnx.convert_keras(keras_model_single_batch)

throws "Unsupported dimension type:" error in data_types.py in method to_onnx_type.
But my input shape is (1,113) in this case for the keras model so did not understand how that can be unsupported dimensions.

I updated the onnx conversion package code like below (had to set d = dim.value) and then conversion was successful:

   def to_onnx_type(self):
        onnx_type = onnx_proto.TypeProto()
        onnx_type.tensor_type.elem_type = self._get_element_onnx_type()
        for dim in self.shape:
            d = dim.value
            s = onnx_type.tensor_type.shape.dim.add()
            if d is None:
                pass
            elif isinstance(d, numbers.Integral):
                s.dim_value = d
            elif isinstance(d, str):
                s.dim_param = d
            else:
                raise ValueError('Unsupported dimension type: %s, see %s' % (
                    type(d), "https://github.com/onnx/onnx/blob/master/docs/IR.md#" +
                    "input--output-data-types"))
        if getattr(onnx_type, 'denotation', None) is not None:
            if self.denotation:
                onnx_type.denotation = self.denotation
            if self.channel_denotations:
                for d, denotation in zip(onnx_type.tensor_type.shape.dim,
                                         self.channel_denotations):
                    if denotation:
                        d.denotation = denotation
        return onnx_type

Can anyone help explain this. Would rather not modify the package locally. Thanks for a great package!

ENV:

  • virtualenv python 3.8
  • onnx 1.8.0
  • keras2onnx 1.7.0
  • tensorflow 2.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions