I have a problem with my python code that uses tf.contrib.slim
functionalities and no longer works after upgrading to tensorflow to 2.0.
How can I upgrade the following to tf 2.0:
import tensorflow.contrib.slim as slim
import tensorflow.contrib.slim.nets
# ...
net = slim.conv2d(
inp,
dim,
[3, 3],
rate=1,
normalizer_fn=slim.layer_norm,
activation_fn=lrelu,
scope='g_' + str(width) + '_conv1')
Thanks.
TF-slim is a new lightweight high-level API of TensorFlow ( tensorflow. contrib. slim ) for defining, training and evaluating complex models. This directory contains code for training and evaluating several widely used Convolutional Neural Network (CNN) image classification models using TF-slim.
(As per the TensorFlow team) It is important to understand that there is no battle of TensorFlow 1.0 vs TensorFlow 2.0 as TensorFlow 2.0 is the updated version and hence clearly better and smarter. It was built keeping in mind the drawbacks of TensorFlow 1.0 which was particularly hard to use and understand.
TensorFlow-Slim (TF-Slim) is a TensorFlow wrapper library that allows you to build and train complex TensorFlow models in an easy, intuitive way by eliminating the boilerplate code that plagues many deep learning algorithms.
You can use tf_slim
package instead (https://github.com/google-research/tf-slim)
However, the push request updating the package to TF2 is still pending. So you should install from the branch
pip install git+https://github.com/adrianc-a/tf-slim.git@remove_contrib
That might do it:
net = tf.keras.layers.Conv2D(filters=dim, kernel_size=3, name='g_' + str(width) + '_conv1')(inp)
net = tf.keras.layers.BatchNormalization()(net)
net = tf.keras.layers.LeakyReLU()(net)
Using slim, there's an option to mention which batch normalization and activation you want to have after the convolution layer. You can't do it in 2.0, so you need to specify exactly which normalization and activation you want in 2 different layers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With