简体   繁体   English

该代码显示语法错误“ tf.keras.layers.Dense(units = 4)”

[英]The code is showing syntax error “tf.keras.layers.Dense(units=4)”

We were trying to get started in tensorflow so and we got this error in the celsius to fahrenheit example code of tf. 我们试图从tensorflow开始,因此我们在摄氏到华氏度的tf示例代码中遇到了这个错误。

its a syntax error but as compared to tutorial it looks the same 它是一个语法错误,但与教程相比,它看起来相同

`celsius    = np.array([8,10,12,14,16], dtype = float) #data
 fahrenheit = np.array([12,13,14,15,16], dtype = float) #data
 model = tf.keras.Sequential([ #setting model 
  tf.keras.layers.Dense(units=4, input_shape=[1]) 
  tf.keras.layers.Dense(units=4) #error in the network 
  tf.keras.layers.Dense(units=1)
 ])`

well we are trying to create our first neural network but got stuck here 好吧,我们正在尝试创建我们的第一个神经网络,但被困在这里

Your are adding a list to the model, so the list entries have to be seperated by a , instead of only a new line (after each of the dense layers). 您正在向模型中添加一个列表,因此列表条目必须用分隔,而不是仅换行(在每个密集层之后)。

Try this: 尝试这个:

celsius    = np.array([8,10,12,14,16], dtype = float) #data
 fahrenheit = np.array([12,13,14,15,16], dtype = float) #data
 model = tf.keras.Sequential([ #setting model 
  tf.keras.layers.Dense(units=4, input_shape=[1]), #just added , here (and in the next line)
  tf.keras.layers.Dense(units=4), #error in the network 
  tf.keras.layers.Dense(units=1)
 ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensorflow - 构建 LSTM 模型 - 需要 tf.keras.layers.Dense() - Tensorflow - building LSTM model - need for tf.keras.layers.Dense() tf.keras.layers.Dense output 对同一输入行的更改 - tf.keras.layers.Dense output changes for the same input row Keras - 使用 tf.keras.layers.Dense(1,activation='sigmoid')(x) 时指定 from_logits=False - Keras - Specifying from_logits=False when using tf.keras.layers.Dense(1,activation='sigmoid')(x) tf.contrib.layer.fully_connected, tf.layers.dense, tf.contrib.slim.fully_connected, tf.keras.layers.Dense 之间的不一致 - Inconsistencies between tf.contrib.layer.fully_connected, tf.layers.dense, tf.contrib.slim.fully_connected, tf.keras.layers.Dense ValueError:尝试转换一个值( <tf.keras.layers.core.dense) with an unsupported type (<class 'tf.keras.layers.core.dense'> ) 到张量</tf.keras.layers.core.dense)> - ValueError:Attempt to convert a value (<tf.keras.layers.core.Dense) with an unsupported type (<class 'tf.keras.layers.core.Dense'>) to a Tensor 凯拉斯的密集层单位 - Units in Dense layer in Keras 关于tf.layers .dense的问题 - Questions on tf.layers .dense keras 层没有属性 Dense - keras layers has no attribute Dense keras 用于添加两个密集层 - keras for adding two dense layers TensorFlow 2.0 如何从 tf.keras.layers 层获取可训练变量,如 Conv2D 或 Dense - TensorFlow 2.0 How to get trainable variables from tf.keras.layers layers, like Conv2D or Dense
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM