为什么我不能在 tensorflow 中导入 tfprof_log_pb2?
Why cannot I import tfprof_log_pb2 in tensorflow?
从this line了解到新添加的配置文件工具是导入的,但是感觉很奇怪:1)无法从交互界面导入; 2) 当 运行 在 spyder 中使用 mnist 示例时,我也得到一个错误 sayinng ImportError: cannot import name 'tfprof_log_pb2'
。
我想既然 tensorflow 是安装在 anaconda 中的,那么它可能是一个旧版本,因此里面没有 tfprof。但这只能解释为什么我不能直接在交互界面中运行 from tensorflow.tools.tfprof import tfprof_log_pb2
(不是在anaconda环境中)并且不能解释为什么我在anaconda中运行它会引发错误。它在 spyder 中引发此错误,那么支持 tfprof 的版本应该在那里。
两个答案都对。
在 Ubuntu(python2.7 和 GPU)中,我走捷径,通过以下方式将张量流从 10 更新为 12:
pip install \
-i https://pypi.tuna.tsinghua.edu.cn/simple/ \
https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
在国内我用的是清华大学的镜像安装比较快
直接就好了。
但这似乎不适用于 Mac(至少仅适用于 python3.5 和 cpu),即使您tensorflow的版本是12或以上那个文件还没有生成(甚至其他两个文件已经列在那里了(//anaconda/lib/python3.5/site-packages/tensorflow/tools/tfprof/
)。所以我只是复制了那个文件(它必须与我的[=27中的相同) =],对吗?)由 Yaroslav Bulatov 提供给该文件夹。它有效。
您的磁盘上是否存在 tfprof_log_pb2.py
?它是一个自动生成的文件,不存在于源代码树中。相反,它被放置在 bazel-genfiles
目录中,并且应该在 build_pip_package.sh
期间被复制到分发中
this issue 修复了其他工具的一些缺失文件,我想知道 tfprof 文件是否逃脱了修复(即,如果它不是 tools:all_files
目标的一部分)
顺便说一句,该文件的副本来自我的本地构建 -- http://pastebin.com/dJnnWKuy
如果 python 的 protobuf 比 3.1.0 更旧并且 TF 也更旧,就会出现问题。我有如下确切问题:
$python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
>>> from tensorflow.tools.tfprof import tfprof_log_pb2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tfprof
我是这样解决的:
已将 setuptools 更新到最新的 32.x 或更高版本(我这样做是因为我的 TF 安装未能将 setuptools 更新到版本 32.x):
pip install update --user setuptools
之后我安装了 TF 如下:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
sudo pip install --upgrade $TF_BINARY_URL
您会注意到 TF 12.1 安装了以下内容:
Collecting tensorflow==0.12.1 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow==0.12.1)
Collecting protobuf>=3.1.0 (from tensorflow==0.12.1)
Collecting setuptools (from protobuf>=3.1.0->tensorflow==0.12.1)
成功安装 TF 后:
Successfully installed protobuf-3.1.0.post1 tensorflow-0.12.1
我尝试了下面的第一个命令:
$python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
>>> from tensorflow.tools.tfprof import tfprof_log_pb2
>>> tfprof_log_pb2
<module 'tensorflow.tools.tfprof.tfprof_log_pb2' from '/Library/Python/2.7/site-packages/tensorflow/tools/tfprof/tfprof_log_pb2.pyc'>
从this line了解到新添加的配置文件工具是导入的,但是感觉很奇怪:1)无法从交互界面导入; 2) 当 运行 在 spyder 中使用 mnist 示例时,我也得到一个错误 sayinng ImportError: cannot import name 'tfprof_log_pb2'
。
我想既然 tensorflow 是安装在 anaconda 中的,那么它可能是一个旧版本,因此里面没有 tfprof。但这只能解释为什么我不能直接在交互界面中运行 from tensorflow.tools.tfprof import tfprof_log_pb2
(不是在anaconda环境中)并且不能解释为什么我在anaconda中运行它会引发错误。它在 spyder 中引发此错误,那么支持 tfprof 的版本应该在那里。
两个答案都对。
在 Ubuntu(python2.7 和 GPU)中,我走捷径,通过以下方式将张量流从 10 更新为 12:
pip install \
-i https://pypi.tuna.tsinghua.edu.cn/simple/ \
https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
在国内我用的是清华大学的镜像安装比较快
直接就好了。
但这似乎不适用于 Mac(至少仅适用于 python3.5 和 cpu),即使您tensorflow的版本是12或以上那个文件还没有生成(甚至其他两个文件已经列在那里了(//anaconda/lib/python3.5/site-packages/tensorflow/tools/tfprof/
)。所以我只是复制了那个文件(它必须与我的[=27中的相同) =],对吗?)由 Yaroslav Bulatov 提供给该文件夹。它有效。
您的磁盘上是否存在 tfprof_log_pb2.py
?它是一个自动生成的文件,不存在于源代码树中。相反,它被放置在 bazel-genfiles
目录中,并且应该在 build_pip_package.sh
this issue 修复了其他工具的一些缺失文件,我想知道 tfprof 文件是否逃脱了修复(即,如果它不是 tools:all_files
目标的一部分)
顺便说一句,该文件的副本来自我的本地构建 -- http://pastebin.com/dJnnWKuy
如果 python 的 protobuf 比 3.1.0 更旧并且 TF 也更旧,就会出现问题。我有如下确切问题:
$python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
>>> from tensorflow.tools.tfprof import tfprof_log_pb2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tfprof
我是这样解决的:
已将 setuptools 更新到最新的 32.x 或更高版本(我这样做是因为我的 TF 安装未能将 setuptools 更新到版本 32.x):
pip install update --user setuptools
之后我安装了 TF 如下:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
sudo pip install --upgrade $TF_BINARY_URL
您会注意到 TF 12.1 安装了以下内容:
Collecting tensorflow==0.12.1 from https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow==0.12.1)
Collecting protobuf>=3.1.0 (from tensorflow==0.12.1)
Collecting setuptools (from protobuf>=3.1.0->tensorflow==0.12.1)
成功安装 TF 后:
Successfully installed protobuf-3.1.0.post1 tensorflow-0.12.1
我尝试了下面的第一个命令:
$python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
>>> from tensorflow.tools.tfprof import tfprof_log_pb2
>>> tfprof_log_pb2
<module 'tensorflow.tools.tfprof.tfprof_log_pb2' from '/Library/Python/2.7/site-packages/tensorflow/tools/tfprof/tfprof_log_pb2.pyc'>