[重要]
课程主页
https://classroom.udacity.com/courses/ud730/lessons/224c71d3-9dc3-4cb5-abca-f8d12fce5cfa/concepts/b69b7b74-d76e-4749-a7fc-35be6551480f
课程作业代码在github_tensorflow可以找到,https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/udacity
课程最后一节作一个多数字串识别的项目,其中提到 non-mnist的数据库,人工合成,提供下载
http://yaroslavvb.blogspot.com/2011/09/notmnist-dataset.html
其他:
google的机器学习课程笔记
https://github.com/ahangchen/GoogleML/blob/master/note/lesson-7-tflearn-mnist.md
https://github.com/ahangchen/GDLnotes
1.比较基本的入门级资料,从例子讲起,好理解
learningtensorflow.com/index.html
Lesson 2,有两个问题:
model = tf.initialize_all_variables() // initialize_all_variables 的作用是什么,构图之前必须有这步操作吗
y = tf.Variable(x + 5, name='y') // 只要是变量,是否必须这么声明一下?
如何在tensorBorad中显示图?下面的代码要运行看看才是
import tensorflow as tf
x = tf.constant(35, name='x')
print(x)
y = tf.Variable(x + 5, name='y')
with tf.Session() as session:
merged = tf.merge_all_summaries() // ???
writer = tf.train.SummaryWriter("/tmp/basic", session.graph_def) // ???
model = tf.initialize_all_variables()
session.run(model)
print(session.run(y))
Lesson 3
x = tf.reverse_sequence(x, np.ones((height,)) * width, 1, batch_dim=0) // 这个函数的意义,没有搞清楚?
TensorFlow 常见函数说明
slice = tf.slice(image, [1000, 0, 0], [3000, -1, -1]) // 见http://learningtensorflow.com/lesson4/
[tip]python查看某个变量的类型,可以用 type(x) 或者 help(x)y = x * 2 // 什么情况下 y已经可以直接作为tensorflow的变量使用了?
见http://learningtensorflow.com/lesson4/
Lesson 7
$ export PATH="$PATH:$HOME/bin"
import tensorflow as tf
import numpy as np
# x and y are placeholders for our training data
x = tf.placeholder("float")
y = tf.placeholder("float")
# w is the variable storing our values. It is initialised with starting "guesses"
# w[0] is the "a" in our equation, w[1] is the "b"
w = tf.Variable([1.0, 2.0], name="w")
# Our model of y = a*x + b
y_model = tf.mul(x, w[0]) + w[1]
# Our error is defined as the square of the differences
error = tf.square(y - y_model)
# The Gradient Descent Optimizer does the heavy lifting
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(error)
# Normal TensorFlow - initialize values, create a session and run the model
model = tf.initialize_all_variables()
with tf.Session() as session:
session.run(model)
for i in range(1000):
x_value = np.random.rand()
y_value = x_value * 2 + 6
session.run(train_op, feed_dict={x: x_value, y: y_value}) // train_op 与 x y之间并没有在之前的构图环节体现出来,run的时候又是怎么体现呐?
w_value = session.run(w)
print("Predicted model: {a:.3f}x + {b:.3f}".format(a=w_value[0], b=w_value[1]))
【重要】画误差函数曲线
import matplotlib.pyplot as plt
plt.plot([np.mean(errors[i-50:i]) for i in range(len(errors))])
plt.show()
plt.savefig("errors.png")
Lesson 10
如何将某些操作设定为由GPU执行?可参考 http://learningtensorflow.com/lesson10/
【常见函数】
tensorflow 的入口函数,tf.app.run() // run() -> main, 定义主main() 函数时main函数需要一个传入参数,main(argv=None)
tf.truncated_normal() // 截断正太分布,可用这个函数生成随机数,初始化权值,可参看tensorflow自带例子中的 convolutional.py
tf.nn.conv2d()理解
调用顺序 --> op_def_library.py --> nn_ops.py --> gen_nn_ops.py -- > _op_def_library.py
gen_nn_ops.py 这个文件是自动编译生成的。这个不解???
生成器的源码位于 tensorflow/tensorflow/python/framework/python_op_gen.h 和 python_op_gen.cc 参考http://blog.csdn.net/kkk584520/article/details/51612370 中提到的
Tensorflow 数据类型变换
从tensorflow格式转成 numpy格式
v1 = tf.constant([1, 2, 3, 4, 5, 6, 7])
with tf.Session() as sess:
v2 = sess.run(v1)
result:array([1, 2, 3, 4, 5, 6, 7], dtype=int32)
Convert from [depth,height,width] to [height,width,depth]
tf.transpose(deth_major,[1,2,0])