Keras-ImportError: cannot import name ctc_ops - keras

I have Anaconda 4.3.1 installed in my laptop after the commands cd /home/username/anaconda3and source bin/activate ~/anaconda3 my package starts .
And I installed keras using pip3 conda install keras inside my anaconda. package.and made a document named keras.json inside my keras folder.
When I start my Python in anaconda3 and import keras this happens
>>> import keras'
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tushar/.local/lib/python3.5/site-packages/keras/__init__.py", line 3, in <module>
from . import activations
File "/home/tushar/.local/lib/python3.5/site-packages/keras/activations.py", line 3, in <module>
from . import backend as K
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/__init__.py", line 64, in <module>
from .tensorflow_backend import *
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
from tensorflow.python.ops import ctc_ops as ctc
ImportError: cannot import name 'ctc_ops'
After following this I could not get any solution. I would appreciate any help.

I had this same exact issue (I was using pip instead of conda to install keras / tensorflow, however). Make sure you have the most up-to-date version of tensorflow (tensorflow-1.0.1 as of March 31st, 2017).
sudo pip install tensorflow --upgrade
fixed the problem for me (I was running tensorflow-0.9.0rc0 before and was getting the same ImportError: cannot import name ctc_ops error as you)

Related

How to fix ' module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1''

While training the yolov3 framework, there's always this module error
I have tried reinstalling keras and tensorflow, and the version of keras is 2.3.0 and the version of tensorflow is 1.14.0.
Traceback (most recent call last):
File "train.py", line 6, in <module>
import keras.backend as K
File "F:\Anacoda\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "F:\Anacoda\lib\site-packages\keras\utils\__init__.py", line 27, in <module>
from .multi_gpu_utils import multi_gpu_model
File "F:\Anacoda\lib\site-packages\keras\utils\multi_gpu_utils.py", line 7, in <module>
from ..layers.merge import concatenate
File "F:\Anacoda\lib\site-packages\keras\layers\__init__.py", line 4, in <module>
from ..engine.base_layer import Layer
File "F:\Anacoda\lib\site-packages\keras\engine\__init__.py", line 8, in <module>
from .training import Model
File "F:\Anacoda\lib\site-packages\keras\engine\training.py", line 21, in <module>
from . import training_arrays
File "F:\Anacoda\lib\site-packages\keras\engine\training_arrays.py", line 14, in <module>
from .. import callbacks as cbks
File "F:\Anacoda\lib\site-packages\keras\callbacks\__init__.py", line 19, in <module>
if K.backend() == 'tensorflow' and not K.tensorflow_backend._is_tf_1():
AttributeError: module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1'
I fix this problem by replacing keras.XXX to tensorflow.keras.XXX
try replace
import keras.backend as K
to
import tensorflow.keras.backend as K
import this:
import tensorflow as tf
then use
tf.compat.v1.keras.backend.
as prefix of your desired attribute
I had the same error and tried installing and uninstalling. In the end, I found that the library was not actually installed correctly.
I went through each library in my:
C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\
I tracked down the file in within the site-packages in Keras, which was calling from the Tensorflow library, which was calling from another folder. I found the final folder had the get_session(), but this was not being called in. When I checked the directory, I found that get_session wasn't being loaded in. Within the file directory /tensorflow/keras/backend.py it was importing everything, but missed out the get_session.
To fix this I added this line:
from tensorflow.python.keras.backend import get_session
Then saved it. The next time I ran my code it was fine. I would suggest doing similar with your files, locating where the attribute is called in and making sure it is being imported.
pip3 uninstall keras
pip3 install keras --upgrade
https://github.com/keras-team/keras/issues/13352
installing TensorFlow 1.14.0 + Keras 2.2.5 on Python 3.6 fix this
make sure your keras version is right. if your backbend is tensorflow,you can
import tensorflow as tf
print(tf.VERSION)
print(tf.keras.__version__)
get the right version of keras,then install this version,I fix this problem by this way,i hope my answer can help you.

Importing keras

I'm trying to import keras and the code returns an error about tensorflow.
import numpy
import matplotlib.pyplot as plt
import pandas
import math
from keras.models import Sequential
from keras.layers import Dense
and the error says:
Using TensorFlow backend.
Traceback (most recent call last):
File "C:/Users/gonza/Documents/Projects/jeremiah/neuralNet.py", line 6, in <module>
from keras.models import Sequential
File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
from . import conv_utils
File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
from .. import backend as K
File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
from .tensorflow_backend import *
File "C:\Users\gonza\AppData\Local\Programs\Python\Python37-32\lib\site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
It seems like tensorflow is not found. You need to install tensorflow in order to use keras library.
If you already installed tensorflow, try to uninstall and install it again.
sudo pip3 uninstall tensorflow
pip3 install --upgrade tensorflow
You can verify the install by running this command:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
This error is related to TensorFlow. TensorFlow may not be installed or installed incorrectly. please check TensorFlow installation

Keras import loading neural network

