【发布时间】:2021-08-25 02:22:05
【问题描述】:
我正在尝试创建一个 q-learning 国际象棋引擎,其中神经网络最后一层的输出(密度等于合法移动的数量)通过 argmax() 函数运行,该函数返回一个整数我用作存储合法移动的数组的索引。这是我的代码的一部分:
#imports
env = gym.make('ChessAlphaZero-v0') #builds environment
obs = env.reset()
type(obs)
done = False #game is not won
num_actions = len(env.legal_moves) #array where legal moves are stored
obs = chess.Board()
model = models.Sequential()
def dqn(board):
#dense layers
action = layers.Dense(num_actions)(layer5)
i = np.argmax(action)
move = env.legal_moves[i]
return keras.Model(inputs=inputs, outputs=move)
但是当我运行代码时出现以下错误:
TypeError: Cannot convert a symbolic Keras input/output to a numpy array. This error may indicate that you're trying to pass a symbolic value to a NumPy call, which is not supported. Or, you may be trying to pass Keras symbolic inputs/outputs to a TF API that does not register dispatching, preventing Keras from automatically converting the API call to a lambda layer in the Functional Model.
任何代码示例都将不胜感激,谢谢。
【问题讨论】:
-
您不能在
Dense对象上调用np.argmax()。尝试将argmax操作包装在Lambda层中。参考this。
标签: python arrays numpy keras deep-learning