Reputation: 83
Hello I am getting this value error while making a reccurent neural network which plays cartpole using the openaigym -
Traceback (most recent call last):
File "C:/Users/Tejas/Desktop/ML Laboratory/Deep Learning/Neural Networks/4. Sentdex/Part - 3/Gym.py", line 147, in train_model
model.fit(X, y, batch_size=64, epochs = 5)
File "C:\Users\Tejas\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\keras\engine\training.py", line 952, in fit
batch_size=batch_size)
File "C:\Users\Tejas\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\keras\engine\training.py", line 789, in _standardize_user_data
exception_prefix='target')
File "C:\Users\Tejas\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\keras\engine\training_utils.py", line 102, in standardize_input_data
str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 19570 arrays: [array([[0],
[1]]), array([[1],
[0]]), array([[0],
[1]]), array([[1],
[0]]), array([[1],
[0]]), array([[1],
[0]]), array([[1],
[0]]), array([[0],
...
Here is my recurrent neural network model which I made. I think some changes have to be made in the definition have to be made here -
def neural_network_model(input_size):
model = Sequential()
model.add(CuDNNLSTM(128, input_shape=(input_size, 1), return_sequences=True))
model.add(Dropout(0.8))
model.add(CuDNNLSTM(256, return_sequences=True))
model.add(Dropout(0.8))
model.add(CuDNNLSTM(512))
model.add(Dropout(0.8))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.8))
model.add(Dense(2, activation='softmax'))
return model
And then the training of the model which this function does -
def train_model(training_data, model=False):
X = np.array([i[0] for i in training_data]).reshape(-1,len(training_data[0][0]),1)
y = [i[1] for i in training_data]
print(len(X[0]))
if not model:
model = neural_network_model(input_size = len(X[0]))
model.compile(optimizer = 'adam', loss = 'categorical_crossentropy', metrics = ['accuracy'])
model.fit(X, y, batch_size=64, epochs = 5)
return model.
I can't understand why is it giving me this error. I have tried changing the input shape and many other things but none of them are solving my problem. If you need the full code if you think that will be helpful you can take it from here - Full Code
Upvotes: 1
Views: 83
Reputation: 3588
Your target y
is a list but it should be a numpy array. Try with y = np.array(y)
before fitting your model.
Upvotes: 1