简体   繁体   English

tf.layers.Dense 不适用于张量流。 如何使用它?

[英]tf.layers.Dense doesn't work for tensorflow. How to use it?

I have a very simple few lines of code (I was following some tensorflow tutorial) Specifications: Tensorflow v. = 1.15 , IDE = PyCharm我有一个非常简单的几行代码(我正在关注一些 tensorflow 教程)规范:Tensorflow v. = 1.15 ,IDE = PyCharm

import tensorflow as tf 

network = tf.placeholder(tf.float32)

network = tf.layers.Dense(network,10,activation=tf.nn.relu)

and when I try to run, it gives me当我尝试跑步时,它给了我

TypeError: __init__() got multiple values for argument 'activation'

I've tried every "combination" for tf.layers.Dense .我已经尝试了tf.layers.Dense所有“组合”。 for example,例如,

I've tried我试过了

network = tf.layers.Dense(inputs=network, units=10, activation=tf.nn.relu) 

This doesn't recognize the argument "inputs", but the tutorial I'm seeing, clearly uses the first argument as the input, 2nd argument as the units, and third argument as the activation这不能识别参数“输入”,但是我看到的教程清楚地使用第一个参数作为输入,第二个参数作为单位,第三个参数作为激活

Few issues,几个问题,

  • Your placeholder doesn't have a shape (it's a scalar).您的占位符没有形状(它是标量)。 Dense layer needs a 2+ dimensional input. Dense层需要 2+ 维输入。
  • You pass the input to the Dense layers as Dense(args)(input) .您将输入作为Dense(args)(input)传递给 Dense 层。

So change the code to following and it'll work.因此,将代码更改为以下内容,它将起作用。 You can change the shape argument according to the what the input dimensionality is for your problem.您可以根据问题的输入维度更改形状参数。

import tensorflow as tf 

network = tf.placeholder(tf.float32, shape=[None, 15])

network = tf.layers.Dense(10,activation=tf.nn.relu)(network)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM