卷積神經網絡

2D Convolution

35-卷積神經網絡-2d卷積.jpg

Kernel size

35-卷積神經網絡-卷積靜態.jpg

  • 矩陣卷積

35-卷積神經網絡-卷積動態圖.gif

Padding & Stride

35-卷積神經網絡-卷積padding.gif

  • 步長2

35-卷積神經網絡-卷積步長2.jpg

Channels

35-卷積神經網絡-通道.jpg

For instance

  • x: [b,28,28,3]
  • one k: [3,3,3]
  • multi-k: [16,3,3,3]
  • stride: 1
  • padding: [1,1,1,1]
  • bias: [16]
  • out: [b,28,28,16]

35-卷積神經網絡-卷積張量動態.gif

LeNet-5

35-卷積神經網絡-最先的神經網絡.jpg

Pyramid Architecture

  • 從底層的邊緣顏色到高層抽象的概念(輪子、車窗)

35-卷積神經網絡-金字塔結構.jpg

layers.Conv2D

import tensorflow as tf
from tensorflow.keras import layers
x = tf.random.normal([1, 32, 32, 3])
# padding='valid':輸入和輸出維度不一樣
layer = layers.Conv2D(4, kernel_size=5, strides=1, padding='valid')
out = layer(x)
out.shape
TensorShape([1, 28, 28, 4])
# padding='same':輸入和輸出維度相同
layer = layers.Conv2D(4, kernel_size=5, strides=1, padding='same')
out = layer(x)
out.shape
TensorShape([1, 32, 32, 4])
layer = layers.Conv2D(4, kernel_size=5, strides=2, padding='same')
out = layer(x)
out.shape
TensorShape([1, 16, 16, 4])
layer.call(x).shape
TensorShape([1, 16, 16, 4])

weight & bias

layer = layers.Conv2D(4, kernel_size=5, strides=2, padding='same')
out = layer(x)
out.shape
TensorShape([1, 16, 16, 4])
# 5,5--》size,3--》通道數,4--》核數量
layer.kernel.shape
TensorShape([5, 5, 3, 4])
layer.bias
<tf.Variable 'conv2d_11/bias:0' shape=(4,) dtype=float32, numpy=array([0., 0., 0., 0.], dtype=float32)>

nn.conv2d

w = tf.random.normal([5, 5, 3, 4])
b = tf.zeros([4])
x.shape
TensorShape([1, 32, 32, 3])
out = tf.nn.conv2d(x, w, strides=1, padding='VALID')
out.shape
TensorShape([1, 28, 28, 4])
out = out + b
out.shape
TensorShape([1, 28, 28, 4])
out = tf.nn.conv2d(x, w, strides=2, padding='VALID')
out.shape
TensorShape([1, 14, 14, 4])

Gradient?

\[ \frac{\partial{Loss}}{\partial{w}} \]網絡

35-卷積神經網絡-梯度.jpg

For instance

35-卷積神經網絡-梯度實例.jpg

相關文章
相關標籤/搜索