拟合具有不同形状的多个输出的keras模型

时间:2019-06-25 13:41:47

标签: python keras

我正在尝试拟合具有不同输出的深度神经网络模型,策略输出至多是向量,值输出至多是标量。我也想实施体验重播。这就是为什么我要在每个时期之后训练模型。

我不知道什么是最好的方法,但是在互联网上学习了一些教程之后,我想出了以下代码来训练模型(请注意,agent.brain是模型):

for epoch in range(agent.EPOCHS):

    # running some code using the model.predict function

    minibatch = random.sample(agent.memory, agent.BS)
    for s, target_vector in minibatch:
         agent.brain.fit(x = s, y = [target_vector, np.array([target_value])], epochs = 1)

输出形状:

policy_output (Dense)           (None, 4098)         4724994     flatten_3[0][0]                  
__________________________________________________________________________________________________
value_output (Activation)       (None, 1)            0           dense_4[0][0]                    
==================================================================================================

此代码:

print(s.shape)
print(target_vector.shape)

给我:

(1, 72, 8, 8)
(4098,)

target_value是一个整数。 但是我得到了错误:

ValueError: All target arrays (y) should have the same number of samples. Got array shapes: [(4098, 1), (1, 1)]

我还尝试使用{'policy_output' : target_vector, 'value_output' : np.array([target_value])}

这样的字典来拟合模型

您能帮助我了解我在做什么吗?

0 个答案:

没有答案
相关问题