如何修复googlecolab上的错误语法

2024-09-30 01:36:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我试着把代码注释掉,然后用一条简单的打印线来替换它,但是没有用。然而,当我使笔记本少于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)

我收到的错误消息是:

^{pr2}$

Tags: 代码testimportlabelstensorflowas错误语法
1条回答
网友
1楼 · 发布于 2024-09-30 01:36:25

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

x = (1, 2, 3
test_loss = model.evaluate(test_images, test_labels)

签署后:

^{pr2}$

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

相关问题 更多 >

    热门问题