ModuleNotFoundError:没有名为“ tensorflow.keras”的模块

时间:2019-12-08 01:48:57

标签: python tensorflow keras

我已经使用github页面上的指南安装了DeepPoseKit

我有以下tensorflow-gpu版本:

                            Web webSite = ctx.Web;
                            ctx.Load(webSite);
                            ctx.ExecuteQuery();
                            List list = ctx.Web.Lists.GetByTitle("TempDoc");
                            ctx.Load(list);
                            var lst = ctx.Web.Lists.GetByTitle("TempDoc");
                            var fld1 = lst.RootFolder.Folders.Add(FolderName);
                            fld1.Update();
                            ctx.ExecuteQuery();
                            foldersatus = true;



                            try
                            {
                                int FileLen;
                                FileLen = Request.Files[upload].ContentLength;
                                byte[] input = new byte[FileLen];
                                System.IO.Stream fileStream;
                                // Initialize the stream.
                                fileStream = Request.Files[upload].InputStream;
                                // Read the file into the byte array.
                                fileStream.Read(input, 0, FileLen);


                                FileCreationInformation newFile = new FileCreationInformation();

                                newFile.Content = input;
                                newFile.Url = filename;
                                List docs = webSite.Lists.GetByTitle("TempDoc");
                                ctx.Load(docs.RootFolder);
                                ctx.Load(docs.RootFolder.Folders);
                                Microsoft.SharePoint.Client.File uploadFile1 = docs.RootFolder.Folders[0].Files.Add(newFile);
                                ctx.ExecuteQuery(); }

如何解决以下错误:

[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

我的keras版本是:

---------------------------------------------------------------------------
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'

我的DeepPoseKit版本是:

[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

1 个答案:

答案 0 :(得分:1)

那是因为您使用的是tensorflow的旧版本。

pip install tensorflow==1.14 

这将卸载以前的版本并安装1.14。

这对我有用:)