OpenCV::DNN doesn't support conv1d

asked 2020-04-10 08:21:35 -0600

Hi! I'm working with pytorch cnn for timeseries. I use some conv1d layers in my model and I would like to use this model as ONNX in OpenCV C++ backend but I've faced the problem - this type of layers isn't supported. Some assertions connected with dimensions are failed. For example

    if(attribute_name == "kernel_shape")
    {
        CV_Assert(attribute_proto.ints_size() == 2 || attribute_proto.ints_size() == 3); <--- this one
        lp.set("kernel_size", parse(attribute_proto.ints()));
    }

To skip this problem i made that workaround - I changed conv1d to conv2d:

def SimpleNet(input_shape, n_classes):

    input_layer = layers.Input(input_shape)

    """Block Series 1"""
    # --- Layer 1 (Convolution) ------------------------------------------------------------------------------ #
    # Set name
    layer_name = 'layer_1'
    # net = layers.Conv1D(filters=128,
    #                 kernel_size=3,
    #                 padding='same',
    #                 strides=2,
    #                 dilation_rate=1,
    #                 use_bias=False,
    #                 name=layer_name + '_conv'
    #                 )(input_layer)

    net = layers.Conv2D(filters=128,
                    kernel_size=(3, 1),
                    padding='same',
                    strides=(2, 1),
                    dilation_rate=(1, 1),
                    use_bias=False,
                    name=layer_name + '_conv'
                    )(input_layer)

    net = layers.Flatten()(net)
    output_layer = layers.Dense(n_classes, activation='softmax')(net)

    model = Model(inputs=input_layer, outputs=output_layer)

    model.compile(loss='categorical_crossentropy', optimizer=keras.optimizers.Adam(),
                  metrics=['accuracy'])

    return model

But now my network needs huge amount of memory and even that it cannot be trained - low accuracy. What should I do?

edit retag flag offensive close merge delete

Comments

You should open a feature request on GitHub.

Yashas gravatar imageYashas ( 2020-04-11 01:22:06 -0600 )edit