keras-onnx icon indicating copy to clipboard operation
keras-onnx copied to clipboard

Input shape Error

Open Madankumar90 opened this issue 4 years ago • 2 comments

This is the initial step of the architecture i am using as mentioned in keras2onnx i have put input_shape for the conversion:

class AlexNet(Sequential): def init(self, input_shape, num_classes): super().init()

    self.add(Conv2D(96, kernel_size=(11,11), strides= 4,
                    padding= 'same', use_bias=False,
                    input_shape= input_shape,
                    kernel_initializer= 'he_normal'))
    .....

with the call being: model = AlexNetD((227, 227, 3), num_classes)

and for conversion i am using: onnx_model = keras2onnx.convert_keras(model, model.name)

the conversion is successful but when i run the onnx i am getting this error: OpenCV(4.4.0) Error: Unspecified error (Number of input channels should be multiple of 3 but got 227) in cv::dnn::ConvolutionLayerImpl::getMemoryShapes, file C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\layers\convolution_layer.cpp, line 347 [ERROR:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\dnn.cpp (3444) cv::dnn::dnn4_v20200609::Net::Impl::getLayerShapesRecursively OPENCV/DNN: [Convolution]:(convolution_output4): getMemoryShapes() throws exception. inputs=1 outputs=0/1 blobs=2 [ERROR:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\dnn.cpp (3447) cv::dnn::dnn4_v20200609::Net::Impl::getLayerShapesRecursively input[0] = [ 1 227 3 227 ] [ERROR:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\dnn\src\dnn.cpp (3455) cv::dnn::dnn4_v20200609::Net::Impl::getLayerShapesRecursively blobs[0] = CV_32FC1 [ 96 3 11 11 ]

what am i doing wrong here?? Thanks

Madankumar90 avatar Oct 07 '20 10:10 Madankumar90

Looks like your input data dimension does not match the model input dimension. Since the conversion is successful, you can see our test examples to write simple test for the onnx model (running on onnxruntime). See if the simple test can work.

jiafatom avatar Oct 07 '20 18:10 jiafatom

Thanks for the reply . I will check the test examples. should i mention anything about inputs in this onnx_model = keras2onnx.convert_keras(model, model.name) as argument??. My inputs are [2272273]. Thanks.

Madankumar90 avatar Oct 08 '20 06:10 Madankumar90