Ubuntu18.04+python3.6+pip3入门tensorflow

本文记录了在Ubuntu18.04上使用Python3.6和pip3安装TensorFlow的过程及遇到的问题。在安装过程中,官方文档推荐的Python2.7版本引起了一些困扰,但在尝试用Python3.6重新安装后,成功运行了MNIST初级教程的代码,得到了预期结果。对于初学者来说,理解版本兼容性和解决导入包问题至关重要。
摘要由CSDN通过智能技术生成

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值