Мой ввод - файл CSV, и я сделал сегменты примерно из 400 сэмплов. Функция 3 (х, у, г). Сначала я применил CNN2D, используя model.add(Conv2D(16, (2, 2), activation = 'relu', input_shape = x_train[0].shape))
. это сработало идеально, однако в случае LSTM ввод показал ошибки. Итак, я изменил ввод в model.add(LSTM(32, input_shape = (400,3), return_sequences=True))
, тогда этот код работал, но ниже в model.fit я столкнулся с проблемой. Пожалуйста, найдите код и ошибку ниже:
x_train.shape, x_test.shape
вывод вышеуказанного кода: ((836, 400, 3), (209, 400, 3))
x_train = x_train.reshape(836, 400, 3, 1)
x_test = x_test.reshape(209, 400, 3, 1)
x_train[0].shape #output of this line: (400, 3, 1)
model = Sequential()
model.add(LSTM(32, input_shape = (400,3), return_sequences=True))
model.add(Dropout(0.5))
model.add(Dense(100, activation='relu'))
model.add(Flatten())
#Then Here we have Dense Layer
model.add(Dense(64, activation= 'relu'))
model.add(Dropout(0.5))
model.add(Dense(3, activation='softmax'))
model.compile(optimizer=Adam(learning_rate = 0.001), loss = 'sparse_categorical_crossentropy', metrics=['accuracy'])
history = model.fit(x_train, y_train, epochs = 10, validation_data = (x_test, y_test), verbose=1)
ОШИБКА
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-109-3ffd974b58e0> in <module>
1 #Record this model tranning into a history
2
----> 3 history = model.fit(x_train, y_train, epochs = 10, validation_data = (x_test, y_test), verbose=1)
4 #Below here you can see xthe training, here at the very first step 75% traning accuracy and 84% validation accuracy, After 10
5 #epoc you see 91% of traning accuracy and 87% validaton accuracy, (As a complement, with accelrometer data, this is very good
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\engine\training.py in fit(self, 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)
726 max_queue_size=max_queue_size,
727 workers=workers,
--> 728 use_multiprocessing=use_multiprocessing)
729
730 def evaluate(self,
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, 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, **kwargs)
222 validation_data=validation_data,
223 validation_steps=validation_steps,
--> 224 distribution_strategy=strategy)
225
226 total_samples = _get_total_number_of_samples(training_data_adapter)
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _process_training_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, steps_per_epoch, validation_split, validation_data, validation_steps, shuffle, distribution_strategy, max_queue_size, workers, use_multiprocessing)
545 max_queue_size=max_queue_size,
546 workers=workers,
--> 547 use_multiprocessing=use_multiprocessing)
548 val_adapter = None
549 if validation_data:
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _process_inputs(model, x, y, batch_size, epochs, sample_weights, class_weights, shuffle, steps, distribution_strategy, max_queue_size, workers, use_multiprocessing)
592 batch_size=batch_size,
593 check_steps=False,
--> 594 steps=steps)
595 adapter = adapter_cls(
596 x,
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\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)
2470 feed_input_shapes,
2471 check_batch_axis=False, # Don't enforce the batch size.
-> 2472 exception_prefix='input')
2473
2474 # Get typespecs for the input data and sanitize it if necessary.
c:\users\nafee\appdata\local\programs\python\python37\lib\site-packages\tensorflow_core\python\keras\engine\training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
563 ': expected ' + names[i] + ' to have ' +
564 str(len(shape)) + ' dimensions, but got array '
--> 565 'with shape ' + str(data_shape))
566 if not check_batch_axis:
567 data_shape = data_shape[1:]
ValueError: Error when checking input: expected lstm_16_input to have 3 dimensions, but got array with shape (836, 400, 3, 1)
Есть идеи для решения этой проблемы?