为什么我无法导入 Tensorflow.contrib 我收到了 No module named 'tensorflow.python.saved 的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/55082483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:32:57  来源:igfitidea点击:

Why I cannot import Tensorflow.contrib I get an error of No module named 'tensorflow.python.saved

pythontensorflow

提问by Daromogo

Hi I just installed Tensorflowon my Mac and I want to use tf.contrib.slimbut when I use it I get this

嗨,我刚刚安装Tensorflow在我的 Mac 上,我想使用,tf.contrib.slim但是当我使用它时,我得到了这个

import tensorflow as tf

slim = tf.contrib.slim

Error:

错误:

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/export/export_lib.py", line 25, in from tensorflow.python.saved_model.model_utils import build_all_signature_defs ModuleNotFoundError: No module named 'tensorflow.python.saved_model.model_utils'

文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_estimator/python/estimator/export/export_lib.py”,第25行,来自tensorflow.python.saved_model.model_utils导入 build_all_signature_defs ModuleNotFoundError:没有名为“tensorflow.python.saved_model.model_utils”的模块

I don't know what to do, please help me

我不知道该怎么办,请帮帮我

I use Tensorflow.13.1and python 3.7

我使用Tensorflow.13.1python 3.7

回答by Yehdhih ANNA

For anyone who is trying some old codes from githubwith Tensorflow 1.x.xversions while having Tensorflow 2.0.xplease note that tf.contribno longer exist in Tensorflow 2.0.xand it's modules were moved.
Please google the name of the module without the tf.contribpart to know it's new location and thus migrating your code accordingly by correcting the importstatement.

对于那些在github 中尝试一些带有Tensorflow 1.x.x版本的旧代码的人,Tensorflow 2.0.x请注意tf.contrib不再存在Tensorflow 2.0.x并且它的模块被移动了。
请在没有tf.contrib部分的情况下用谷歌搜索模块的名称以了解它的新位置,从而通过更正import语句相应地迁移您的代码。

Hope this helped!

希望这有帮助!

回答by PemaGrg

first unistall tensorflow

首先卸载 tensorflow

pip uninstall tensorflow

then install 1.13.2 version

然后安装 1.13.2 版本

pip install tensorflow==1.13.2

it works.. had the same issue.. but installing tensorflow 1.13.2 solved it!
the newer version of tensorflow doesn't have

它有效..有同样的问题..但安装tensorflow 1.13.2解决了它!
较新版本的 tensorflow 没有

回答by Jasper Chih

I solved this by below method.

我通过以下方法解决了这个问题。

  pip uninstall tensorflow_estimator
  pip install tensorflow_estimator

the reference is : https://github.com/tensorflow/tensorflow/issues/27079

参考是:https: //github.com/tensorflow/tensorflow/issues/27079

回答by Ganesh Krishnan

Currently the default install of tensorflow is 2.x while your code is for 1.x. The contrib module has been removed from tf 2.x. Check the warnings:

目前 tensorflow 的默认安装是 2.x,而你的代码是 1.x。contrib 模块已从 tf 2.x 中删除。检查警告:

"The TensorFlow contrib module will not be included in TensorFlow 2.0"

“TensorFlow contrib 模块将不会包含在 TensorFlow 2.0 中”

Uninstall tensorflow and then install the 1.x version with

卸载 tensorflow 然后安装 1.x 版本

pip install tensorflow==1.15

回答by Rich Rajah

for running it on python3 I used pip3 to install

为了在 python3 上运行它,我使用 pip3 来安装

pip3 install tensorflow

This worked for me

这对我有用

回答by zcseho

In tensorflow 13.1 there's no contrib. Use without it. slim = tf.slim

在 tensorflow 13.1 中没有贡献。不用它就可以使用。苗条 = tf.slim