Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 projcet?

like image 556
hkitano Avatar asked Jan 01 '23 14:01

hkitano


2 Answers

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

like image 158
qiPeng huang Avatar answered Jan 03 '23 05:01

qiPeng huang


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.

like image 29
nessuno Avatar answered Jan 03 '23 04:01

nessuno