model = tf.keras.models.Sequential([
# Note the input shape is the desired size of the training dataset 8000 * 10
# This is the first convolution
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape= (8000, 10, 4)),
# Flatten the results to feed into a DNN
tf.keras.layers.Flatten(),
tf.keras.layers.Dropout(0.5),
# 512 neuron hidden layer
tf.keras.layers.Dense(512, activation='relu'),
tf.keras.layers.Dense(4, activation='softmax'),
])
model.summary()
model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
history = model.fit(X_train, y_train, epochs=25, validation_data = X_cv, verbose = 1)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-166-5defea4eaeb5> in <module>
3 model.compile(loss = 'categorical_crossentropy', optimizer='rmsprop', metrics=
['accuracy'])
4
5 history = model.fit(X_train, y_train, epochs=25, validation_data = X_cv, verbose = 1)
~/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in
fit(self,0 x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data,
shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps,
validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
707 steps=steps_per_epoch,
708 validation_split=validation_split,
709 shuffle=shuffle)
710
711 # Prepare validation data.
~/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in
_standardize_user_data(self, x, y, sample_weight, class_weight, batch_size, check_steps,
steps_name, steps, validation_split, shuffle, extract_tensors_from_dataset)
2649 feed_input_shapes,
2650 check_batch_axis=False, # Don't enforce the batch size.
2651 exception_prefix='input')
2652
2653 if y is not None:
~/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training_utils.py in
standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
374 ': expected ' + names[i] + ' to have ' +
375 str(len(shape)) + ' dimensions, but got array '
376 'with shape ' + str(data_shape))
377 if not check_batch_axis:
378 data_shape = data_shape[1:]
ValueError: Error when checking input: expected conv2d_50_input to have 4 dimensions, but
got array with shape (8000, 10)
контекст: я использую эту сверточную нейронную сеть для мультиклассовой классификации (4 класса), предоставляя входную форму в моем наборе данных X_train (8000, 10). Но получаю ошибку как показано выше. Я не понимаю, почему ожидается 4 измерения. Или какое может быть решение. Пожалуйста, помогите мне. Спасибо заранее.