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 :
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.
Shape should be (78300, 90, 90, 1).
Reshape x
(add a dimension):
x = x[..., tf.newaxis]
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加