1. 数据类型
1.1. 数据容器
- list
- np.array
- tf.Tensor
1.2. What’s Tensor
- scalar: 1.1
- vector: [1.1],[1.1, 2.2, … ]
- matrix: [[1.1, 2.2],[3.3, 4.4],[5.5, 6.6]]
- tensor: 𝑟𝑎𝑛𝑘 > 2 (在神经网络中, tensor的范围相当广, 这里可以理解为狭义的定义)
1.3. 数据类型(TF is a computing lib)
- int, float, double
- bool
- string
1.3.1. Create
- tf.constant(1)
- <tf.Tensor: id=0, shape=(), dtype=int32, numpy=1>
- tf.constant(1.0)
- <tf.Tensor: id=1, shape=(), dtype=float32, numpy=1.0>
tf.constant(2.2, dtype=tf.int32)
error:TypeError: Cannot convert 2.2 to EagerTensor of dtype int32
- tf.constant(2., dtype=tf.double) (
注意:tf.double 实际上就是tf.float64的别名
)- <tf.Tensor: id=3, shape=(), dtype=float64, numpy=2.0>
- tf.constant([True, False])
- <tf.Tensor: id=4, shape=(2,), dtype=bool, numpy=array([ True, False])>
- tf.constant(“hello world”)
- <tf.Tensor: id=5, shape=(), dtype=string, numpy=b’hello world’>
1.3.2. Tensor Property
1.3.3. Check Tensor Type
import tensorflow as tf
import numpy as np
a = tf.constant([1.])
b = tf.constant([True, False])
c = tf.constant('hello world')
d = np.arange(4)
print(isinstance(a, tf.Tensor)) # 注意: tf.Variable也是tensor,但是此时就不能用isinstance(,tf.Tensor)来判断了
print(tf.is_tensor(b))
print(tf.is_tensor(d)) # 是一个numpy,而非tensor
print(a.dtype, b.dtype, c.dtype)
print(a.dtype == tf.float32)
1.3.4. Convert
1.3.5. bool & int
1.3.6. tf.Variable
1.3.7. To numpy
2. 创建Tensor
2.1. Outline
- from numpy, list
- zeros, ones
- fill
- random
- constant
- Application
2.1.1. From Numpy, List
2.1.2. zeros, ones
-
tf.zeros
- tf.ones类似
- tf.ones类似
-
tf.zeros_like
- tf.ones_like
2.1.3. Fill
2.1.4. Normal 正态分布
- Truncated Distribution 截断分布
- Gradient Vanish 截断消失
- 链接:https://assessingpsyche.wordpress.com/2014/06/04/using-the-truncated-normal-distribution/
- Gradient Vanish 截断消失
2.1.5. Uniform 均匀分布
-
tf.random.uniform([2, 2], minval=0,maxval=1)
-
tf.random.uniform([2,2], minval=0, maxval=100)
-
Random Permutation 随机置换
2.2. Typical Dim Data
2.2.1. Scalar
- []
- 0, 1., 2.2…
- loss = mse(out, y)
- accuracy
2.2.2. Vector
2.2.3. Matrix
###.2.3.4. Dim=3 Tensor (自然语言处理)
2.3.5. Dim=4 Tensor
- Image: [b, h, w, 3]
- feature maps: [b, h, w, c]
2.3.6. Dim=5 Tensor
3. 需要全套课程视频+PPT+代码资源可以私聊我
- 方式1:CSDN私信我!
- 方式2:
QQ邮箱
:594042358@qq.com
或者直接加我QQ:
594042358
!