What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)

I wrote it in the sample code for beginners of TensorFlow RNN (Try RNN of TensorFlow with a basic model), but the version of TensorFlow has been upgraded. There are some parts that are stuck, so I will briefly summarize them.

environment

OSX python 3.5 TensorFlow r0.11

import

When performing RNN related inport, up to v.0.8

from tensorflow.models.rnn import rnn, rnn_cell

However, due to a problem related to repackaging,

ImportError: This module is deprecated.  Use tf.nn.rnn_* instead.

I get the error.

Therefore, the import part of rnn and rnn_cell is deleted, and the part using rnn and rnn_cell is deleted.

# rnn_cell.BasicLSTMCell( ->
tf.nn.rnn_cell.BasicLSTMCell(...

# rnn( ->
tf.nn.rnn(...

Please change it to.

BasicLSTMCell

Even if you fix the above error


cell = tf.nn.rnn_cell.BasicLSTMCell(
    num_of_hidden_nodes, forget_bias=forget_bias)
rnn_output, states_op = tf.nn.rnn(cell, in4, initial_state=istate_ph)

In the part like

TypeError: 'Tensor' object is not iterable.

Error may be thrown.

This is because the default argument of `` `BasicLSTMCellhas changed, and state_is_tuple```, which determines whether tuple type is allowed or combined as the return value format, has changed from False to True. Because it is.

Therefore, if it is the above code


cell = tf.nn.rnn_cell.BasicLSTMCell(
    num_of_hidden_nodes, forget_bias=forget_bias, state_is_tuple=False)
rnn_output, states_op = tf.nn.rnn(cell, in4, initial_state=istate_ph)

And state_is_tuple = False should be specified in the argument of BasicLSTMCell. However, regarding this, the Official Document states that it will be abolished soon. Eventually, it will be necessary to change the writing style again.

reference

Recommended Posts

What to do if an error occurs in TensorFlow RNN related import or RNN (LSTM) Cell (v 0.11r ~)
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do when an error occurs with import _ssl
[Beanstalk] What to do when an error occurs with import uuid
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if an error occurs when importing numpy with VScode
[OSX] [pyenv] What to do when an SSL error occurs in pip
[python] What to do when an error occurs in send_keys of headless chrome
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if a version error occurs in the selenium Chrome driver
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do if a UnicodeDecodeError occurs in pip
What to do if the print command itself causes an error in Maya python
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you run python in IntelliJ and end with an error
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get an error saying c compiler cannot create executables in configure
What to do if pip --user returns an error in a virtual environment created with pyenv
What to do if you can't find PDO in Laravel or CakePHP
What to do if pyenv install does not proceed with an error
[Python] What to do when an error related to SSL authentication is returned
What to do if you get an error when trying to load mnist
What to do if you get an error when installing Dlib (Ubuntu)
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if you get a "No versions found" error in pipenv
What to do if pipreqs results in UnicodeDecodeError
What to do when SSL error occurs in pip in Windows10, miniconda, VScode environment
What to do if you get an error when installing python with pyenv
[Python] Type Error:'WebElement' object is not iterable What to do when an error occurs
What to do if you get an "unknown service" error from your gRPC server
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if pip install fails in Xcode 5.1
What to do if you get an error like dyld: mach-o, but built for simulator or dyld: attempt to run simulator program outside simulator (DYLD_ROOT_PATH not set) in golang
What to do if you get an error when vagrant up when you enable public_network or private_network on Vagrant + Arch Linux → Install netctl
What to do if Fatal Python error: Py_Initialize: can't initialize sys standard streams LookupError: unknown encoding: windows-31j occurs in PyCharm
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
What to do if pip gives a DistributionError in Homebrew
What to do when a Remove Error occurs when updating conda
What to do if you get "coverage unknown" in Coveralls
What to do if you can't log in as root
EC2 / Amazon Linux2: What to do if you get an "unable to execute'gcc': No such file or directory" error with pip install
What to do if an error message "There was a problem displaying this web page" is displayed in Chrome's Web Driver (Selenium)
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you get a minus zero in Python
What to do if intellisense doesn't work with Anaconda + VSCode + Tensorflow2.1
What to do if "Unnamed: 0" is added in to_csv-> read_csv in pandas
What to do if you can't use the trash in Lubuntu 18.04.
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do if you get the error Input contains NaN, infinity or a value too large for dtype ('float64'). In machine learning
What to do if yum breaks
What to do if there is a decimal in python json .dumps
What to do if you couldn't send an email to Yahoo with Python.