引言
為了所有想要應(yīng)用深度學(xué)習(xí)技巧和計(jì)算機(jī)專業(yè)的人士設(shè)計(jì)的課程

深度學(xué)習(xí)的發(fā)展

準(zhǔn)備
GPU 的準(zhǔn)備
下載相應(yīng)的數(shù)據(jù)
Then download dogscats.zip into that directory and unzip.
looking at the Dogs vs. Cats Kaggle competition
數(shù)據(jù)結(jié)構(gòu)概覽
1.切分驗(yàn)證集,訓(xùn)練集以及測試集
2.分別看這幾個(gè)文件夾下面的文件結(jié)構(gòu)是什么樣的

使用CNN
本周的任務(wù)
建一個(gè)模型可以識別狗和貓,達(dá)到80%以上的準(zhǔn)確率
基本配置
Use $ jupyter notebook to open a connection to the notebook GUI at port 8888. Recall the ip address for your instance we recorded earlier. In your browser, go to instanceIP:8888 to access the GUI, and login with password dl_course. Click on lesson1.ipynb.
from __future__ import division,print_function
import os, json
from glob import glob
import numpy as np
np.set_printoptions(precision=4, linewidth=100)
from matplotlib import pyplot as plt
import utils; reload(utils)
from utils import plots
定義文件夾路徑
#path = "data/dogscats/"
path = "data/dogscats/sample/"
注意這里的utils是一個(gè)我們下載好的庫,里面有一些常用的函數(shù),我們可以用. reload(utils) 來更新我們的notebook如果我們對這個(gè)庫有什么更新的話。
用訓(xùn)練好的VGG模型
使用別人訓(xùn)練好的模型,VGG16
理解vgg的建造方法很重要,他的數(shù)據(jù)大部分是單個(gè)物體的,也就是說vgg比較適合于單個(gè)物體的識別,比如貓呀狗呀,看看數(shù)據(jù)你就知道你用的別人的模型有什么好的和壞的地方。
punchline: state of the art custom model in 7 lines of code
現(xiàn)在我們可以開始:
# As large as you can, but no larger than 64 is recommended.
# If you have an older or cheaper GPU, you'll run out of memory, so will have to decrease this.
batch_size=64
# Import our class, and instantiate
from vgg16 import Vgg16# Import our class, and instantiate
from vgg16 import Vgg16
vgg = Vgg16()
# Grab a few images at a time for training and validation.
# NB: They must be in subdirectories named based on their category
batches = vgg.get_batches(path+'train', batch_size=batch_size)
val_batches = vgg.get_batches(path+'valid', batch_size=batch_size*2)
vgg.finetune(batches)
vgg.fit(batches, val_batches, nb_epoch=1)
我們可以用vgg來識別主要的imagenet 的類別(就是原來那個(gè)比賽的數(shù)據(jù)集里面有的類別)但是我們不能直接識別貓和狗因?yàn)樵瓉砟莻€(gè)比賽沒有這個(gè)類別,然而我們可以看看他是怎么識別這些圖像的。首先我們構(gòu)造了一個(gè)vgg的對象;由于vgg是基于keras的,所以他可以直接識別圖片和他的標(biāo)簽,用一個(gè)文件夾目錄的結(jié)構(gòu),不同的類別必須被放在單獨(dú)的文件夾中。
BTW,當(dāng)Keras引用“類”時(shí),并不意味著Python類,而是指標(biāo)簽的類別,例如“pug”或“tabby”。)批次只是一個(gè)常規(guī)的python迭代器。 每次迭代都會返回圖像本身以及標(biāo)簽。
為了理解什么是batch,我們可以先看看一個(gè)batch長什么樣子
