Reputation: 75
following this tutorial
I am trying to run a pre-written model for TensorFlow, and because I am running TensorFlow 2, and the code I am using was meant for an older version. specifically, tf.contrib.
From original code:
from tensorflow.contrib import legacy_seq2seq
From first fix I found:
from tensorflow.python.ops.seq2seq import sequence_loss
error:
ModuleNotFoundError: No module named 'tensorflow.python.ops.seq2seq'
Where do I find the methods that were in tf.contrib, and import them and use them? Do the old functionalities still exist?
Upvotes: 1
Views: 2385
Reputation: 7353
Please note that tf.contrib has been dropped in TF 2.0. Source
- Removal of tf.contrib - These features have been either moved to TensorFlow Core, or to tensorflow/addons, or are no longer part of the TensorFlow build but are developed and maintained by their respective owners.
- Updated and revised documentation, examples, and website, including migration docs and TF 1.x to 2.0 converter guide.
For example tf.contrib.layers.layer_norm
, according to this github issue got moved to here: https://github.com/tensorflow/addons/tree/master/tensorflow_addons/layers.
seq2seq
is under tensorflow_addons
nowYou can find a github post on how to handle seq2seq
for TF 2.0 under tensorflow_addons: https://github.com/tensorflow/addons/tree/master/tensorflow_addons/seq2seq. It gives you a clear example on how convert TF 1.x seq2seq
into its TF 2.0
equivalent. Look under Sample code and Migration guide from TF 1.X
# TF 2.0
import tensorflow_addons as tfa
sampler = tfa.seq2seq.sampler.TrainingSampler()
1.x
to TF 2.0
UpgradeI would suggest you to first try and migrate the TF 1.x code to TF 2.0. Refer to how to automatically upgrade from TF 1.x to TF 2.0?
Upvotes: 2