What should be the input_shape here?

the_it_weirdo

I don't have much experience in posting questions to Stack Overflow. Pardon my mistakes. I will try to be thorough.

I have two numpy arrays :

  1. X with shape (78300, 90, 90).
  2. y with shape (78300, 29)
  • X is an array of black and white images with height and width (90, 90).
  • y is the corresponding encoded class labels for X. (encoded as in y = tensorflow.keras.utils.to_categorical(labels) )

I am trying to train the following CNN on this data.

from tensorflow.keras import utils
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D, BatchNormalization
from tensorflow.keras.callbacks import ModelCheckpoint

model = Sequential()

model.add(Conv2D(64, (3, 3), input_shape=(90, 90, 1), activation='relu'))
model.add(MaxPooling2D((2, 2)))

model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))

model.add(Conv2D(256, (3, 3), activation='relu'))
model.add(MaxPooling2D((2, 2)))

model.add(BatchNormalization())

model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(1024, activation='sigmoid'))
model.add(Dense(29, activation='softmax'))

I am receiving the following error on running

n_classes = 29
batch = 64
epochs = 5
learning_rate = 0.001

adam = Adam(lr=learning_rate)

model.compile(optimizer=adam,
              loss='categorical_crossentropy',
              metrics=['accuracy'])

cp_callback = ModelCheckpoint(filepath=os.path.join("/output_dir", "result_folder"),
                              save_weights_only=True,
                              verbose=1)

history = model.fit(x,
                    y,
                    batch_size=batch,
                    epochs=epochs,
                    validation_split=0.1,
                    shuffle=True,verbose=1,
                   callbacks=[cp_callback])

: ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [None, 90, 90]

I cannot figure out what is going wrong. Please help me. Also, if you could link a documentation/article/blog post/video that will help me understand the nuances of the input shape in layers, that will be very helpful.

Andrey

Shape should be (78300, 90, 90, 1).

Reshape x (add a dimension):

x = x[..., tf.newaxis]

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

What is asterisk doing here?

分類Dev

What is the purpose of set here?

分類Dev

What is the being called here: return _()

分類Dev

What should be the regex expresesion?

分類Dev

What is exact sequence of operations made here?

分類Dev

What is wrong here? Component with ternary inside

分類Dev

Can someone explain to me what to do here

分類Dev

What does `omega` really do here?

分類Dev

What's wrong with my code here?

分類Dev

Ubuntu OpenStack and What Did I Miss Here?

分類Dev

What's wrong with the PHP syntax here?

分類Dev

keraslstmが正しくないinput_shape

分類Dev

If Downcasting Should Be Avoided, What Should I Do?

分類Dev

What happens when the Controller gets bad input? Should it propagate the bad input to the UseCaseInteractor?

分類Dev

What should be put into this fragment viewmodel?

分類Dev

What size should TabBar images be?

分類Dev

What widget should after be called on?

分類Dev

gnuplot: what should sgn(NaN) be?

分類Dev

What value should be assigned to `serialVersionUID`?

分類Dev

What should the TwoDimensionalShape Class contain?

分類Dev

What is a dehydrated detector and how am I using one here?

分類Dev

What's wrong with here? Python2 ->Python3

分類Dev

What is the pickling problem that persistent IDs are used to solve here?

分類Dev

A while loop and an here-document - what happens when?

分類Dev

MATLAB data indexing issue. What is going on here?

分類Dev

LSTMのinput_shapeとbatch_input_shapeの違いは何ですか

分類Dev

Keras入力の説明:input_shape、units、batch_size、dimなど

分類Dev

How do i get the input_shape of a frozen Tensorflow-Model for TOCO tf_convert

分類Dev

ここでinput_shapeはどうあるべきですか?

Related 関連記事

  1. 1

    What is asterisk doing here?

  2. 2

    What is the purpose of set here?

  3. 3

    What is the being called here: return _()

  4. 4

    What should be the regex expresesion?

  5. 5

    What is exact sequence of operations made here?

  6. 6

    What is wrong here? Component with ternary inside

  7. 7

    Can someone explain to me what to do here

  8. 8

    What does `omega` really do here?

  9. 9

    What's wrong with my code here?

  10. 10

    Ubuntu OpenStack and What Did I Miss Here?

  11. 11

    What's wrong with the PHP syntax here?

  12. 12

    keraslstmが正しくないinput_shape

  13. 13

    If Downcasting Should Be Avoided, What Should I Do?

  14. 14

    What happens when the Controller gets bad input? Should it propagate the bad input to the UseCaseInteractor?

  15. 15

    What should be put into this fragment viewmodel?

  16. 16

    What size should TabBar images be?

  17. 17

    What widget should after be called on?

  18. 18

    gnuplot: what should sgn(NaN) be?

  19. 19

    What value should be assigned to `serialVersionUID`?

  20. 20

    What should the TwoDimensionalShape Class contain?

  21. 21

    What is a dehydrated detector and how am I using one here?

  22. 22

    What's wrong with here? Python2 ->Python3

  23. 23

    What is the pickling problem that persistent IDs are used to solve here?

  24. 24

    A while loop and an here-document - what happens when?

  25. 25

    MATLAB data indexing issue. What is going on here?

  26. 26

    LSTMのinput_shapeとbatch_input_shapeの違いは何ですか

  27. 27

    Keras入力の説明:input_shape、units、batch_size、dimなど

  28. 28

    How do i get the input_shape of a frozen Tensorflow-Model for TOCO tf_convert

  29. 29

    ここでinput_shapeはどうあるべきですか?

ホットタグ

アーカイブ