深度学习核心技术笔记(一)

1、TensorFlow中矩阵量的存在形式常用的有三种,或者说相应的python类有三种,具体如下:

2)  tf.Variable()  #是变量,表示神经网络中可变化的量,(可以通过trainable=False设置成不可变),可在运行中赋值,可以通过constant进行初始化,或者以其他方法进行初始化

2)  tf.constant()  #是常量,可以通过numpy中的array或者list,还有给定的shape和数值进行赋值
3)  tf.placeholder()  #placeholder是TensorFlow的占位符节点,由placeholder方法创建,其也是一种常量,但是由用户在调用run方法是传递的,也可以将placeholder理解为一种形参。即其不像constant那样直接可以使用,需要用户传递常数值。
练习

import matplotlib.pyplot as plt
import numpy as np

mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
batch_xs, batch_ys = mnist.train.next_batch(100)

fig = plt.figure()
ax = fig.add_subplot(221)
ax.matshow(np.reshape(batch_xs[1],[28,28]), cmap=plt.get_cmap("Purples"))
ax = fig.add_subplot(222)
ax.matshow(np.reshape(batch_xs[2],[28,28]), cmap=plt.get_cmap("Purples"))
ax = fig.add_subplot(223)
ax.matshow(np.reshape(batch_xs[3],[28,28]), cmap=plt.get_cmap("Purples"))
ax = fig.add_subplot(224)
ax.matshow(np.reshape(batch_xs[4],[28,28]), cmap=plt.get_cmap("Purples"))
plt.show()

原文地址:https://www.cnblogs.com/zhaop8078/p/9556312.html