Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Error with Tensorflow as Backend #6545

Closed
stephenhky opened this issue May 8, 2017 · 18 comments
Closed

Import Error with Tensorflow as Backend #6545

stephenhky opened this issue May 8, 2017 · 18 comments

Comments

@stephenhky
Copy link

I ran with the latest version of tensorflow and keras. I didn't experience an import problem with theano as the backend. And when I put tensorflow as the backend, I saw the following message:

`
In [1]: import keras
Using TensorFlow backend.

AttributeError Traceback (most recent call last)
in ()
----> 1 import keras

//anaconda/lib/python2.7/site-packages/keras/init.py in ()
1 from future import absolute_import
2
----> 3 from . import activations
4 from . import applications
5 from . import backend

//anaconda/lib/python2.7/site-packages/keras/activations.py in ()
4 from . import backend as K
5 from .utils.generic_utils import deserialize_keras_object
----> 6 from .engine import Layer
7
8

//anaconda/lib/python2.7/site-packages/keras/engine/init.py in ()
6 from .topology import Layer
7 from .topology import get_source_inputs
----> 8 from .training import Model

//anaconda/lib/python2.7/site-packages/keras/engine/training.py in ()
22 from .. import metrics as metrics_module
23 from ..utils.generic_utils import Progbar
---> 24 from .. import callbacks as cbks
25 from ..legacy import interfaces
26

//anaconda/lib/python2.7/site-packages/keras/callbacks.py in ()
24 if K.backend() == 'tensorflow':
25 import tensorflow as tf
---> 26 from tensorflow.contrib.tensorboard.plugins import projector
27
28

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/init.py in ()
28 from tensorflow.contrib import deprecated
29 from tensorflow.contrib import distributions
---> 30 from tensorflow.contrib import factorization
31 from tensorflow.contrib import framework
32 from tensorflow.contrib import graph_editor

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/factorization/init.py in ()
22 from tensorflow.contrib.factorization.python.ops.clustering_ops import *
23 from tensorflow.contrib.factorization.python.ops.factorization_ops import *
---> 24 from tensorflow.contrib.factorization.python.ops.gmm import *
25 from tensorflow.contrib.factorization.python.ops.gmm_ops import *
26 # pylint: enable=wildcard-import

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/factorization/python/ops/gmm.py in ()
25 from tensorflow.contrib.framework.python.framework import checkpoint_utils
26 from tensorflow.contrib.framework.python.ops import variables
---> 27 from tensorflow.contrib.learn.python.learn.estimators import estimator
28 from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib
29 from tensorflow.python.framework import constant_op

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/init.py in ()
85
86 # pylint: disable=wildcard-import
---> 87 from tensorflow.contrib.learn.python.learn import *
88 # pylint: enable=wildcard-import
89

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/init.py in ()
21
22 # pylint: disable=wildcard-import
---> 23 from tensorflow.contrib.learn.python.learn import *
24 # pylint: enable=wildcard-import

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/init.py in ()
23 from tensorflow.contrib.learn.python.learn import basic_session_run_hooks
24 from tensorflow.contrib.learn.python.learn import datasets
---> 25 from tensorflow.contrib.learn.python.learn import estimators
26 from tensorflow.contrib.learn.python.learn import graph_actions
27 from tensorflow.contrib.learn.python.learn import learn_io as io

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/init.py in ()
295 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
296 from tensorflow.contrib.learn.python.learn.estimators.constants import ProblemType
--> 297 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNClassifier
298 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNEstimator
299 from tensorflow.contrib.learn.python.learn.estimators.dnn import DNNRegressor

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn.py in ()
27 from tensorflow.contrib.layers.python.layers import optimizers
28 from tensorflow.contrib.learn.python.learn import metric_spec
---> 29 from tensorflow.contrib.learn.python.learn.estimators import dnn_linear_combined
30 from tensorflow.contrib.learn.python.learn.estimators import estimator
31 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/dnn_linear_combined.py in ()
29 from tensorflow.contrib.layers.python.layers import optimizers
30 from tensorflow.contrib.learn.python.learn import metric_spec
---> 31 from tensorflow.contrib.learn.python.learn.estimators import estimator
32 from tensorflow.contrib.learn.python.learn.estimators import head as head_lib
33 from tensorflow.contrib.learn.python.learn.estimators import model_fn

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/estimators/estimator.py in ()
47 from tensorflow.contrib.learn.python.learn.estimators import tensor_signature
48 from tensorflow.contrib.learn.python.learn.estimators._sklearn import NotFittedError
---> 49 from tensorflow.contrib.learn.python.learn.learn_io import data_feeder
50 from tensorflow.contrib.learn.python.learn.utils import export
51 from tensorflow.contrib.learn.python.learn.utils import saved_model_export_utils

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/init.py in ()
19 from future import print_function
20
---> 21 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_data
22 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import extract_dask_labels
23 from tensorflow.contrib.learn.python.learn.learn_io.dask_io import HAS_DASK

//anaconda/lib/python2.7/site-packages/tensorflow/contrib/learn/python/learn/learn_io/dask_io.py in ()
24 try:
25 # pylint: disable=g-import-not-at-top
---> 26 import dask.dataframe as dd
27 allowed_classes = (dd.Series, dd.DataFrame)
28 HAS_DASK = True

//anaconda/lib/python2.7/site-packages/dask/dataframe/init.py in ()
1 from future import print_function, division, absolute_import
2
----> 3 from .core import (DataFrame, Series, Index, _Frame, map_partitions,
4 repartition)
5 from .io import (from_array, from_bcolz, from_array, from_bcolz,

//anaconda/lib/python2.7/site-packages/dask/dataframe/core.py in ()
36 return_scalar = 'return_scalar'
37
---> 38 pd.computation.expressions.set_use_numexpr(False)
39
40

AttributeError: 'module' object has no attribute 'computation'
`

