Python 如何修复Google Colab上的错误语法错误

Python 如何修复Google Colab上的错误语法错误,python,google-colaboratory,Python,Google Colaboratory,我正在谷歌Colab上与TensorFlow合作的时尚Mnist库。我在第62行得到一个错误,说它有无效的语法,即使它没有。我想知道我的代码中是否有错误,或者Google Colab是否有故障 我试过注释代码,只是用一行简单的打印行来替换它,但这不起作用。然而,当我使笔记本少于62行时,我没有得到错误。我还尝试在注释完所有代码后,它只会说所有后续代码的语法都无效 代码如下: from __future__ import absolute_import, division, print_funct

我正在谷歌Colab上与TensorFlow合作的时尚Mnist库。我在第62行得到一个错误,说它有无效的语法,即使它没有。我想知道我的代码中是否有错误,或者Google Colab是否有故障

我试过注释代码,只是用一行简单的打印行来替换它,但这不起作用。然而,当我使笔记本少于62行时,我没有得到错误。我还尝试在注释完所有代码后,它只会说所有后续代码的语法都无效

代码如下:

from __future__ import absolute_import, division, print_function, 
unicode_literals

# Import TensorFlow & Keras
import tensorflow as tf
from tensorflow import keras

# Import helper libraries
import numpy as np
import matplotlib.pyplot as plt

print("TensorFlow is currently on version "+tf.__version__)

# Fashion Mnist setup
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']

# Train neuron
train_images.shape
len(train_labels)
train_labels
test_images.shape
len(test_labels)

# PREPROCESS THE DATA
plt.figure()
plt.imshow(train_images[0])
plt.colorbar()
plt.grid(False)
plt.show

train_images = train_images / 255.0
test_images = test_images / 255.0

plt.figure(figsize=(10,10))
for i in range(25):
  plt.subplot(5,5,i+1)
  plt.xticks([])
  plt.yticks([])
  plt.grid(False)
  plt.imshow(train_images[i], cmap=plt.cm.binary)
  #plt.xlabel(class_names[train_labels[[i]]])
plt.show)
我收到的错误消息是:

File "<ipython-input-5-a9c182238576>", line 62
  test_loss = model.evaluate(test_images, test_labels)
          ^
SyntaxError: invalid syntax
文件“”,第62行
测试损耗=模型。评估(测试图像、测试标签)
^
SyntaxError:无效语法

前一行可能缺少右括号。下面是一个简短的示例,显示了该行为:

x = (1, 2, 3
test_loss = model.evaluate(test_images, test_labels)
执行时:

  File "<ipython-input-14-2b487d3dfc3a>", line 2
    test_loss = model.evaluate(test_images, test_labels)
            ^
SyntaxError: invalid syntax
文件“”,第2行
测试损耗=模型。评估(测试图像、测试标签)
^
SyntaxError:无效语法

在错误上方的行中查找缺少的右大括号。

问题中包含的行中没有语法错误。我怀疑您在前一行中缺少一个结束括号。您能否编辑问题以包含问题单元格的全文?如果您在当前行中没有看到错误,请始终查看该行之前的内容:通常是缺少(结束)括号。前一行中没有缺少结束括号。前一行是“model.fit(train_图像、train_标签、epochs==5)”,它不必位于前一行:它可以位于前面61行中的任何一行。如果您需要帮助找出问题,请使用问题单元格的完整内容编辑您的问题。我刚刚编辑了代码,以显示第62行前面文档中的所有代码。提前谢谢!哦谢谢,我真不敢相信我错过了。