Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
tensorflow中神经网络加层错误_Tensorflow_Neural Network_Tensorflow2.0 - Fatal编程技术网

tensorflow中神经网络加层错误

tensorflow中神经网络加层错误,tensorflow,neural-network,tensorflow2.0,Tensorflow,Neural Network,Tensorflow2.0,我试图在tensorflow中创建一个2层神经网络模型,但得到了以下错误: import tensorflow as tf from tensorflow.keras.datasets import mnist from tensorflow.keras import models from tensorflow.keras import layers from tensorflow.

我试图在tensorflow中创建一个2层神经网络模型,但得到了以下错误:

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
文件“”,第7行
network.add(layers.Dense(8,activation='softmax'))#这是输出层
^
SyntaxError:无效语法

我可以知道为什么我在输出层而不是隐藏层上得到这个错误吗?谢谢。

您错过了一个结束括号

File "<ipython-input-6-0dde2ff676f8>", line 7
network.add(layers.Dense(8, activation = 'softmax'))  # this is the output layer
      ^
SyntaxError: invalid syntax
第7行缺少一个
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