Tensorflow快速入门教程

什么是Tensorflow?

  • Tensorflow是google发布的深度学习开源框架
  • Tensorflow提供了定义张量的函数,而且可以自动的计算导数

TensorFlow VS. Numpy

  • Few people make this comparison, but TensorFlow and
    Numpy are quite similar. (Both are N-d array libraries!)
  • Numpy has Ndarray support, but doesn’t offer methods to
    create tensor functions and automatically compute
    derivatives (+ no GPU support).

Simple Numpy Recap

In [23]: import numpy as np
In [24]: a = np.zeros((2,2)); b = np.ones((2,2))
In [25]: np.sum(b, axis=1)
Out[25]: array([ 2., 2.])
In [26]: a.shape
Out[26]: (2, 2)
In [27]: np.reshape(a, (1,4))
Out[27]: array([[ 0., 0., 0., 0.]])

Repeat in TensorFlow

In [31]: import tensorflow as tf
In [32]: tf.InteractiveSession()    ##More on Session
soon
In [33]: a = tf.zeros((2,2)); b = tf.ones((2,2))
In [34]: tf.reduce_sum(b, reduction_indices=1).eval()
Out[34]: array([ 2., 2.], dtype=float32)
In [35]: a.get_shape()      ##TensorShape behaves
like a python tuple.
Out[35]: TensorShape([Dimension(2), Dimension(2)])
In [36]: tf.reshape(a, (1, 4)).eval()
Out[36]: array([[ 0., 0., 0., 0.]], dtype=float32)

这里写图片描述
这里写图片描述

● tf.InteractiveSession() is just convenient syntactic sugar for keeping a default session open in ipython.
● sess.run(c) is an example of a TensorFlow Fetch. Will say more on this soon

Tensorflow Computation Graph

  • TensorFlow programs are usually structured into a construction phase, that assembles a graph, and an execution phase that uses a session to execute ops in the graph.
  • All computations add nodes to global default graph
Tensorflow Variables

-“When you train a model you use variables to hold and update parameters. Variables are in-memory buffers containing tensors
- All tensors we’ve used previously have been constant tensors, not variables
这里写图片描述
这里写图片描述

Updating Variable State

这里写图片描述

Fetch Variable State

这里写图片描述
这里写图片描述

Inputing Data

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

Variable Scope

这里写图片描述
这里写图片描述
这里写图片描述

Understanding get_variable()

这里写图片描述

这里写图片描述

Tensorflow实战:线性回归

这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

计算流图如下所示:

这里写图片描述
这里写图片描述

Tips: 关于更多的Tensorflow教程请参考Tensorflow中文社区http://www.tensorfly.cn/以及莫烦老师一系列的Tensorflow教程http://list.youku.com/albumlist/show?id=27327189&asce,谢谢大家!
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值