引言
為了所有想要應用深度學習技巧和計算機專業(yè)的人士設計的課程
深度學習的發(fā)展
準備
GPU 的準備
下載相應的數(shù)據(jù)
Then download dogscats.zip into that directory and unzip.
looking at the Dogs vs. Cats Kaggle competition
數(shù)據(jù)結構概覽
1.切分驗證集但两,訓練集以及測試集
2.分別看這幾個文件夾下面的文件結構是什么樣的
使用CNN
本周的任務
建一個模型可以識別狗和貓,達到80%以上的準確率
基本配置
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是一個我們下載好的庫,里面有一些常用的函數(shù),我們可以用. reload(utils) 來更新我們的notebook如果我們對這個庫有什么更新的話。
用訓練好的VGG模型
使用別人訓練好的模型刷后,VGG16
理解vgg的建造方法很重要,他的數(shù)據(jù)大部分是單個物體的,也就是說vgg比較適合于單個物體的識別憾儒,比如貓呀狗呀,看看數(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 的類別(就是原來那個比賽的數(shù)據(jù)集里面有的類別)但是我們不能直接識別貓和狗因為原來那個比賽沒有這個類別起趾,然而我們可以看看他是怎么識別這些圖像的。首先我們構造了一個vgg的對象警儒;由于vgg是基于keras的训裆,所以他可以直接識別圖片和他的標簽眶根,用一個文件夾目錄的結構,不同的類別必須被放在單獨的文件夾中边琉。
BTW属百,當Keras引用“類”時,并不意味著Python類变姨,而是指標簽的類別族扰,例如“pug”或“tabby”。)批次只是一個常規(guī)的python迭代器定欧。 每次迭代都會返回圖像本身以及標簽渔呵。
為了理解什么是batch,我們可以先看看一個batch長什么樣子