The script normally works on a local machine, but it also fails when it is uploaded to the server. The program falls on the line:
from keras.models import model_from_json
All versions of libraries on a laptop and server are the same. Python 3.6.5, Keras 2.2.4, Tensorflow 1.5.0, Numpy 1.14.3
Error message:
(base) C:\classX5>python app.py
Using TensorFlow backend.
Traceback (most recent call last):
File "app.py", line 8, in <module>
from keras.models import model_from_json
File "C:\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 27, in <mo
dule>
from .multi_gpu_utils import multi_gpu_model
File "C:\Anaconda3\lib\site-packages\keras\utils\multi_gpu_utils.py", line 7,
in <module>
from ..layers.merge import concatenate
File "C:\Anaconda3\lib\site-packages\keras\layers\__init__.py", line 4, in <mo
dule>
from ..engine.base_layer import Layer
File "C:\Anaconda3\lib\site-packages\keras\engine\__init__.py", line 8, in <mo
dule>
from .training import Model
File "C:\Anaconda3\lib\site-packages\keras\engine\training.py", line 21, in <m
odule>
from . import training_arrays
File "C:\Anaconda3\lib\site-packages\keras\engine\training_arrays.py", line 8,
in <module>
from scipy.sparse import issparse
File "C:\Anaconda3\lib\site-packages\scipy\__init__.py", line 119, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Anaconda3\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <mo
dule>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
All versions of libraries on a laptop and server are the same. Python
3.6.5, Keras 2.2.4, Tensorflow 1.5.0, Numpy 1.14.3
But NOT the scipy package.
Just uninstall (pip3 uninstall scipy) and reinstall scipy package. It solved the problem for many people.
Posting my same answer here I posted on the linked question:
This is likely an issue with the SciPy Python module compatibility you have installed in your site-packages folder and the OS architecture you're running it on.
After digging in, to give the full background on this, first of all SciPy relies on having NumPy already installed. The SciPy wheel's setup.py file uses NumPy functionality to configure and install the wheel.
SciPy setup.py:
...
if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
Secondly, when just trying to use the wheel, if you run into this error, you can see after inspecting the wheel's files that the reason is the binary wheels have a naming convention where the shared object file, here it's called _ccallback_c.so, is instead named based on the architecture that the binary wheel supports. When trying to import the shared object by file name in /_lib/_ccallback.py it can't find it, hence this error (line 1 in /_lib/_ccallback.py) because, instead of being named _ccallback_c.so it's called _ccallback_c.cpython-36m-x86_64-linux-gnu.so or another architecture variation:
from . import _ccallback_c
These file names may be an artifact of having not run the NumPy setup process yet or something related to Cython, that I'm not quite sure about. But the easiest fix is to change the .whl extension to .zip and rename all those relevant .so files to not contain the architecture snippet. Then change .zip -> .whl and it should be good to go.

Import Seaborn Error - Numpy_MKL (Python Script)

I coded in jupyter-notebook, fetching data from mysqlserver and then downloaded it as a python script because I want to implement it in my website using cronjob. So when I run the Python script, I'm getting this error:
import seaborn as sns
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\__init__.py", line 6, in <module>
from .rcmod import *
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\rcmod.py", line 5, in <module>
from . import palettes, _orig_rc_params
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\palettes.py", line 12, in <module>
from .utils import desaturate, set_hls_values, get_color_cycle
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\seaborn\utils.py", line 7, in <module>
from scipy import stats
File "C:\Users\Debadri\AppData\Local\Programs\Python\Python36\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
I tried to install numpy+mkl .whl file from this link: Numpy+MKL, this (numpy‑1.15.1+mkl‑cp37‑cp37m‑win_amd64.whl) package, but it showed, not supported when I tried to install it.
The following solution worked out:
Solution:
If you are using windows make sure you install numpy+mkl instead of just numpy.
If you have already installed scipy and numpy, uninstall then using "pip uninstall scipy" and "pip uninstall numpy"
Now download scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy (appropriate version for your python and system)
and install using "pip install scipy‑1.1.0‑cp36‑cp36m‑win_amd64.whl" (Please install from the list according to your system config)
Your numpy and Scipy both should work now.
These binaries by Christoph Gohlke makes it very easy to install python packages on windows. But make sure you download all the dependent packages from there.
Reference: 4th answer of this question ImportError: cannot import name NUMPY_MKL

Error while installing keras in conda using pip

Can anyone help here.
I am trying to install keras in conda using pip and I get below error:
(C:\Users\HARSHALL\Anaconda3) C:\Users\HARSHALL>pip install --upgrade keras
Traceback (most recent call last):
File "C:\Users\HARSHALL\Anaconda3\Scripts\pip-script.py", line 6, in
from pip import main
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip_init_.py", line 28, in
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\vcs\mercurial.py", line 9, in
from pip.download import path_to_url
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\download.py", line 41, in
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
ImportError: No module named 'pip._vendor.requests.adapters'

Resources