$ bazel build -c opt //tensorflow/tools/pip_package:build_pip_package $ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg # .whl 文件的实际名字与你所使用的平台有关 $ pip install /tmp/tensorflow_pkg/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
从源代码树的根路径执行:
$ cd tensorflow/models/image/mnist $ python convolutional.py Succesfully downloaded train-images-idx3-ubyte.gz 9912422 bytes. Succesfully downloaded train-labels-idx1-ubyte.gz 28881 bytes. Succesfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes. Succesfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes. Extracting data/train-images-idx3-ubyte.gz Extracting data/train-labels-idx1-ubyte.gz Extracting data/t10k-images-idx3-ubyte.gz Extracting data/t10k-labels-idx1-ubyte.gz Initialized! Epoch 0.00 Minibatch loss: 12.054, learning rate: 0.010000 Minibatch error: 90.6% Validation error: 84.6% Epoch 0.12 Minibatch loss: 3.285, learning rate: 0.010000 Minibatch error: 6.2% Validation error: 7.0% ... ...常见问题
如果在尝试运行一个 TensorFlow 程序时出现以下错误:
ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
请确认你正确安装了 GPU 支持
如果出现错误:
... "__add__", "__radd__", ^ SyntaxError: invalid syntax
解决方案: 确认正在使用的 Python 版本为 Python 2.7.
如果出现错误:
import six.moves.copyreg as copyreg ImportError: No module named copyreg解决方案: TensorFlow 使用的 protobuf 依赖
six-1.10.0
. 但是, Apple 的默认 python 环境 已经安装了 six-1.4.1
, 该版本可能很难升级. 这里提供几种方法来解决该问题:
升级全系统的 six
:
sudo easy_install -U six
通过 homebrew 安装一个隔离的 python 副本:
brew install python
virtualenv
内编译或使用 TensorFlow.
如果出现错误:
>>> import tensorflow as tf Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module> from tensorflow.python import * File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module> from tensorflow.core.framework.graph_pb2 import * ... File "/usr/local/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module> serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3') TypeError: __init__() got an unexpected keyword argument 'syntax'这是由于安装了冲突的 protobuf 版本引起的, TensorFlow 需要的是 protobuf 3.0.0. 当前 最好的解决方案是确保没有安装旧版本的 protobuf, 可以使用以下命令重新安装 protobuf 来解决 冲突:
brew reinstall --devel protobuf