'tensorflow' has no attribute 'config' error - python

I am trying to run the following lines:
import tensorflow as tf
physical_devices = tf.config.list_physical_devices("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
I am trying to run this lines too:
import tensorflow as tf
physical_devices = tf.test.gpu_device_name("GPU")
for i in range(len(physical_devices)):
tf.config.experimental.set_memory_growth(physical_devices[i], True)
But the first method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 4, in <module>
physical_devices = tf.config.list_physical_devices("GPU")
AttributeError: module 'tensorflow' has no attribute 'config'
And the second method errors out like this:
Traceback (most recent call last):
File "main_train.py", line 5, in <module>
for i in range(len(tf.test.gpu_device_name("GPU"))):
AttributeError: module 'tensorflow' has no attribute 'test'
I am using Tensorflow 2.4.0 .Any ideas what I'm doing wrong?
If anyone could help that would be great:)
Thank's for every help in advance:)

I read that you already fixed it but since you didn't included it in your post here is the solution everyone else having this error: you need to change some modules from e.g. tf.config.list_physical_devices("GPU") to tf.compat.v1.config.list_physical_devices("GPU"). By adding ".compat.v1" you are ensuring backwards capability. You can use this code snippet for all other modules, that don't work.

Related

Getting error with ". prepare_dataset.sh" command from lpot

I am following this github(https://github.com/intel/lpot/tree/master/examples/tensorflow/object_detection) for lpot and in the 5th step for downloading the dataset I am getting the below error.Unable to proceed.
HEAD is now at 7a9934df Merged commit includes the following changes: 184048729 by Zhichao Lu:
Traceback (most recent call last):
File "./object_detection/dataset_tools/create_coco_tf_record.py", line 46, in <module>
flags = tf.app.flags
AttributeError: module 'tensorflow' has no attribute 'app'
mv: cannot stat '/root/lpot/examples/tensorflow/object_detection/data/coco_testdev.record*': No such file or directory
mv: cannot stat '/root/lpot/examples/tensorflow/object_detection/data/coco_train.record*': No such file or directory
mv: cannot stat '/root/lpot/examples/tensorflow/object_detection/data/coco_val.record*': No such file or directory
Thanks in advance.
If it is tensorflow 2.0 or higher version then minor change in create_coco_tf_record.py code will resolve your issue.Replace import tensorflow as tf with import tensorflow.compat.v1 as tf
Regards,
Janani Chandran

module 'pytesseract' has no attribute 'image_to_string'

I've been trying to solve this error for a long time. I have googled this error and find nothing to solve it.
error
Traceback (most recent call last):
File "tess.py", line 6, in <module>
print(pytesseract.image_to_string(Image.open(image_file)))
AttributeError: module 'pytesseract' has no attribute 'image_to_string'
Please also tell me, What would be the "pytesseract.pytesseract.tesseract_cmd = 'System_path_to_tesseract'" for ubuntu
code
from PIL import Image
from pytesseract import *
import pytesseract
image_file = '4.jpg'
print(pytesseract.image_to_string(Image.open(image_file)))
Help me to solve this error
Thanks in advance

module 'pyomo' has no attribute 'AbstractModel'

I have installed pyomo and trying to create a instance model from AbstractModel as follows:
import pyomo as pmo
absmd = pmo.AbstractModel()
Traceback (most recent call last):
File "", line 1, in
absmd = pmo.AbstractModel()
But i am getting the following error:
AttributeError: module 'pyomo' has no attribute 'AbstractModel'
Any advise?
You're importing the wrong stuff. Either use pmo.environ.AbstractModel() or
from pyomo.environ import *
model = AbstractModel()

AttributeError: module 'keras.preprocessing' has no attribute 'text'

When I am trying to import the Tokenizer() function in Keras, I am getting the following error.
I am following official Keras documentation at https://keras.io/preprocessing/text/#tokenizer
import keras
tokenizer = keras.preprocessing.text.Tokenizer()
Getting error like this :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'keras.preprocessing' has no attribute 'text'
Using Keras version '2.1.3'
Where I have done wrong?
You want
from keras.preprocessing import text
tokenizer = text.Tokenizer(...)
The reason is that keras/preprocessing/__init__.py doesn't import nor expose the text submodule

Why scipy.io.wavfile.read does not return a tuple?

I am trying to read a *.wav file using scipy. I do the following:
import scipy
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
As a result of this code I get:
Traceback (most recent call last):
File "test3.py", line 2, in <module>
x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav')
AttributeError: 'module' object has no attribute 'io'
Does anybody know what is wrong here? Thank you in advance.
As the error says, scipy module does not have 'io'.
io.wavfile is a submodule, you need to from scipy.io import wavfile and then do wavfile.read("/usr/share/sounds/purple/receive.wav")
This gives me an error with the file you are using as an example, however...

Categories