CNN下象棋时在Keras(TF)中输入数组的尺寸问题

时间:2018-11-24 12:57:09

标签: keras neural-network deep-learning conv-neural-network python-chess

我想将一个numpy数组馈入CNN,该数组包含2个棋位置,一个在移动之前,另一个在移动之后。我想训练CNN来估算常规棋程序对该动作的评估。这些评估是整数值。

Traceback (most recent call last): File "Main.py", line 16, in <module> print(int(int(a[0])-int(a[2]))) ValueError: invalid literal for int() with base 10: 'x' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "Main.py", line 18, in <module> print(int(int(a[0])-int(a[4]))) ValueError: invalid literal for int() with base 10: 'x' ['1', '+', '3', '=', 'x'] 的形状为:m

型号代码:

Map

培训是通过以下方式完成的:

t = g.addV()
m.each{k,v -> t= t.property(k,v)]
t

它给我以下错误:

STATICFILES_DIRS = [
    os.path.join(
        BASE_DIR,
        '/static/')
]

我做错了什么?我该如何解决?


好的,我意识到问题与最后一层的输出形状有关:

x

但是为什么y呢?不应该是x: (2000000, 8, 8, 2) , y: (2000000,)吗?这是一个具有1个值的神经元!

1 个答案:

答案 0 :(得分:0)

  

但是为什么会这样(无,4、4、1)?应该不是(无,1)吗?

不,不应该。因为Dense layer is applied on the last axis of its input,因此由于在这种情况下,它被应用到Conv2D层的输出(它是4D张量),因此Dense层的输出也将是4D张量。要解决此问题,您可以先使用Conv2D层将Flatten层的输出展平,然后再使用Dense层,如下所示:

model.add(Conv2D(128, kernel_size=(3, 3), strides=(1, 1), activation='relu'))
model.add(Flatten())  # flatten the output of `Conv2D` to a 2D tensor
model.add(Dense(128, activation='relu', init='uniform'))