機器不學習 www.jqbxx.com : 深度聚合機器學習、深度學習算法及技術實戰
deep dive into images and convolutional models
Convnet
BackGround
人眼在識別圖像時,往往從局部到全局局部與局部之間聯繫往往不太緊密我們不需要神經網絡中的每個結點都掌握全局的知識,因此可以從這裡減少需要學習的參數數量Weight share
但這樣參數其實還是挺多的,所以有了另一種方法:權值共享Share Parameters across space
取圖片的一小塊,在上面做神經網絡分析,會得到一些預測將切片做好的神經網絡作用於圖片的每個區域,得到一系列輸出可以增加切片個數提取更多特徵在這個過程中,梯度的計算跟之前是一樣的Concept
Deep Convnet
在Convnet上套Convnet,就可以一層一層綜合局部得到的信息
OutPut
將一個deep and narrow的feature層作為輸入,傳給一個Regular神經網絡
Optimization
將不同Stride的卷積用某種方式合併起來,節省卷積層的空間複雜度。
Max Pooling在一個卷積層的輸出層上取一個切片,取其中最大值代表這個切片優點不增加需要調整的參數通常比其他方法準確缺點:更多Hyper Parameter,包括要取最值的切片大小,以及去切片的步長LENET-5, ALEXNET
Average Pooling在卷積層輸出中,取切片,取平均值代表這個切片1x1 Convolutions
在一個卷積層的輸出層上,加一個1x1的卷積層,這樣就形成了一個小型的神經網絡。
cheap for deeper model結合Average Pooling食用效果更加Inception對同一個卷積層輸出,執行各種二次計算,將各種結果堆疊到新輸出的depth方向上TensorFlow卷積神經網絡實踐
數據處理
dataset處理成四維的,label仍然作為one-hot encodingdef reformat(dataset, labels, image_size, num_labels, num_channels):
dataset = dataset.reshape(
(-1, image_size, image_size, num_channels)).astype(np.float32)
labels = (np.arange(num_labels) == labels[:, None]).astype(np.float32)
return dataset, labels
將lesson2的dnn轉為cnn很簡單,只要把WX+b改為conv2d(X)+b即可關鍵在於conv2d`conv2d
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)
給定四維的input和filter tensor,計算一個二維卷積
Args:
input: A Tensor. type必須是以下幾種類型之一: half, float32, float64.filter: A Tensor. type和input必須相同strides: A list of ints.一維,長度4, 在input上切片採樣時,每個方向上的滑窗步長,必須和format指定的維度同階paddingReturns:
A Tensor. type與input相同
Given an input tensor of shape [batch, in_height, in_width, in_channels]
and a filter / kernel tensor of shape
[filter_height, filter_width, in_channels, out_channels]
conv2d實際上執行了以下操作:
將filter轉為二維矩陣,shape為[filter_height * filter_width * in_channels, output_channels].從input tensor中提取image patches,每個patch是一個virtual tensor,shape[batch, out_height, out_width, filter_height * filter_width * in_channels].將每個filter矩陣和image patch向量相乘具體來講,當data_format為NHWC時:
output[b, i, j, k] =
sum_{di, dj, q} input[b, strides[1] * i + di, strides[2] * j + dj, q] *
filter[di, dj, q, k]
input 中的每個patch都作用於filter,每個patch都能獲得其他patch對filter的訓練
需要滿足strides[0] = strides[3] = 1. 大多數水平步長和垂直步長相同的情況下:strides = [1, stride, stride, 1].
- - -
Max Pooling
在tf.nn.conv2d後面接tf.nn.max_pool,將卷積層輸出減小,從而減少要調整的參數
max_pool
tf.nn.max_pool(value, ksize, strides, padding, data_format='NHWC', name=None)
Performs the max pooling on the input.
Args:
value: A 4-D Tensor with shape [batch, height, width, channels] andtype tf.float32.ksize: A list of ints that has length >= 4. 要執行取最值的切片在各個維度上的尺寸strides: A list of ints that has length >= 4. 取切片的步長padding: A string, either 'VALID' or 'SAME'. padding算法data_format: A string. 'NHWC' and 'NCHW' are supported.name: 操作名,可選Returns:
A Tensor with type tf.float32. The max pooled output tensor.
優化
仿照lesson2,添加learning rate decay 和 drop out,可以將準確率提高到90.6%
參考鏈接
Tensorflow 中 conv2d 都幹了啥TensorFlow Example張雨石 Conv神經網絡Bill Xia 卷積神經網絡(CNN)轉自:https://www.cnblogs.com/hellocwh/p/5564568.html