Need help transferring a TensorFlow1 project to TensorFlow2

I found this project that I would like to use with TensorFlow2 (I’ll use it in openFrameworks with the ofxTensorFlow2 addon that builds on version2), but it is written for TensorFlow1. I read about migrating from TensorFlow1 to 2 here and tried a the automated script, but it didn’t work.

For now, the main issue is the tensorflow.contrib submodule, which is not present in version 2. This is used in model.py, in lines 2 and 3. I have no idea which submodules I should use to replace rnn and legacy_seq2seq from the contrib submodule.

Can anyone help with this?

Hi @AlexandrosDrymonitis, For tf.contrib.rnn layers you can use tf.keras.layers and for migrating tf.contrib.legacy_seq2seq please refer to this sample code. Thank You.

Hi @Kiran_Sai_Ramineni. Thanks for your reply. I got over these first two errors, but now I’m getting the following:

Traceback (most recent call last):
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/char-rnn-tensorflow_v2/train.py", line 11, in <module>
    from model import Model
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/char-rnn-tensorflow_v2/model.py", line 3, in <module>
    from tensorflow_addons import seq2seq
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/venv/lib/python3.11/site-packages/tensorflow_addons/__init__.py", line 23, in <module>
    from tensorflow_addons import activations
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/venv/lib/python3.11/site-packages/tensorflow_addons/activations/__init__.py", line 17, in <module>
    from tensorflow_addons.activations.gelu import gelu
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/venv/lib/python3.11/site-packages/tensorflow_addons/activations/gelu.py", line 19, in <module>
    from tensorflow_addons.utils.types import TensorLike
  File "/home/alex/Documents/python/TensorFlow_various/TensorFlow2/venv/lib/python3.11/site-packages/tensorflow_addons/utils/types.py", line 29, in <module>
    from keras.src.engine import keras_tensor
ModuleNotFoundError: No module named 'keras.src.engine'

which, from what I understand, is not related to the code I’m trying to use, but from a cascade of module importing. Any idea how to solve this?

Found that installing tfa-nightly with pip solves keras.src.engine issue. Will keep digging to see if I can get this working.
It’s a pitty that so many new releases break compatibility, makes it hard to use this software.