AttributeError: module 'torch' has no attribute 'inference_mode' - pytorch

I am very new to pytorch, and when I try to run my CNN, I encountered the Error:
AttributeError: module 'torch' has no attribute 'inference_mode'.
Does anyone know what is going one? It worked on Google colab but no where else.

Try bump the version to 1.13. Reference: https://pytorch.org/docs/stable/generated/torch.inference_mode.html

Most likely its a version issue.
torch.inference_mode() was added recently in v1.9. Make sure you have the correct version.
Try printing torch.__version__ to check your version.

Related

AttributeError: 'Tokenizer' object has no attribute 'oov_token'

I have this issue when I process the text. Do you know how to fix it. I just use pip install keras.
This is a generic Python/Pickle issue, not a Keras issue.
You can set tokenizer.oov_token = None to fix this.
The error was report in github comment

AttributeError: module 'torch.utils' has no attribute 'make_grid'

I tried following along with the PyTorch transfer learning tutorial and found it pulled an error code when I brought up the make grid.
It's because it's out of date. As of 1.11.0 it has been moved to torchvision.utils.make_grid instead of torch.utils.make_grid
https://pytorch.org/vision/main/generated/torchvision.utils.make_grid.html?highlight=make_grid#torchvision.utils.make_grid

AttributeError: module 'tensorflow' has no attribute 'contrib'

I am using someone else code (Code Link) which is implemented in Tensorflow1. I want to run this code into Tensorflow2 However I am getting this error:
mnist = tf.contrib.learn.datasets.load_dataset("mnist")
AttributeError: module 'tensorflow' has no attribute 'contrib'
I upgraded this code by using this instruction:
!tf_upgrade_v2 \
--infile /research/dept8/gds/anafees/MyTest.py \
--outfile /research/dept8/gds/anafees/MyTest2.py
Most things are updated, however generated report showed:
168:21: ERROR: Using member tf.contrib.distribute.MirroredStrategy in deprecated module tf.contrib. tf.contrib.distribute.MirroredStrategy cannot be converted automatically. tf.contrib will not be distributed with TensorFlow 2.0, please consider an alternative in non-contrib TensorFlow, a community-maintained repository such as tensorflow/addons, or fork the required code.
I search google; however, I could not find any suitable solution. I do not want to move back to Tensorflow1. Is there any alternate solution? Can anyone help?
Few libraries are deprecated in Tensorflow 2.x such tf.contrib, To make the code compatible with Tf 2 needs some changes in library.
Replace
tf.contrib.learn.datasets.load_dataset("mnist")
with
tf.keras.datasets.mnist.load_data()
And Replace
tf.contrib.distribute.MirroredStrategy
with
tf.distribute.MirroredStrategy(devices=None, cross_device_ops=None)

Tensorboard: AttributeError: 'Model' object has no attribute '_get_distribution_strategy'

I'm getting this error when i use the tensorboard callback while training.
I tried looking for answers from posts related to tensorboard errors but this exact error was not found in any stackoverflow posts or github issues.
Please let know.
The following versions are installed in my pc:
Tensorflow and Tensorflow GPU : 2.0.0
Tensorboard: 2.0.0
I had the same problem and fixed it with this hack
model._get_distribution_strategy = lambda: None
It seems to be a bug on tensorflow's side.
https://github.com/tensorflow/tensorflow/pull/34870
Remove tensorboard callback for now.
This error mostly happens because of mixed imports from keras and tf.keras. Make sure that throughout the code exact referencing of libraries is maintained. For example instead of model.add(Conv2d()) try model.add(tf.keras.layers.Conv2D()) , applying this for all layers solved the problem for me.

module 'tensorflow' has no attribute 'placeholder'

I am using Tensorflow version 1.3.0 and Tensorboard (0.1.8), and when I am using tf.placeholder(), tf.GLOBAL_VARIABLES() or tf.global_variables_initializer, it get an error like the one in the title. I know that there is an update in the function's syntax for this version, but I can't find what is wrong.
Can anyone help me?

Resources