Mona Jalal
Mona Jalal

Reputation: 38135

ModuleNotFoundError: No module named 'tensorflow.keras'

I have installed DeepPoseKit using the guide on the github page.

I have the following tensorflow-gpu version:

[jalal@goku examples]$ python -c 'import tensorflow as tf; print(tf.__version__)'
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
1.13.1

How can I fix the following error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-1cceeb3fcd52> in <module>()
      5 import glob
      6 
----> 7 from deepposekit.io import TrainingGenerator, DataGenerator
      8 from deepposekit.augment import FlipAxis
      9 import imgaug.augmenters as iaa

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/__init__.py in <module>()
     18 import warnings
     19 
---> 20 from deepposekit.io import TrainingGenerator, DataGenerator
     21 from deepposekit.augment.FlipAxis import FlipAxis
     22 

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/io/__init__.py in <module>()
     16 from __future__ import absolute_import
     17 
---> 18 from deepposekit.io.BaseGenerator import BaseGenerator
     19 from deepposekit.io.DataGenerator import DataGenerator
     20 from deepposekit.io.ImageGenerator import ImageGenerator

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/deepposekit/io/BaseGenerator.py in <module>()
     14 # limitations under the License.
     15 
---> 16 from tensorflow.keras.utils import Sequence
     17 import numpy as np
     18 

ModuleNotFoundError: No module named 'tensorflow.keras'

My keras version is:

[jalal@goku examples]$ which python 
/scratch/sjn-p3/anaconda/anaconda3/bin/python
[jalal@goku examples]$ python
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 09:07:38) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keras
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
>>> keras.__version__
'2.3.1'
$ uname -a
Linux goku.bu.edu 3.10.0-1062.4.3.el7.x86_64 #1 SMP Wed Nov 13 23:58:53 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.7.1908 (Core)
Release:    7.7.1908
Codename:   Core

My DeepPoseKit version is:

>>> import deepposekit
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
>>> deepposekit.__version__
'0.3.4'

Upvotes: 7

Views: 65612

Answers (7)

aadi
aadi

Reputation: 1

I've been having the same issue for a bit in PyCharm. The solution is quite odd, simply install keras as a package by itself, and then replace imports to import tensorflow.keras to keras.api and it will compile just fine.

Would appreciate it if anyone could give further explanation as to why this works..

Upvotes: 0

Alireza Mohamadi
Alireza Mohamadi

Reputation: 45

Please install the latest versions of these two packages:

pip install tensorflow

and also

pip install Keras

Upvotes: 0

Nim J
Nim J

Reputation: 1033

I had scikeras installed and it was upgraded to newer version , due to which I was getting this error. Reverting to previous version as below worked for me. !pip install scikeras==0.12.0

Upvotes: 0

DaCutePotato
DaCutePotato

Reputation: 11

You don't need "tensorflow.keras" you can directly use for example keras.models. (for me, "import keras.models" worked)

Upvotes: 1

AKV
AKV

Reputation: 1

The issue for me was having a file name as keras.py. The runtime was trying to access objects from this keras file. Renamed it to something else(keras_playpen.py), it just worked.

Upvotes: 0

Tobechukwu Ezenachukwu
Tobechukwu Ezenachukwu

Reputation: 559

Three years after and this is still a major problem. I followed every guide I found online on how to install tensorflow to avoid having this error.

Best output I have so far is that it runs well on Cursor without any errors. Cursor is a new code editor, similar to vs code. cursor download link. This error persists on vs code editor, even though I used the same python environment on both code editor. The environment was created using anaconda.

I wish there's a definitive guide that explains and solves this issue.

vscode output with the error enter image description here

cursor output without the error enter image description here

Upvotes: -1

Sai Krishnadas
Sai Krishnadas

Reputation: 3409

That's because you have an older version of TensorFlow.

pip install tensorflow==1.14.0

This will uninstall the previous version and will install 1.14.0.

This worked for me :)

Upvotes: 2

Related Questions