Python 将Tensorflow Keras模型移植到Tensorflow版本1.14.0时出错

Python 将Tensorflow Keras模型移植到Tensorflow版本1.14.0时出错,python,tensorflow,keras,Python,Tensorflow,Keras,我最近编程了一个小NN来和我玩井字游戏。 这真的是我自己写的第一本书。 今天我想通过Google Collab向一位朋友展示它,但我遇到了以下错误: model.fit(train_layout, train_place, epochs=3000) ^ SyntaxError: invalid syntax 我以前从未犯过这个错误。我认为这与谷歌Collag使用1.14.0版和我使用1.13.1版有关 这是我的密码: import tensorflow as tf fr

我最近编程了一个小NN来和我玩井字游戏。 这真的是我自己写的第一本书。 今天我想通过Google Collab向一位朋友展示它,但我遇到了以下错误:

    model.fit(train_layout, train_place, epochs=3000)
        ^
SyntaxError: invalid syntax
我以前从未犯过这个错误。我认为这与谷歌Collag使用1.14.0版和我使用1.13.1版有关

这是我的密码:

import tensorflow as tf
from tensorflow import keras

model = keras.Sequential([
        keras.layers.Dense(9, activation=tf.nn.tanh),
        keras.layers.Dense(128, activation=tf.nn.relu),
        keras.layers.Dense(256, activation=tf.nn.relu),
        keras.layers.Dense(96, activation=tf.nn.relu),
        keras.layers.Dense(9, activation=tf.nn.softmax)
        ])

gd = tf.train.GradientDescentOptimizer(0.2)

model.compile(gd, loss='mean_squared_error', metrics=['accuracy'])


model.fit(train_layout, train_place, epochs=3000)
培训数据如下所示:

train_layout = np.array([[0, 0, 0, 0, 1, 0, 0, 0, 0]])
train_place = np.array([[0, 1, 0, 0, 0, 0, 0, 0, 0]])
(当然,只有一个数据块=D)

提前谢谢你的帮助
-NALLUJ05

你实际上给了自己一个答案

我以前从未犯过这个错误。我认为这与谷歌Collag使用1.14.0版和我使用1.13.1版有关


我认为解决这个问题的一种方法是保存
json
model,并手动检查在补丁中更改的操作符名称。如果您的模型是
.h5
,我不知道任何解决方案来处理它。

首先,我在collab中复制粘贴的ur代码,我得到的错误是无法构建密集层

第二,仅仅倾倒各种尺寸的密集层对于1块tic-tac-toe这样一个简单的问题不是一个好主意…我相信你会遇到过度装配


第三个也是最重要的一个是……您忘记了提到输入层的大小……这可能是错误的根本原因……

如果您查看错误,它会说
语法错误
,这主要是因为您忘记了代码中要编写的内容,例如括号,逗号或有时空格等。我不认为这是因为tensorflow版本。我可以用TF1.14和1.13在colab中运行这段代码,它只是显示了一个错误,可以通过在第一层之前定义输入形状来消除这个错误。 比如说,

model = keras.Sequential([
        keras.layers.Flatten(input_shape=(28, 28)),
        keras.layers.Dense(9, activation=tf.nn.tanh),
        keras.layers.Dense(128, activation=tf.nn.relu),
        keras.layers.Dense(256, activation=tf.nn.relu),
        keras.layers.Dense(96, activation=tf.nn.relu),
        keras.layers.Dense(9, activation=tf.nn.softmax)
        ])