CNN image classifier trains in Edge Impulse, but not from iPython notebook

In my project (fashion-mnist-png-test-01), I have all 60k training images from Fashion-MNIST uploaded as PNG files. I used Image feature extraction (all defaults).

For the classifier, I used a NN (Keras) block with default architecture (2D Conv (32, 3x3), 2D Conv (16, 3x3), Flatten, Dropout (0.25). This trains with no issues on Edge Impulse.

However, if I download the iPython notebook and try to run it in Colab, I get the following error when trying to run model.fit(...):

ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=2. Full shape received: (32, 784)

Is there a Python or Keras version mismatch between Egde Impulse and Colab or some other way to correct this error?

@dansitu Any idea here?

1 Like

Thanks @ShawnHymel! We’re deploying a fix right now, but while you wait you can add the following to your notebook, above the BATCH_SIZE lines:


SPECIFIC_INPUT_SHAPE = (96, 96, 3) # your image dimensions & channels
 
def get_reshape_function(reshape_to):
    def reshape(image, label):
        return tf.reshape(image, reshape_to), label
    return reshape

train_dataset = train_dataset.map(get_reshape_function(SPECIFIC_INPUT_SHAPE), tf.data.experimental.AUTOTUNE)
validation_dataset = validation_dataset.map(get_reshape_function(SPECIFIC_INPUT_SHAPE), tf.data.experimental.AUTOTUNE)

### Add it above the following lines:

# this controls the batch size, or you can manipulate the tf.data.Dataset objects yourself
BATCH_SIZE = 32
train_dataset, validation_dataset = set_batch_size(BATCH_SIZE, train_dataset, validation_dataset)
1 Like

Sweet, thank you! It’s not super important for me, but I figured it would be cool to demonstrate to some students how to plot the loss and accuracy over epochs after training.

@ShawnHymel Fix will be live today.

1 Like