However, I did not experience any error when simply import tensorflow directly:

import tensorflow

@gokceneraslan
Copy link
Contributor

Which version of tensorflow do you have e.g. the output of import tensorflow; print tensorflow.__version__

@stephenhky
Copy link
Author

Mine is 1.1.0

@gokceneraslan
Copy link
Contributor

Can you run from tensorflow.contrib.tensorboard.plugins import projector manually as well? I guess this should be reported to tensorflow and/or dask.

@gokceneraslan
Copy link
Contributor

Can you try updating dask and pandas packages?

@stephenhky
Copy link
Author

My pandas package is updated.

For dask package, before updating it, running from tensorflow.contrib.tensorboard.plugins import projector gives the same error message. But after updating dask, the error message dissappeared, by running this import and import keras (with Tensorflow backend)

It looks like it is resolved.

@abedkhooli
Copy link

Ran through same issue and applied same fix (update dask). Most likely this was caused by updating pandas to recent version (saw it after updating pandas to 0.20.1).

@xfsm1912
Copy link

Just update dask to 0.15.0, the problem will disappear

@stephenhky
Copy link
Author

Great to hear that!

@chimera9900
Copy link

Thanks so much once I updated dask and pandas, works now

@gionatarogiani
Copy link

gionatarogiani commented Dec 12, 2017

Hi, I have a similar issue.
I'm working with ubuntu 16.04, keras 2.1.2, tensorflow 1.3.0 and pandas 0.21.0, dask 0.16.0.
If I try to import anything from keras, after I imported pandas i get the following error:

ImportError: /folder_name/../lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /folder_name/anaconda3/lib/python3.6/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so)

If I import the things I need from keras before importing pandas everything works fine.
Any idea how to fix this or why it happens?
I read that downgrading pandas should work, but that would cause me some compatibility issues.
Thanks

@rsalomon
Copy link

Hi I had similar issue and was able to fix by reinstalling TensorFlow using
sudo conda install tensorflow

This allows and gave permission to downgrade to the compatible
numba: 0.35.0-np113py36_6 --> 0.35.0-np112py36_0 numpy: 1.13.3-py36h2cdce51_0 --> 1.12.1-py36h8871d66_1

@akshatk05
Copy link

i have been having a similar error for a while now the error is ModuleNotFoundError: no module named tensorflow.contrib:tensorflow is not a package

could someone please help me out with this

@Qaazi
Copy link

Qaazi commented Apr 28, 2019

Big problem that wasted a week of mine
small solution
if keras is giving import problem and you are facing "no module named keras" even if you have installed it.

  1. just upgrade your pip by:
    python -m pip install –upgrade pip

re install upgraded keras and tensorflow by:
2. pip install keras

  1. pip install tensorflow

Hope it will solve the problem. If not, try upgrading your conda (Anaconda) and then do steps 1 to 3 above again

@phamquiluan
Copy link

pip install Keras==2.2.4 solved my same problem.

@Anjali0208
Copy link

i have keras version== 2.2.4 , tensorflow version == 2.0.0b1, numpy version version == 1.16.1 and i m still getting error

@Anjali0208
Copy link

MY CODE

from imageai.Detection import ObjectDetection
import os

execution_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromImage(input_image=os.path.join(execution_path , "traffic.jpeg"), output_image_path=os.path.join(execution_path , "traffic.jpeg"))

for eachObject in detections:
print(eachObject["name"] , " : " , eachObject["percentage_probability"] )

AND I M GETTING THIS ERROR

Using TensorFlow backend.
Traceback (most recent call last):
File "C:/Users/Atul Raj/PycharmProjects/Projects/expression.py", line 6, in
detector = ObjectDetection()
File "C:\python37\lib\site-packages\imageai\Detection_init_.py", line 88, in init
self.sess = K.get_session()
File "C:\python37\lib\site-packages\keras\backend\tensorflow_backend.py", line 174, in get_session
default_session = tf.get_default_session()
AttributeError: module 'tensorflow' has no attribute 'get_default_session'

PLEASE HELP ME SOLVING THIS ERROR

@ghost
Copy link

ghost commented Jul 15, 2019

Same error not solve in my system using instructions given above in various replies.
ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'
How to resolve it.
??

@Anjali0208
Copy link

Same error not solve in my system using instructions given above in various replies.
ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'
How to resolve it.
??

I think you should install keras
command- pip install keras

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests