Ubuntu18.04+python3.6+pip3入门tensorflow
最近课程要求学习tensorflow,在中文社区跑了一下入门例程,在这总结一下踩的一些坑
学习过程如下:
根据官方入门手册我进行的是最简单的二进制安装cpu版本
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
然后就是测试例程:
运行 TensorFlow
打开一个 python 终端:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>
这些都十分顺利,一点问题都没有。
接下来就是:
面向机器学习初学者的 MNIST 初级教程
这是整个新手入门最坑的地方。。。
先来看入门手册开篇:
TensorFlow Python API 依赖 Python 2.7 版本.
在 Linux 和 Mac 下最简单的安装方式, 是使用 pip 安装.
这是官方手册原话,我照搬过来的。
按他手册走,接着开始mnist数据集入门:
MNIST数据集的官网是Yann LeCun’s website。在这里,我们提供了一份python源代码用于自动下载和安装这个数据集。你可以下载这份代码,然后用下面的代码导入到你的项目里面,也可以直接复制粘贴到你的代码文件里面。
直接按连接是打不开的,googlesource不能直接访问。
能直接打开的连接如下:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/mnist/input_data.py
源码我也贴在这:
input_data.py
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Functions for downloading and reading MNIST data (deprecated).
This module and all its submodules are deprecated.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import collections
import gzip
import os
import numpy
from six.moves import urllib
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import random_seed
from tensorflow.python.platform import gfile
from tensorflow.python.util.deprecation import deprecated
_Datasets = collections.namedtuple('_Datasets', ['train', 'validation', 'test'])
# CVDF mirror of http://yann.lec