Article Directory
1, based on Tensorflow of NN
Data are expressed as tensors calculated structures with FIG neural network calculation is performed using the session FIG optimize weight line weight (parameter), to give the model.
2, tensor (tensor)
Zhang is a multidimensional array (list), 0-order tensor can be expressed to the n-order array (list). Represents a dimension of the order tensor, 0 order tensor quantity is a scalar, represents a single number.
dimension | Rank | first name | example |
---|---|---|---|
0-D | 0 | Scalar scalar | s = 123 |
1-D | 1 | Vector vector | v = [1,2,3] |
2-D | 2 | Matrix matrix | m = [[1,2,3],[,4,5,6],[7,8,9]] |
n-D | n | Tensor tensor | t = [[[… |
3, modify the vim
[root@instance-mtfsf05r ~]# vim ~/.vimrc
Written .vimrc file:
set ts = 4
ser nm
ts = 4 denotes a tab key indentation in vim indented four spaces
nm line numbers in vim
4, the addition of two tensors
# coding:utf-8
# 实现两个张量的加法
import tensorflow as tf # 导入tensorflow模块,简写为tf
a = tf.constant([1.0, 2.0]) # 定义张量a,constant方法用来定义常数
b = tf.constant([3.0, 4.0]) # 定义张量b
rs = a + b
print(rs)
Console Printing: Tensor ( "add: 0", shape = (2,), dtype = float32)
add:0: Indicates the name of tensor
add:node
0: 0 output
shape=(2,): Dimension Information
shape: Dimensions
(2,): One-dimensional array of length 2
dtype=float32: Indicates the data type
dtype:type of data
float32: Floating-point data
5, FIG calculated (Graph)
Console Printing: Tensor ( "add: 0", shape = (2,), dtype = float32), the result is displayed only tensor, but no specific values tensor calculation. FIG calculated: build neural network calculation, only the structures, not calculated.
Neurons basic model:
Y = XW = W1 * X1 + X2 * w2 of
description this tensor calculation neurons:
# coding:utf-8
# 实现两个张量的加法
import tensorflow as tf # 导入tensorflow模块,简写为tf
x = tf.constant([[1.0, 2.0]]) # 定义张量a,constant方法用来定义常数
w = tf.constant([[3.0], [4.0]]) # 定义张量b
y = tf.matmul(x, w)
print(y)
Print Console: Tensor ( "MatMul: 0" , shape = (1, 1), dtype = float32)
The result is a two-dimensional tensor of a row.
6, session (Session)
Session node to perform arithmetic calculation in FIG.
Session calculation result obtained using:
# coding:utf-8
# 实现两个张量的加法
import tensorflow as tf # 导入tensorflow模块,简写为tf
x = tf.constant([[1.0, 2.0]]) # 定义张量a,constant方法用来定义常数
w = tf.constant([[3.0], [4.0]]) # 定义张量b
y = tf.matmul(x, w)
# print(y)
# 使用Session得到运算结果
with tf.Session() as sess:
print(sess.run(y)) # [[11.]]
Console Printing: [[11]]
i.e.: 1.0 3.0 2.0 + 4.0 = 11.0