【问题标题】:Error adding layers in neural network in tensorflow [closed]在张量流中的神经网络中添加层时出错[关闭]
【发布时间】:2020-09-15 23:25:10
【问题描述】:
import tensorflow as tf

from tensorflow.keras.datasets import mnist             
from tensorflow.keras import models                     
from tensorflow.keras import layers                     
from tensorflow.keras.utils import to_categorical         

network=models.Sequential()    # this initializes a sequential model that we will call network
network.add(layers.Dense(10, activation = 'relu')    # this adds a dense hidden layer 
network.add(layers.Dense(8, activation = 'softmax'))  # this is the output layer

我正在尝试在 tensorflow 中创建一个 2 层神经网络模型并收到此错误:

File "<ipython-input-6-0dde2ff676f8>", line 7
network.add(layers.Dense(8, activation = 'softmax'))  # this is the output layer
      ^
SyntaxError: invalid syntax

我可以知道为什么输出层会出现此错误,而隐藏层不会出现此错误吗?谢谢。

【问题讨论】:

  • 您在第 7 行缺少)

标签: tensorflow neural-network tensorflow2.0


【解决方案1】:

你有missed a closing bracket

import tensorflow as tf
from tensorflow.keras.datasets import mnist             
from tensorflow.keras import models                     
from tensorflow.keras import layers                     
from tensorflow.keras.utils import to_categorical         

network=models.Sequential()    # this initializes a sequential model that we will call network
network.add(layers.Dense(10, activation = 'relu'))    # this adds a dense hidden layer 
network.add(layers.Dense(8, activation = 'softmax'))  # this is the output layer

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多