为什么我的递归神经网络给我的错误?

问题描述 投票:0回答:1

你好我得到这个值误差,同时使起着cartpole使用openai健身房回归神经网络 -

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],
     ...

这里是我做了我的递归神经网络模型。我想有些变化必须在定义作出了在这里做 -

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

然后它这个函数模型的训练 -

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.

我不明白为什么它给我这个错误。我试图改变输入形状和许多其他的东西,但他们都不是解决我的问题。如果您需要完整的代码,如果你认为这将是有帮助的,你可以把它从这里 - Full Code

python numpy keras deep-learning recurrent-neural-network
1个回答
0
投票

你的目标是y清单,但它应该是一个numpy的阵列。拟合模型之前y = np.array(y)尝试。

© www.soinside.com 2019 - 2024. All rights reserved.