N
N
N1ghtLight2021-03-17 17:27:55
Python
N1ghtLight, 2021-03-17 17:27:55

Error in using Keras ready neural network model?

Neural network for image recognition.

When using a ready-made, trained h5 model, the following error occurs:

/usr/local/lib/python3.7/dist-packages/tensorflow/python/keras/engine/input_spec.py:239 assert_input_compatibility
    str(tuple(shape)))

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


Here is my network model information:

Model: "sequential_6"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_24 (Conv2D)           (None, 200, 200, 16)      1216      
_________________________________________________________________
max_pooling2d_24 (MaxPooling (None, 100, 100, 16)      0         
_________________________________________________________________
conv2d_25 (Conv2D)           (None, 100, 100, 32)      12832     
_________________________________________________________________
max_pooling2d_25 (MaxPooling (None, 50, 50, 32)        0         
_________________________________________________________________
conv2d_26 (Conv2D)           (None, 50, 50, 64)        51264     
_________________________________________________________________
max_pooling2d_26 (MaxPooling (None, 25, 25, 64)        0         
_________________________________________________________________
conv2d_27 (Conv2D)           (None, 25, 25, 128)       204928    
_________________________________________________________________
max_pooling2d_27 (MaxPooling (None, 12, 12, 128)       0         
_________________________________________________________________
flatten_6 (Flatten)          (None, 18432)             0         
_________________________________________________________________
dense_18 (Dense)             (None, 1024)              18875392  
_________________________________________________________________
dropout_12 (Dropout)         (None, 1024)              0         
_________________________________________________________________
dense_19 (Dense)             (None, 256)               262400    
_________________________________________________________________
dropout_13 (Dropout)         (None, 256)               0         
_________________________________________________________________
dense_20 (Dense)             (None, 3)                 771       
=================================================================
Total params: 19,408,803
Trainable params: 19,408,803
Non-trainable params: 0


Input data: Image 200x200 px

Image submission code:

img_path = '9.jpeg'
Image(img_path, width=200, height=200)
img = image.load_img(img_path, target_size=(200, 200), color_mode = "grayscale")

x = image.img_to_array(img)

x = x.reshape(1, 40000)

x = 255 - x

x /= 255

prediction = model.predict(x)


Thanks in advance!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question