Я новичок в машинном обучении и Керас, и я пытаюсь обучить очень простой RNN, чтобы начать работать.Я просто импортирую свои данные, на которых хочу тренироваться, создаю генератор и передаю в RNN для обучения.У меня есть следующий короткий код:
from keras.models import Sequential
from keras import models, optimizers
from keras import layers
from keras import losses
from keras import metrics
from keras.optimizers import RMSprop
import numpy as np
from numpy import genfromtxt
from matplotlib import pyplot as plt
def my_generator(data, timesteps, batch_size, labeled_data):
while 1:
(n, m) = data.shape
this_batch = np.zeros((batch_size, timesteps, m))
labels = np.zeros((batch_size, timesteps, 1))
for x in range(batch_size):
start_index = np.random.randint(0, n-timesteps, 1)
end_index = start_index + timesteps
this_batch[x] = data[start_index:end_index, :]
labels[x] = labeled_data[start_index:end_index, :]
yield (this_batch, labels)
f = open('Heading1.csv')
data1 = f.read()
f.close()
lines = data1.split('\n')
my_data = genfromtxt('Heading1.csv', delimiter=',')
my_data = np.array(my_data)
print('shape', my_data[0:163026, 3:].shape)
train_gen = my_generator(my_data[:163026,3:], 20, 20, my_data[:163026,1])
val_gen = my_generator(my_data[163026:244539, 3:], 20, 20, my_data[163026:244539, 1])
test_gen = my_generator(my_data[244539:, 3:], 20, 20, my_data[244539:, 1])
model = Sequential()
model.add(layers.LSTM(32, return_sequences=True, input_shape=(None, 10)))
model.add(layers.TimeDistributed(layers.Dense(1)))
model.compile(optimizer=RMSprop(), loss='mse')
model.fit_generator(train_gen,
steps_per_epoch = 100,
epochs = 20,
validation_data = val_gen,
validation_steps = 10)
, и я получаю следующую ошибку:
deep-learning-with-python_service_1 | Using TensorFlow backend.
deep-learning-with-python_service_1 | ('shape', (163026, 10))
deep-learning-with-python_service_1 | Epoch 1/20
deep-learning-with-python_service_1 | Traceback (most recent call last):
deep-learning-with-python_service_1 | File "/opt/project/PMLproject.py", line 51, in <module>
deep-learning-with-python_service_1 | validation_steps = 10)
deep-learning-with-python_service_1 | File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper
deep-learning-with-python_service_1 | return func(*args, **kwargs)
deep-learning-with-python_service_1 | File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1418, in fit_generator
deep-learning-with-python_service_1 | initial_epoch=initial_epoch)
deep-learning-with-python_service_1 | File "/usr/local/lib/python2.7/dist-packages/keras/engine/training_generator.py", line 181, in fit_generator
deep-learning-with-python_service_1 | generator_output = next(output_generator)
deep-learning-with-python_service_1 | File "/usr/local/lib/python2.7/dist-packages/keras/utils/data_utils.py", line 709, in get
deep-learning-with-python_service_1 | six.reraise(*sys.exc_info())
deep-learning-with-python_service_1 | File "/usr/local/lib/python2.7/dist-packages/keras/utils/data_utils.py", line 685, in get
deep-learning-with-python_service_1 | inputs = self.queue.get(block=True).get()
deep-learning-with-python_service_1 | File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get
deep-learning-with-python_service_1 | raise self._value
deep-learning-with-python_service_1 | TypeError: only integer scalar arrays can be converted to a scalar index
Я не понимаю ошибку, потому что я не уверен, где Python думает, что я пытаюсьполучить индекс.