hkitano
hkitano

Reputation: 129

tf.contrib.layers.fully_connected() in TensorFlow 2?

I'm trying to use tf.contrib.layers.fully_connected() in one of my projects, and it's been deprecated in TensorFlow 2.0. Is there an equivalent function, or should I just keep TensorFlow v1.x in my virtual environment for this project?

Upvotes: 6

Views: 14660

Answers (4)

Prof. Hell
Prof. Hell

Reputation: 809

use: tf.compat.v1.layers.dense for example, instead of

Z = tf.contrib.layers.fully_connected(F, num_outputs, activation_fn=None)

you can replace it with:

Z = tf.compat.v1.layers.dense(F, num_outputs, activation = None)

Upvotes: 6

Mike Chen
Mike Chen

Reputation: 397

tf.contrib.layers.fully_connected() is a perfect mess. It is a very old historical mark(or a prehistory DNN legacy). Google has completely deprecated the function since Google hated it. There is no any direct function in TensoFlow 2.x to replace tf.contrib.layers.fully_connected(). Therefore, it is not worth inquiring and getting to know the function.

Upvotes: 0

nessuno
nessuno

Reputation: 27052

In TensorFlow 2.0 the package tf.contrib has been removed (and this was a good choice since the whole package was a huge mix of different projects all placed inside the same box), so you can't use it.

In TensorFlow 2.0 we need to use tf.keras.layers.Dense to create a fully connected layer, but more importantly, you have to migrate your codebase to Keras. In fact, you can't define a layer and use it, without creating a tf.keras.Model object that uses it.

Upvotes: 5

qiPeng huang
qiPeng huang

Reputation: 61

tf-slim, as a standalone package, already included tf.contrib.layers.you can install by pip install tf-slim,call it by from tf_slim.layers import layers as _layers; _layers.fully_conntected(..).The same as the original, easy to replace

Upvotes: 6

Related Questions