《深度學習》,又名“花書”。該書由三位大佬 Ian Goodfellow、Yoshua Bengio 和 Aaron Courville 撰寫,是深度學習領域奠基性的經典教材,被譽為深度學習的“聖經”。
原書內容非常充實,接近 800 頁。這本書內容很深很全面,但起點稍微高了一些,對數學理論基礎知識要求的比較多。因此,讀完之後,及時進行高度概括和經驗總結是十分有幫助的。石頭君最近在 GitHub 上發現一個關於花書各章摘要的專案,內容非常精煉,除了筆記的同時,部分章節還配備程式碼,值得推薦,我們一起來看一下。
該專案的名稱是:Deep-Learning-Book-Chapter-Summaries,作者是 Aman Dalmia 和 Ameya Godbole 兩位小哥。專案地址為:
https://github.com/dalmia/Deep-Learning-Book-Chapter-Summaries
主要內容
這份花書核心筆記主要涉及的章節包括:
- ch02 線性代數
-
ch03 概率與資訊理論
-
ch04 數值優化
-
ch07 深度學習正則化
-
ch08 深度模型中的優化
-
ch09 卷積網路
-
ch11 實踐方法論
-
ch13 線性因子模型
筆記的形式是 .ipynb,便於在 Jupyter Notebook 上開啟和觀看。例如,我們來看一下第二章線性代數的筆記。
可見,Jupyter 筆記不僅包含了知識點的總結,也有相關程式碼。再來看第九章的卷積網路部分,配備了一些完整的圖片處理程式碼。
import numpy as np
from scipy import signal
from scipy import misc
import matplotlib.pyplot as plt
# %matplotlib inline
img = misc.ascent()
kernel = np.random.randn(5,5)
# kernel = np.array([[0,-10,0,10,0],[-10,-30,0,30,10],[0,-10,0,10,0]])
img = img.astype(np.float32)/255
orig_in = img
offsetx = offsety = 20
shift_in = np.zeros(orig_in.shape)
shift_in[offsetx:,offsety:] = img[:-offsetx,:-offsety]
rot_in = misc.imrotate(img, 90)
scale_in = misc.imresize(orig_in, 1.5)
output1 = signal.convolve2d(orig_in, kernel, mode='same')
output2 = signal.convolve2d(shift_in, kernel, mode='same')
output3 = signal.convolve2d(rot_in, kernel, mode='same')
output4 = signal.convolve2d(scale_in, kernel, mode='same')
fig, axes = plt.subplots(2, 4, figsize=(14, 7))
ax_orig = axes[0,0]
ax_shift = axes[0,1]
ax_rot = axes[0,2]
ax_scale = axes[0,3]
diff_orig = axes[1,0]
diff_shift = axes[1,1]
diff_rot = axes[1,2]
diff_scale = axes[1,3]
ax_orig.imshow(output1, cmap='gray')
ax_orig.set_title('Original')
ax_shift.imshow(output2, cmap='gray')
ax_shift.set_title('Shifted')
ax_rot.imshow(output3, cmap='gray')
ax_rot.set_title('Rotated')
ax_scale.imshow(output4, cmap='gray')
ax_scale.set_title('Scaled')
def shift(arr, offset):
output = np.zeros(arr.shape)
output[offset:, offset:] = arr[:-offset,:-offset]
return output
def rotate(arr, angle):
return misc.imrotate(arr, angle)
def resize(arr, scale):
return misc.imresize(arr, scale)
diff_orig.hist(np.ravel(output1),bins=100)
diff_orig.set_title('Output histogram')
diff_shift.hist(np.ravel(np.abs(output2-shift(output1, 20))),bins=100)
diff_shift.set_title('Shift histogram difference')
diff_rot.hist(np.ravel(np.abs(output3-rotate(output1, 10))),bins=100)
diff_rot.set_title('Rotate histogram difference')
diff_scale.hist(np.ravel(np.abs(output4-resize(output1, 1.5))),bins=100)
diff_scale.set_title('Scale histogram difference')
ax_orig.set_xticks([])
ax_shift.set_xticks([])
ax_rot.set_xticks([])
ax_scale.set_xticks([])
ax_orig.set_yticks([])
ax_shift.set_yticks([])
ax_rot.set_yticks([])
ax_scale.set_yticks([])
plt.tight_layout()
# plt.show()
plt.savefig('images/conv_equivariance.png')
對於池化層的程式碼示例:
import numpy as np
np.random.seed(101)
from scipy import signal
from scipy import misc
import matplotlib.pyplot as plt
%matplotlib inline
img = misc.ascent()
img = img.astype(np.float32)/255
# The image is more interesting here
orig_in = img[-200:,-300:-100]
offsetx = offsety = 15
shift_in = img[-200-offsetx:-offsetx,-300-offsety:-100-offsety]
kernel1 = np.random.randn(5,5)
kernel2 = np.random.randn(5,5)
kernel3 = np.random.randn(5,5)
def sigmoid(arr):
# Lazy implementation of sigmoid activation
return 1./(1 + np.exp(-arr))
def maxpool(arr, poolsize, stride):
# Lazy looping implementation of maxpool
output_shape = np.floor((np.array(arr.shape)-poolsize)/stride)+1
output_shape = output_shape.astype(np.int32)
output = np.zeros(output_shape)
for x in range(output_shape[0]):
for y in range(output_shape[1]):
output[x,y] = np.max(arr[x*stride:x*stride+poolsize,y*stride:y*stride+poolsize])
return output
output1_1 = signal.convolve2d(orig_in, kernel1, mode='valid')
pool1_1 = maxpool(output1_1, 2, 2)
actv1_1 = sigmoid(pool1_1)
output1_2 = signal.convolve2d(actv1_1, kernel2, mode='valid')
pool1_2 = maxpool(output1_2, 2, 2)
actv1_2 = sigmoid(pool1_2)
output1_3 = signal.convolve2d(actv1_2, kernel3, mode='valid')
pool1_3 = maxpool(output1_3, 2, 2)
output2_1 = signal.convolve2d(shift_in, kernel1, mode='valid')
pool2_1 = maxpool(output2_1, 2, 2)
actv2_1 = sigmoid(pool2_1)
output2_2 = signal.convolve2d(actv2_1, kernel2, mode='valid')
pool2_2 = maxpool(output2_2, 2, 2)
actv2_2 = sigmoid(pool2_2)
output2_3 = signal.convolve2d(actv2_2, kernel3, mode='valid')
pool2_3 = maxpool(output2_3, 2, 2)
fig, axes = plt.subplots(4, 3, figsize=(10, 10))
k1, k2, k3 = axes[0,:]
p1_1, p1_2, p1_3 = axes[1,:]
p2_1, p2_2, p2_3 = axes[2,:]
h1, h2, h3 = axes[3,:]
k1.imshow(kernel1, cmap='gray')
k1.set_title('kernel1')
k2.imshow(kernel2, cmap='gray')
k2.set_title('kernel2')
k3.imshow(kernel3, cmap='gray')
k3.set_title('kernel3')
k1.set_xticks([])
k2.set_xticks([])
k3.set_xticks([])
k1.set_yticks([])
k2.set_yticks([])
k3.set_yticks([])
p1_1.imshow(pool1_1, cmap='gray')
p1_1.set_title('pool1_1')
p1_2.imshow(pool1_2, cmap='gray')
p1_2.set_title('pool1_2')
p1_3.imshow(pool1_3, cmap='gray')
p1_3.set_title('pool1_3')
p1_1.set_xticks([])
p1_2.set_xticks([])
p1_3.set_xticks([])
p1_1.set_yticks([])
p1_2.set_yticks([])
p1_3.set_yticks([])
p2_1.imshow(pool2_1, cmap='gray')
p2_1.set_title('pool2_1')
p2_2.imshow(pool2_2, cmap='gray')
p2_2.set_title('pool2_2')
p2_3.imshow(pool2_3, cmap='gray')
p2_3.set_title('pool2_3')
p2_1.set_xticks([])
p2_2.set_xticks([])
p2_3.set_xticks([])
p2_1.set_yticks([])
p2_2.set_yticks([])
p2_3.set_yticks([])
h1.hist(np.ravel(np.abs(pool1_1-pool2_1)),bins=100)
h1.set_title('Pool 1 diff')
h2.hist(np.ravel(np.abs(pool1_2-pool2_2)),bins=100)
h2.set_title('Pool 2 diff')
h3.hist(np.ravel(np.abs(pool1_3-pool2_3)),bins=100)
h3.set_title('Pool 3 diff')
plt.tight_layout()
# plt.show()
plt.savefig('images/pool_invariance.png')
部落格筆記
該專案的作者還在自己的個人網站上釋出了花書的精煉筆記,地址為:
https://medium.com/inveterate-learner/tagged/deep-learning
附加資源
除了這份花書重點章節摘要之外,石頭君還推薦一份來自 Microsoft 計算機軟體工程師 Jeff Macaluso 總結的關於花書的經驗法則!
線上版閱讀地址:
https://jeffmacaluso.github.io/post/DeepLearningRulesOfThumb/
離線地址:
連結:https://pan.baidu.com/s/1eLlJy3xB6Hs0w_Q7bO536g
提取碼:7q1d
希望這份資源對你有所幫助~
更多 AI 乾貨,請關注公眾號:AI有道!