torchvision and tensorflow-gpu import error - python

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

Related

ImportError: cannot import name '_log_class_usage' from 'torchtext.utils'

I recently updated pytorch and torchtext from anaconda, in order to run this tutorial from the torchtext website, but it seems that my installation of torchtext has been broken. Everytime that I try import torchtext I get the following error:
ImportError: cannot import name '_log_class_usage' from 'torchtext.utils' (c:\Users\ferdi\anaconda3\lib\site-packages\torchtext\utils.py)
Uninstalling torchtext then reinstalling with conda install -c pytorch torchtext does not help.
Does anybody have an idea for how to solve it? My torch version is 1.13.0.

Unable to import patch sklearn

after importing and installing required packages and libraries I am encountering an import error on patch_sklearn().
from sklearnx import patch_sklearn()
patch_sklearn()
ImportError: cannot import name 'sparse_lsqr' from 'sklearn.utils.fixes' (C:\Users\yogis\AppData\Roaming\Python\Python38\site-packages\sklearn\utils\fixes.py)
Didn't know what you want to do here.
But you can try this:
from sklearn.feature_extraction.image import extract_patches_2d
You must install scikit learn version 1.0 and not 1.1
pip install scikit-learn==1.0
Then after this, restart kernel. If it doesn't work after this, I also had to force reinstall the other packages for conda.
conda install numpy scipy joblib scikit-learn --force-reinstall
and then restart kernel. It worked fine. This is a known bug and is fixed on pypi releases but not yet on conda.

cannot import name 'normalization' from 'tensorflow.python.keras.layers'

I am trying to use tensorflow_rankings, but cannot import it due to the above error. I am using tensorflow 2.8.0 and tensorflow_rankings 0.5.0, which seem to be the latest stable builds. They are what get automatically installed from
pip install tensorflow
pip install tensorflow_ranking
I am on Python 3.8.10, Windows 11.
The TF 2.8.0 docs show there is a Normalization layer in tf.keras.layers. The error seems to come from:
from tensorflow.python.keras.layers import normalization as keras_norm
in
from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
Any advice?
Seems my installation of TF was corrupted. A full uninstall and reinstall fixed it.

\_tfq_simulate_ops.so not found while import tensorflow_quantum

Trying import of initial libraries related to tensorflow_quantum:
import tensorflow as tf
import tensorflow_quantum as tfq
import cirq
import sympy
import numpy as np
Getting error in 2nd line:
File "Path_to_anaconda_site_packages\tensorflow_core\python\framework\load_library.py", line 61, in load_op_library
lib_handle = py_tf.TF_LoadLibrary(library_filename)
NotFoundError: Path_To_Tensorflow_Quantum\core\ops\_tfq_simulate_ops.so not found
This is the solution provided by the Tensorflow team, it worked for me.
!pip install tensorflow-gpu==2.1.0
!pip install cirq==0.7.0 pathos==0.2.5 tensorflow-quantum==0.2.0
Do following steps:
!pip uninstall tensorflow
!pip install tensorflow
then restart runtime to import the packages.It works.
This might be something that would be worth raising as an issue on the TensorFlow Quantum Github here (https://github.com/tensorflow/quantum/issues). Without much information on the platform your are using or even what python version you have it might be hard to diagnose the problem here, but a quick fix you could try might be that you have an older version of TensorFlow installed. TensorFlow Quantum requires tf == 2.1.0.
pip install --upgrade pip
pip install --upgrade tensorflow
If that doesn't do it, then it might be worth opening an issue on github and giving a few more details on there :)

AttributeError: module 'tensorflow' has no attribute 'name_scope' with Keras

I am trying to run a script, but I struggle already at the imports.
This import
from keras.preprocessing.image import save_img
raises the following error:
AttributeError: module 'tensorflow' has no attribute 'name_scope'.
I am using the following packages.
Keras 2.2.2,
Keras-Applications 1.0.4,
Keras-Preprocessing 1.0.2,
tensorflow 1.9.0,
tensorflow-gpu 1.9.0
I was unable to reproduce with the same versions of the keras and tensorflow, reinstalling keras and tensorflow, may solve the issue, please use commands below:
pip install --upgrade pip setuptools wheel
pip install -I tensorflow
pip install -I keras
NOTE: The -I parameter stands for ignore installed package.
For everyone who use Tensorflow 2.0 and stumble upon this question with the same error, like I did: I solved it by changing the imports from keras.xxx to tensorflow.keras.xxx
I also encountered this same problem when I stopped my IDE while executing. Restarting my IDE works for me. Just save your program and restart IDE. Hope it will work for you as well.
As Andriy Ivaneyko mentioned above, reinstalling tensorflow helps. I'm not sure why, but installing tensorflow-serving-api breaks something somewhere along the way. We solved this by running:
pip install --force-reinstall tensorflow
Note that this applies to both tensorflow and tensorflow-gpu installations. Specifically, the above command will fix this problem in situations where you're specifically using tensorlfow-gpu. tensorflow-serving-api installs regular tensorflow if it's not already installed.
I encountered this same bug and reinstalling tensorflow made no difference, and this caused me some headscratching.
Eventually I noticed that my IDE autocomplete had added the following line to my code:
from tensorflow_core.python.keras.callbacks import EarlyStopping
It seems that directly referencing tensorflow_core.python will break tensorflow.
Replacing this with the normal tensorflow import solved the problem!
from tensorflow.keras.callbacks import EarlyStopping
My IDE offered me two different import paths
keras
or
tensorflow_core.python.keras
In my example I could either import like this:
from keras.layers import Dense, Dropout, LSTM, Input, Activation
from keras import optimizers, Model
or like that:
from tensorflow_core.python.keras import Input, Model, optimizers
from tensorflow_core.python.keras.layers import LSTM, Dropout, Dense
Mixing up tensorflow_core.python.keras and plain keras led to the problem in my case. After I imported everything directly from keras and keras.layers, it worked for me.
My tensorflow version is 2.1, and I found my tensorflow-estimator version is 2.2
My fix is to downgrade the estimator to the same version

Categories

Resources