I am trying to use keras for image classification. I want to load an already trained model (VGG16) for my project. but when I run
from keras.applications.vgg16 import VGG16
I get an error.
ImportError: cannot import name 'abs'
I reinstalled both tensorflow and keras using :
pip install --ignore-installed --upgrade tensorflow
conda install -c conda-forge keras
since I have found some suggestions that reinstalling could help on here though it was related tfp not VGG16.
Could someone help me, please? Why I am getting this error and how could I fix it?
OS:windows
Tensorflow and keras installed on CPU
after all trying to install tensorflow and keras in a virtual environment solved the problem. Still, don't know why this problem existed in the first place. steps are taken:
conda create --name vgg16project python # you can name it other than vgg16project
activate vgg16project
then install other packages you need such as pandas, seaborn etc. then installing tensorflow and keras with pip
pip install --upgrade tensorflow
pip install --upgrade keras
simply solved it. I guess there must be a reason why it is recommended to use tensorflow and keras in a virtual environment.
I was having similar issue with keras cannot import abs. Tried updating and found tensorflow file was still in use.
Could not install packages due to an EnvironmentError: [WinError 32] The process
cannot access the file because it is being used by another process: 'c:\progra
m files (x86)\microsoft visual studio\shared\python36_64\Lib\site-packages\
\tensorflow\python\ops\gen_dataset_ops.py'
Consider using the --user option or check the permissions.
After uninstalling keras and tensorflow - I deleted the whole tensorflow folder and reinstalled both tensorflow 1.10 and keras. This resolved my issue.
I had the same issue and just uninstalled (and deleted) tensorflow.
After that I installed it again with:
pip install tensorflow-gpu==2.0.0-rc1
I tried something like three different versions before getting it to work.
Related
I am trying to use BERT with bert-serving-start in python3.8 but it does not initialise and throws error:
TypeError: cannot unpack non-iterable NoneType object
This may have something to do with the path not being recognised but I followed the instructions as follows: https://github.com/hanxiao/bert-as-service#install
My folder is unzipped and entire model path is:
C:\Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12
This occurs when running this in the command line as instructed.
bert-serving-start
-model_dir \Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12 -num_worker=1
I don't know if this is a bug to report as it does say untested with the current Tensorflow but it may just be a mistake I made.
Was hoping someone could double check it's not me before submitting a bug report.
Short Answer
You are using too new a version of Tensorflow. BERT-as-a-Service works only with a TF version between 1.10.0 and 1.15.0. Once you install the old version of Tensorflow, this error would go away. Also, use the absolute path, instead of relative path for the model_dir directory.
Long Answer
If you are on the latest version of Python and hence pip, you wouldn't be able to get TF 1.x versions. Currently TF 2.3.0 is out there. The oldest version of TF pip can get for you is 2.1.0cr1. But you can do the following to get say v1.15.0 of Tensorflow:
Create a virtual environment with Python v3.7.6 that comes with old version of pip.
Activate the new virtual environment.
Install v1.15.0 of Tensorflow
Install Bert server in this virtual environment.
Start the Bert server
You don't have to install bert client in this virtual environment. You can continue using the bert client in the base environment. It will still work.
conda create -n test python=3.7.6
conda activate test
pip install tensorflow==1.15.0
pip install bert-serving-server
bert-serving-start -model_dir C:\Users\VHS\uncased_L-12_H-768_A-12\ -num_worker=2
I got this error with various versions including 1.15.0, 1.15.2, 1.15,3 but found it worked with 1.14.0, 1.15.4 and 1.15.5 when upgrading incrementally
Adding to the answer by #VHS, the following works (using tensorflow 1.13.0rc1).
conda create -n test python=3.7.6
conda activate test
pip install tensorflow==1.13.0rc1
pip install bert-serving-server
bert-serving-start -model_dir /path/to/pretrained/bert/uncased_L-12_H-768_A-12/ -num_worker=4
For me, installing frash env with tensorflow 1.11.0 did the trick,
also in the doc's https://github.com/google-research/bert it state they used 1.11.0
python 3.7.3 and tensorflow 1.15.0 works for me. be careful about the numpy version, my version is 1.18, too advanced will cause the same error
I'm using anaconda ver 3, and I have installed python as well separately from anaconda. I installed python ver 2.7 and ver 3.6 from python website.
Now, I have installed keras from anaconda command prompt by using conda install keras. However, when I open jupyter notebook and write :
import keras
it says :
no module named keras
I also tried importing tensorflow but it gave me the same error
As far as i know, keras is a version of tensorflow. You should try installing tensorflow instead and then run
import tensorflow as tf
tf.__version__
if you get '2.1.0' or any 2., you should be all set!
EDIT1: Keras is part of tensorflow not a version (as pointed out in the comments).
EDIT2: The link below gives good details on environments activation/creation.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Okay so what I did is first updated anaconda by using :
conda update conda
and then I installed python :
conda install python=3.7
and finally I installed keras again :
conda install keras
And now I can import both packages of keras and tenserflow
I am trying to develop some time-series sequence prediction, using the latest resources available. To that end, I did check the example code from TensorFlow time-series, but I'm getting this error:
AttributeError: module 'tensorflow.python.pywrap_tensorflow' has no attribute 'TFE_Py_RegisterExceptionClass'
I'm using Anaconda. The current environment is Python 3.5 and TensorFlow 1.2.1. Also tried TensorFlow 1.3, but nothing changed.
Here is the code I'm trying to run. I did not find anything useful related to the issue on Google. Any ideas on how to solve it?
As Conan.Net wrote:
I tried to remove/clean some environments from anaconda and install
all again and it work this time.
This solution worked for me as well, so though not ideal, it will solve the problem. If you are using anaconda, it might happen when installing some packages and then removing them (e.g. tensorflow vs tensorflow-gpu) leaves some dependencies hanging. In my case, I used:
conda remove --name py2_tf_gpu --all
then
conda create --name py2_tf_gpu python=2 anaconda pandas numpy scipy jupyter
source activate py2_tf_gpu
pip install --ignore-installed --upgrade tensorflow-gpu
pip currently installs a later(1.4) than anaconda(1.3) version and I had need for it.
Maybe the version of tensorflow doesn't match the version of keras.
Using a lower version of keras solve this problem
I'm trying to install tensorflow with gpu support into a conda environment
I use the command:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl
When I look at the packages installed with conda list I wind up with a package called tensorflow-gpu.
You cannot even import this package because it has a '-' in it.
How can I change the name to 'tensorflow'?
Edit: I'm now thinking that there must be something more to this. Why would a major package in the deep learning community have this apparent problem. Hopefully, a tensorflow expert can answer. I'm following the directions for Ubuntu and Anaconda here: https://www.tensorflow.org/install/install_linux
When you install the tensorflow gpu version, Anaconda will show that you have installed tensorflow-gpu. The -gpu just indicates that it is a gpu version and is not a part of the name. You can still just import tensorflow and the gpu version will be found.
I had a similar problem which was quite frustrating. I started with recently built .whl file and tried to install.
pip install /home/ubuntu/xfer/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl
Command line testing:
pip show tensorflow
no package called tensorflow
pip show tensorflow-gpu
but there is a package tensorflow-gpu at version 1.2.1
However, running one line in python failed despite assurances that conda would substitute:
import tensorflow as tf
I then repeated the pip install of the .whl file with the --upgrade option:
pip install --upgrade /home/ubuntu/xfer/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl
And then the one line of python succeeded:
import tensorflow as tf
And in fact based on https://www.tensorflow.org/install/install_linux#run_a_short_tensorflow_program, one would then run a slightly longer program which also succeeds:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
I'm trying to get TensorFlow to work on my Mac (OSX El Capitan 10.11.2). I tried the pip install from the setup guide and also followed the instructions in the accepted answer here.
In both cases I am able to successfully activate the virtualenv and my prompt changes to tensorflow. Python works fine, I'm able to do simple computations on the command line. But when I try to import tensorflow:
import tensorflow as tf
I repeatedly get this error:
ImportError: No module named tensorflow
Any help would be appreciated.
I had the issue reported in the original question. Python worked fine, I followed the installation steps on the Tensforflow website, and got "No module named tensorflow."
Re-installing python via brew, and re-installing pip as a result, fixed it. I didn't need to uninstall anything, just the line below along with the normal pip install from the tensorflow installation document afterwards:
brew install python