Caffe學習筆記(三)——Matlab介面
阿新 • • 發佈:2019-01-09
本文主要介紹:Windows下Caffe框架的Matlab介面,即Matlab如何呼叫Caffe框架中的函式,進行分類、提取特徵以及訓練。
1 官網說明
2 相關說明
2.1 影象預處理
classification.m中,在影象輸入CNN網路之前,經過了一個預處理過程:- RGB影象轉成BGR;
- BGR每個通道進行轉置,即 M*N 變成 N*M;
- 調整影象大小,轉化為IMAGE_DIM*IMAGE_DIM*3,IMAGE_DIM預設為256;
- 減去訓練影象均值;
- 資料擴充套件,即對影象裁剪和翻折處理,使一張影象擴充套件成10張影象,裁剪後圖像大小為CROPPED_DIM*CROPPED_DIM*3,CROPPED_DIM預設為227,擴充套件方法為:分別取影象左上、右上、左下、右下、中心,如下圖,共得到5張影象,然後每張影象上下翻折,又得到5張,最後共擴充套件得到10張影象;
- 10張影象放在一起構成輸入資料,維度為:CROPPED_DIM * CROPPED_DIM * 3 * 10
預處理過程圖:
擴充影象:
2.2 CNN輸入資料維度
(1)CNN網路輸入資料的預設維度為[227 227 3 10],即classification.m中影象預處理結果,輸入資料必須為4維,即 [影象高度 影象寬度 通道數 影象個數](注:[影象高度 = 影象寬度),其中預處理把一張影象擴充套件為10張,每張影象都會得到一個分類結果,即每張影象屬於每類的概率(共1000類),然後把10張圖屬於每類的概率求和,最後把影象劃分為概率最大的那一類。 (2)網路輸入資料的維度是可以調整的,通過以下程式設定:-
net.blobs(
- net.reshape();
2.3 簡單應用
比較簡單的應用是,可以直接利用以訓練好的權值,對影象分類和提取特徵:分類得到的不是目標的類別名稱,而是一個類別號,具體類別可以查表得到,下面為類別號對應目標名稱;提取特徵,可以獲取各層特徵具體函式見- tench, Tinca tinca
- goldfish, Carassius auratus
- great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias
- tiger shark, Galeocerdo cuvieri
- hammerhead, hammerhead shark
- electric ray, crampfish, numbfish, torpedo
- stingray
- cock
- hen
- ostrich, Struthio camelus
- brambling, Fringilla montifringilla
- goldfinch, Carduelis carduelis
- house finch, linnet, Carpodacus mexicanus
- junco, snowbird
- indigo bunting, indigo finch, indigo bird, Passerina cyanea
- robin, American robin, Turdus migratorius
- bulbul
- jay
- magpie
- chickadee
- water ouzel, dipper
- kite
- bald eagle, American eagle, Haliaeetus leucocephalus
- vulture
- great grey owl, great gray owl, Strix nebulosa
- European fire salamander, Salamandra salamandra
- common newt, Triturus vulgaris
- eft
- spotted salamander, Ambystoma maculatum
- axolotl, mud puppy, Ambystoma mexicanum
- bullfrog, Rana catesbeiana
- tree frog, tree-frog
- tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui
- loggerhead, loggerhead turtle, Caretta caretta
- leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea
- mud turtle
- terrapin
- box turtle, box tortoise
- banded gecko
- common iguana, iguana, Iguana iguana
- American chameleon, anole, Anolis carolinensis
- whiptail, whiptail lizard
- agama
- frilled lizard, Chlamydosaurus kingi
- alligator lizard
- Gila monster, Heloderma suspectum
- green lizard, Lacerta viridis
- African chameleon, Chamaeleo chamaeleon
- Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis
- African crocodile, Nile crocodile, Crocodylus niloticus
- American alligator, Alligator mississipiensis
- triceratops
- thunder snake, worm snake, Carphophis amoenus
- ringneck snake, ring-necked snake, ring snake
- hognose snake, puff adder, sand viper
- green snake, grass snake
- king snake, kingsnake
- garter snake, grass snake
- water snake
- vine snake
- night snake, Hypsiglena torquata
- boa constrictor, Constrictor constrictor
- rock python, rock snake, Python sebae
- Indian cobra, Naja naja
- green mamba
- sea snake
- horned viper, cerastes, sand viper, horned asp, Cerastes cornutus
- diamondback, diamondback rattlesnake, Crotalus adamanteus
- sidewinder, horned rattlesnake, Crotalus cerastes
- trilobite
- harvestman, daddy longlegs, Phalangium opilio
- scorpion
- black and gold garden spider, Argiope aurantia
- barn spider, Araneus cavaticus
- garden spider, Aranea diademata
- black widow, Latrodectus mactans
- tarantula
- wolf spider, hunting spider
- tick
- centipede
- black grouse
- ptarmigan
- ruffed grouse, partridge, Bonasa umbellus
- prairie chicken, prairie grouse, prairie fowl
- peacock
- quail
- partridge
- African grey, African gray, Psittacus erithacus
- macaw
- sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita
- lorikeet
- coucal
- bee eater
- hornbill
- hummingbird
- jacamar
- toucan
- drake
- red-breasted merganser, Mergus serrator
- goose
- black swan, Cygnus atratus
- tusker
- echidna, spiny anteater, anteater
- platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus
- wallaby, brush kangaroo
- koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus
- wombat
- jellyfish
- sea anemone, anemone
- brain coral
- flatworm, platyhelminth
- nematode, nematode worm, roundworm
- conch
- snail
- slug
- sea slug, nudibranch
- chiton, coat-of-mail shell, sea cradle, polyplacophore
- chambered nautilus, pearly nautilus, nautilus
- Dungeness crab, Cancer magister
- rock crab, Cancer irroratus
- fiddler crab
- king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica
- American lobster, Northern lobster, Maine lobster, Homarus americanus
- spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish
- crayfish, crawfish, crawdad, crawdaddy
- hermit crab
- isopod
- white stork, Ciconia ciconia
- black stork, Ciconia nigra
- spoonbill
- flamingo
- little blue heron, Egretta caerulea
- American egret, great white heron, Egretta albus
- bittern
- crane
- limpkin, Aramus pictus
- European gallinule, Porphyrio porphyrio
- American coot, marsh hen, mud hen, water hen, Fulica americana
- bustard
- ruddy turnstone, Arenaria interpres
- red-backed sandpiper, dunlin, Erolia alpina
- redshank, Tringa totanus
- dowitcher
- oystercatcher, oyster catcher
- pelican
- king penguin, Aptenodytes patagonica
- albatross, mollymawk
- grey whale, gray whale, devilfish, Esc