Skip to main content
clemente
Associate III
February 20, 2019
Solved

"Invalid Network" and "NOT IMPLEMENTED: Input size smaller than filter kernel is not handled" error in log.

  • February 20, 2019
  • 1 reply
  • 2130 views

Hello to all, I'm very new to AI and I tried different Keras model with Cube.AI to test my knowledge. In particular this one generate an "Invalid Network" error and more esplicely I see on the log this error:

2019-02-20 15:25:35,946 [INFO] AIPython:108 - Choose CNN input representation:
2019-02-20 15:25:35,946 [INFO] AIPython:108 - Set model name [network]: network
2019-02-20 15:25:35,946 [INFO] AIPython:108 - 	1. Keras (Tensorflow)
2019-02-20 15:25:35,947 [INFO] AIPython:108 - 	2. Lasagne (Theano)
2019-02-20 15:25:35,947 [INFO] AIPython:108 - 	3. Caffe
2019-02-20 15:25:35,947 [INFO] AIPython:108 - 	4. ConvNetJs
2019-02-20 15:25:35,947 [INFO] AIPython:108 - 
2019-02-20 15:25:35,947 [INFO] AIPython:108 - Choose your option [1]: 1
2019-02-20 15:25:35,947 [INFO] AIPython:108 - 
2019-02-20 15:25:35,947 [INFO] AIPython:108 - Provide Keras model parameters [C:/Users/c.dicaprio/Dropbox/Deep Learning on MCU/Mnist_Keras2.h5]: C:/Users/c.dicaprio/Dropbox/Deep Learning on MCU/Mnist_Keras2.h5
2019-02-20 15:25:35,948 [INFO] AIPython:108 - 
2019-02-20 15:25:35,948 [INFO] AIPython:108 - Provide Keras network topology (if any) []: 
2019-02-20 15:25:35,948 [INFO] AIPython:108 - 
2019-02-20 15:25:35,948 [INFO] AIPython:108 - Provide path to export Platform Independent Neural Network Format (PINNR) [C:/Users/C9F25~1.DIC/AppData/Local/Temp/mxAI65611872897229049032768866819944678]: C:/Users/C9F25~1.DIC/AppData/Local/Temp/mxAI65611872897229049032768866819944678
2019-02-20 15:25:35,948 [INFO] AIPython:108 - NOT IMPLEMENTED: Input size smaller than filter kernel is not handled: (1, 28) < [5, 5]
2019-02-20 15:25:36,091 [ERROR] AIPython:134 - 2019-02-20 15:25:35.839933: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX
2019-02-20 15:25:36,091 [ERROR] AIPython:134 - Using TensorFlow backend.
2019-02-20 15:25:36,105 [INFO] AIPython:149 - Python generation ended

The Keras model I used is this:

def baseline_model():
 # create model
 model = Sequential()
 model.add(Conv2D(32, (5, 5), input_shape=(1, 28, 28), activation='relu'))
 model.add(MaxPooling2D(pool_size=(2, 2)))
 model.add(Dropout(0.2))
 model.add(Flatten())
 model.add(Dense(128, activation='relu'))
 model.add(Dense(num_classes, activation='softmax'))
 # Compile model
 model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
 return model

It appear that the line:

model.add(Conv2D(32, (5, 5), input_shape=(1, 28, 28), activation='relu'))

is generating the error and the log indication:

[INFO] AIPython:108 - NOT IMPLEMENTED: Input size smaller than filter kernel is not handled: (1, 28) < [5, 5]

Can someone help me to understand how I need to change my model to work with the Cube.AI?

Some code I wrote here:

https://github.com/cledic/STM32F769I-Disco_ML

TIA

Clemente

    This topic has been closed for replies.
    Best answer by jean-michel.d

    ​Hello,

    Your definition of the input shape is not correct.

    It should be in your case (mnist model type): input_shape=(28, 28, 1) to have a correct definition. NHWC or 'last channel' format is expected by X-CUBE-AI, if the dimension order in the original toolbox is different from HWC (such as Lasagne: CHW), it is the user's responsibility to properly re-arrange the elements.

    N: batch size (not expected to define the input shape)

    H: height

    W: width

    C: channel

    If you specify (1, 28, 28), 5x5 filter can be not applied on an (1x28) image ->

    NOT IMPLEMENTED: Input size smaller than filter kernel is not handled: (1, 28) < [5, 5]

    Best Regard,

    Jean-Michel

    1 reply

    jean-michel.dBest answer
    ST Employee
    February 20, 2019

    ​Hello,

    Your definition of the input shape is not correct.

    It should be in your case (mnist model type): input_shape=(28, 28, 1) to have a correct definition. NHWC or 'last channel' format is expected by X-CUBE-AI, if the dimension order in the original toolbox is different from HWC (such as Lasagne: CHW), it is the user's responsibility to properly re-arrange the elements.

    N: batch size (not expected to define the input shape)

    H: height

    W: width

    C: channel

    If you specify (1, 28, 28), 5x5 filter can be not applied on an (1x28) image ->

    NOT IMPLEMENTED: Input size smaller than filter kernel is not handled: (1, 28) < [5, 5]

    Best Regard,

    Jean-Michel

    clemente
    clementeAuthor
    Associate III
    February 21, 2019

    Hello Jean-michel,

    I modified the notebook as you suggest and now the "Analyze" step on X-Cube works.

    Thanks a lot!

    Best Regards

    Clemente