简体   繁体   中英

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

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 . 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.
  • You pass the input to the Dense layers as Dense(args)(input) .

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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