How to import BeamSearchDecoder after tensorflow update? - python

from tensorflow.contrib.seq2seq import BeamSearchDecoder as beam_search_decoder
gives
ModuleNotFoundError: No module named 'tensorflow.contrib'
The latest versions of Tensorflow do not contain contrib, so how can I use the function?

BeamSearchDecoder is now part of Tensorflow Addons, which should be installed separately via pip:
pip install tensorflow-addons
After that, you can use it either as you try here:
from tensorflow_addons.seq2seq import BeamSearchDecoder as beam_search_decoder
or directly as suggested in the documentation and the tutorial:
import tensorflow_addons as tfa
tfa.seq2seq.BeamSearchDecoder(...)

Related

Cannot import tensorflow_io

I am getting ModuleNotFoundError when I try to import tensorflow_io.
I tried to fix the error as described in ModuleNotFoundError: No module named 'tensorflow_io' but it didn't work with me
I did the following and I was able to have the module imported in my machine,
pip install tensorflow
pip install tensorflow_io
then in a file.py you can import them
import tensorflow as tf
import tensorflow_io as tfio
I figure you need the tensorflow module installed if you want to use the tensorflow_io.

module 'tensorflow_federated.python' has no attribute 'federated_computation'

I follow the instructions in the github that says to install Tensorflow Federated with Collab we need to install version 0.20.0 but I get this error when I try to run the toturials.
!pip install --quiet tensorflow-federated==0.20.0 # The latest version of tensorflow-federated is not working with the colab python version
!pip install --quiet --upgrade nest-asyncio
from __future__ import absolute_import, division, print_function
import collections
from six.moves import range
import numpy as np
import tensorflow as tf
# from tensorflow import compat
from tensorflow_federated import python as tff
np.random.seed(0)
tf.compat.v1.enable_v2_behavior()
tff.federated_computation(lambda: 'Hello, World!')()
Error:
module 'tensorflow_federated.python' has no attribute 'federated_computation'
What is the problem I don't understand? How can I install it on google colab. There is no resource for this problem.
Are you sure you need to import this
from tensorflow_federated import python as tff
instead of
import tensorflow_federated as tff
According to the Tensorflow docs, the federated_computation was under tensorflow_federated directly.

torchvision and tensorflow-gpu import error

Running this:
import torchvision
import tensorflow
Produces the error:
SystemError: google/protobuf/pyext/descriptor.cc:354: bad argument to internal function
However, swapping the order of the imports does not cause the error:
import tensorflow
import torchvision
Why is this happening?
Version info:
tensorflow-gpu=1.15.0
torchvision==0.5.0
Try reinstalling torchvision.
I have opened a ticket on tensorflow. My guess is that the order in which you install torchvision matters:
The fix is either to reinstall torchvision or to always import tensorflow first, as shown above. The issue is difficult to reproduce since fresh install fixes things. Perhaps it is related to the order in which packages are installed -- perhaps torchvision is somehow targeting older tensorflow-related libraries... and updating it again fixes this.
This fix:
import tensorflow # BEFORE all other imports
import torchvision
It works for me.
Source: https://github.com/tensorflow/tensorflow/issues/48797

ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine'

I'm getting this error while loading the tensorflow addons library
import tensorflow_addons as tfa
ImportError: cannot import name 'keras_tensor' from 'tensorflow.python.keras.engine'
This error is because you have incompatibility issues between your TensorFlow, Python and tensorflow-addons. Uninstall the tensorflow-addons and install the version based on the table below. Refer the Github repo for more information.

TFLearn import issue - no module core_rnn

I am testing out the TFLearn library for using TensorFlow but can't import it due to some config issue. I installed it as required in TFLearn tutorial though. Thankful for any help.
>>> import tflearn as tf
> import tflearn
File "//anaconda/lib/python2.7/site-packages/tflearn/__init__.py", line 4, in <module>
from . import config
ImportError: cannot import name config
This is caused due to incompatibilitiy of TFlearn and Tensorflow. They may be of different version. Hence, to resolve the issue, uninstall tensorflow and tflearn and reinstall them using the following code -
pip uninstall tflearn
pip uninstall tensorflow
pip install -I tensorflow==0.12.1
pip install -I tflearn==0.2.1

Categories

Resources