Python带来的开发速度和C++带来的执行速度。
caffe/caffe2
1建立数据集
2设置参数彩色或黑白
3选择数据地址
小心空格
4为数据集起名字
建立第二个数据集
建立模型
层数选择10
网络模型选择
名字
开始运行
测试图片
输入测试图片,点击classify执行
结果
测试多张图片
回到教程,选择下一步
找到代码,选中按shift+enter
保存
/notebooks/test_images/image-1-1.jpg/notebooks/test_images/image-2-1.jpg/notebooks/test_images/image-3-1.jpg/notebooks/test_images/image-4-1.jpg/notebooks/test_images/image-7-1.jpg/notebooks/test_images/image-8-1.jpg/notebooks/test_images/image-8-2.jpg保存tet文件
上传开始
提高模型,增大数据集
等待运行完
加载有点慢
新建模型
开训练
训练完,使用测试图实验
上传图片路径txt文件测试多张图片
选择新的开始按钮
也可以自己手写,画板大小保存成28*28
打开画板
点击下方
网络模型优化
选中模型克隆
可观看可视化的图
(上图绿色模块为下面添加的层)
67{}最后面加入一层
layer{name:"reluP1"type:"ReLU"bottom:"pool1"top:"pool1"}
改为75
改为100
保存修改后的模型
重新开始识别上传手写字符
目前为止我们所有创建的数据集和模型
AnintroductiontoDeepLearningInthislab,you'lllearntotrainaneuralnetworkusingcleanlabeleddata.We'llintroducedeeplearningthroughthetaskofsupervisedimageclassification,where,givenmanyimagesandtheirlabels,you'llbuildatoolthatcanpredictlabelsofnewimages.
Theintentistobuildtheskillstostartexperimentingwithdeeplearning.You'llexamine:
Attheendofthislab,you'llhaveatrainedneuralnetworkthatcansuccessfullyclassifyimagestosolveaclassicdeeplearningchallenge:
Howcanwedigitizehandwriting
Thefundamentaldifferencebetweenartificialintelligence(AI)andtraditionalprogramingisthatAIlearnswhiletraditionalalgorithmsareprogrammed.Let'sexaminethedifferencethroughanexample:
Imagineyouwereaskedtogivearobotinstructionstomakeasandwichusingtraditionalcomputerprogramming,instructionbyinstruction.Howmightyoustart
Maybesomethinglike:Addtwopiecesofbreadtoanemptyplate.
Runthecodebelowtoseewhattherobotmightdowithyourfirstinstruction.Toruncode,clickonIn[]andpressShift+Enter.
readyPlate=2*bread+emptyPlateYoulikelygota"NameError."Howwouldyouthenworktodefine"bread"toyourrobotNottomentionotheringredientsandhowtocombinethem
Computersonly"see"imagesastheamountofred,blue,andgreenateachpixel.Everythingelsewewantthemtoknow,wewouldhavehadtodescribeintermsofpixels.
Artificialintelligencetakesadifferentapproach.Insteadofprovidinginstructions,weprovideexamples.Above,wecouldshowourrobotthousandsoflabeledimagesofbreadandthousandsoflabeledimagesofotherobjectsandaskourrobottolearnthedifference.Ourrobotcouldthenbuilditsownprogramtoidentifynewgroupsofpixels(images)asbread.
Insteadofinstructions,wenowneeddataandcomputersdesignedtolearn.
Sohowdoweexposeartificialneuralnetworkstodata
Bytheendofthislab,you'llknowhowtoloaddataintoadeepneuralnetworktocreateatrainedmodelthatiscapableofsolvingproblemswithwhatitlearned,notwhataprogrammertoldittodo.
Sinceacomputer"sees"imagesascollectionsofpixelvalues,itcan'tdoanythingwithvisualdataunlessitlearnswhatthosepixelsrepresent.
Whatifwecouldeasilyconverthandwrittendigitstothedigitalnumberstheyrepresent
We'regoingtotrainadeepneuralnetworktorecognizehandwrittendigits0-9.Thischallengeiscalled"imageclassification,"whereournetworkwillbeabletodecidewhichimagebelongstowhichclass,orgroup.
Forexample:Thefollowingimageshouldbelongtotheclass'4':
whereasthisnextimageshouldbelongtotheclass'2':
It'simportanttonotethatthisworkflowiscommontomostimageclassificationtasks,andisagreatentrypointtolearninghowtosolveproblemswithDeepLearning.
Let'sstart.
Let'sstartbybringingourdata,inthiscase,thousandsofimages,intoourlearningenvironment.We'regoingtouseatoolcalledDIGITS,wherewecanvisualizeandmanageourdata.
First,openDIGITSinanewtabusingthefollowinglink.
WhenyoustartDIGITS,youwillbetakentothehomescreenwhereyoucancreatenewdatasetsornewmodels.
BeginbyselectingtheDatasetstabontheleft.
Sincewewantournetworktotelluswhich"class"eachimagebelongsto,weaskDIGITStopreparea"classification"imagedatasetbyselecting"Classification"fromthe"Images"menuontheright.
Atthispointyoumayneedtoenterausername.Ifrequested,justenteranynameinlower-case.
You'llseethatyou'vegotalotofoptionsaroundhowtoloadadataset.Forthisfirstrunthrough,we'regoingtosimplifyandonlyfillouttwofields.
Don'tsee"TrainingImages"Click"DIGITS"onthetopleftandselect"Datasets"beforeselecting"Images"and"Classification."
Notethatwe'vealreadydownloadedthedatasettothecomputerwhereDIGITSisrunning.You'llhaveachancetoexploreitshortlyandwilllearnmethodsforaccessingdataasyouworkthroughourlabs.
Thenpress"Create."
DIGITSisnowcreatingyourdatasetfromthefolder.Insidethefoldertrain_smalltherewere10subfolders,oneforeachclass(0,1,2,3,...,9).Allofthehandwrittentrainingimagesof'0'sareinthe'0'folder,'1'sareinthe'1'folder,etc.
Explorewhatourdatalookslikebyselecting"Explorethedb".
Whilethereisanendlessamountofanalysisthatwecoulddoonthedata,makesureyouatleastnotethefollowing:
Next,we'regoingtouseourdatatotrainanartificialneuralnetwork.Likeitsbiologicalinspiration,thehumanbrain,artificialneuralnetworksarelearningmachines.Alsolikethebrain,these"networks"onlybecomecapableofsolvingproblemswithexperience,inthiscase,interactingwithdata.Throughoutthislab,we'llreferto"networks"asuntrainedartificialneuralnetworksand"models"aswhatnetworksbecomeoncetheyaretrained(throughexposuretodata).
Forimageclassification(andsomeothertasks),DIGITScomespre-loadedwithaward-winningnetworks.Aswetakeondifferentchallengesinsubsequentlabs,we'lllearnmoreaboutselectingnetworksandevenbuildingourown.However,tostart,weighingthemeritsofdifferentnetworkswouldbelikearguingabouttheperformanceofdifferentcarsbeforedrivingforthefirsttime.Buildinganetworkfromscratchwouldbelikebuildingyourowncar.Let'sdrivefirst.We'llgetthere.
GotothetabwhereDIGITSisstillopenandreturntothemainscreenbyclicking"DIGITS"onthetopleftofthescreen.
CreatinganewmodelinDIGITSisalotlikecreatinganewdataset.Fromthehomescreen,the"Models"tabwillbepre-selected.Click"Images"under"NewModel"andselect"Classification",aswe'recreatinganimageclassificationmodeltomatchourimageclassificationdatasetandimageclassificationtask.
Again,forthisfirstroundoftraininglet'skeepitsimple.Thefollowingarethefewestsettingsyoucouldpossiblysettosuccessfullytrainanetwork.
Whenyouhavesetalloftheseoptions,presstheCreatebutton.
Youarenowtrainingyourmodel!Forthisconfiguration,themodeltrainingshouldcompleteinlessthan5minutes.Youcaneitherwatchittrain,continuereading,orgrabacupofcoffee.
Whendone,theJobStatusontherightwillsay"Done",andyourtraininggraphshouldlooksomethinglike:
We'lldigintothisgraphasatoolforimprovement,butthebottomlineisthatafter5minutesoftraining,wehavebuiltamodelthatcanmapimagesofhandwrittendigitstothenumbertheyrepresentwithanaccuracyofabout87%!
Let'stesttheabilityofthemodeltoidentifynewimages.
Nowthatourneuralnetworkhaslearnedsomething,inferenceistheprocessofmakingdecisionsbasedonwhatwaslearned.Thepowerofourtrainedmodelisthatitcannowclassifyunlabeledimages.
We'lluseDIGITStotestourtrainedmodel.Atthebottomofthemodelwindow,youcantestasingleimageoralistofimages.Ontheleft,typeinthepath/data/test_small/2/img_4415.pngintheImagePathtextbox.SelecttheClassifyOnebutton.Afterafewseconds,anewwindowisdisplayedwiththeimageandinformationaboutitsattempttoclassifytheimage.
Itworked!(Tryagainifitdidn't).Youtookanuntrainedneuralnetwork,exposedittothousandsoflabeledimages,anditnowhastheabilitytoaccuratelypredicttheclassofunlabeledimages.Congratulations!
Notethatthatsameworkflowwouldworkwithalmostanyimageclassificationtask.YoucouldtrainAlexNettoclassifyimagesofdogsfromimagesofcats,imagesofyoufromimagesofme,etc.Ifyouhaveextratimeattheendofthislab,theresanotherdatasetwith101differentclassesofimageswhereyoucanexperiment.
Whileyouhavebeensuccessfulwiththisintroductorytask,thereisalotmoretolearn.
Inthenextnotebook,youwillworktodefineandimproveperformance.
第二个教程
Nowthatyou'velearnedtosuccessfullytrainamodel,let'sworktotrainastateoftheartmodel.Inthislab,we'lllearntheleversthatyou,asadeeplearningpractitioner,willusetonavigatetowardsdesiredresults.Intheprocess,we'llstarttopeelbackthelayersaroundthetechnologythatmakesthispossible.
Let'sbringbackourhandwrittendigitclassifier.GotoDIGITS'homescreenbyclickingtheDIGITSlogoonthetopleftofthescreen.Here,you'llsee(atleast)twomodels.Choosethefirstmodelyoucreated,inourcase,"Myfirstmodel."
Amongotherthings,DIGITSwilldisplaythegraphthatwasgeneratedasthemodelwasbeingtrained.
Threequantitiesarereported:trainingloss,validationloss,andaccuracy.Thevaluesoftrainingandvalidationlossshouldhavedecreasedfromepochtoepoch,althoughtheymayjumparoundsome.Theaccuracyisthemeasureoftheabilityofthemodeltocorrectlyclassifythevalidationdata.Ifyouhoveryourmouseoveranyofthedatapoints,youwillseeitsexactvalue.Inthiscase,theaccuracyatthelastepochisabout87%.Yourresultsmightbeslightlydifferentthanwhatisshownhere,sincetheinitialnetworksaregeneratedrandomly.
Analyzingthisgraph,onethingthatjumpsoutisthataccuracyisincreasingovertimeandthatlossisdecreasing.Anaturalquestionmaybe,"willthemodelkeepimprovingifweletittrainlonger"Thisisthefirstinterventionthatwe'llexperimentwithanddiscuss.
Followingtheadviceofparentsandteacherseverywhere,let'sworktoimprovetheaccuracyofourmodelbyaskingittostudymore.
Anepochisonecompletepresentationofthedatatobelearnedtoalearningmachine.Let'smakesenseofwhatishappeningduringanepoch.
Comparethistoahumanstudysessionusingflashcards:
Youcanseethatoneepochcanbecomparedtoonetripthroughadeckofflashcards.
Inthemodelthatwetrained,weaskedournetworkfor5epochs.Thebluecurveonthegraphaboveshowshowfaroffeachpredictionwasfromtheactuallabel.
Likeahumanstudent,thepointofstudyingisn'tjusttobeabletoreplicatesomeoneelse'sknowledge.Thegreencurveshowsthedifferencebetweenthemodel'spredictionsandactuallabelsforNEWdatathatithasn'tlearnedfrom.Theorangecurveissimpletheinverseofthatloss.
Losscanbemeasuredinmanyways,butconceptually,it'ssimplythedifferencebetweenpredictedandactuallabels.
Ifaftertakingatestandearning87%,ahumanstudentwantedtoimproveperformance,theymightbeadvisedtostudymore.Atthispoint,they'dgobacktotheirflashcards.
Adeeplearningpractitionercouldrequestmoreepochs.Itispossibletostartfromscratchandrequestmoreepochswhencreatingyourmodelforthefirsttime.However,ourmodelhasalreadyspentsometimelearning!Let'susewhatithaslearnedtoimproveourmodelinsteadofstartfromscratch.
HeadbacktoDIGITSandscrolltothebottomofyourmodelpageandclickthebiggreenbuttonlabeled:"MakePretrainedModel."
Thiswillsavetwothings:
Wecannowcreateanewmodelfromthisstartingpoint.GobacktoDIGITS'homescreenandcreateanewImageClassficationmodellikebefore.NewModel(Images)->Classification
Yoursettingsshouldlooklike:
Whenyoucreatethemodel,you'llgetthefollowinggraph.
Notethefollowing:
Let'stestournewandimprovedmodelusingthesameimagefrombefore.Atthebottomofourmodelpage,"Testasingleimage."We'lltestthesame"2"tocompareperformance.Asareminder,theimagepathis:/data/test_small/2/img_4415.png
Recallthatouroriginalmodelcorrectlyidentifiedthisasa2aswell,butwithaconfidenceof85%.Thisisclearlyabettermodel.
Feelfreetotryafewmoreimagesbychangingthenumberafter"img_"
Let'strytestingthemodelwithasetofimages.Theyareshownbelow.
Wecanclassifymultiplefilesifweputtheminthelist.Inthelinkbelow,executethecodeblockandalinktothefilean_image.listwillappear.Rightclickonan_image.listandsavethattoafileonyourlocalcomputer(rightclickand"SaveAs").Rememberthedirectoryinwhichitissaved.
fromIPython.displayimportFileLink,FileLinksFileLinks('test_images_list')OntherightsideoftheDIGITSmodelpage,thereisanoptionto"testalistofimages".PressthebuttonBrowseandselectthean_image.listfileyoujustdownloaded.ThenpresstheClassifyManybutton.Afterseveralseconds,youwillseetheresultsfromCaffetryingtoclassifytheseimageswiththegeneratedmodel.Intheimagename,thefirstnumberisthedigitintheimage(ex.image-3-1.jpgisa3).Yourresultsshouldbesimilartothis:
Whatisshownhereistheprobabilitythatthemodelpredictstheclassoftheimage.Theresultsaresortedfromhighestprobabilitytolowest.Ourmodeldidn'tdosowell.
Whiletheaccuracyofthemodelwas87%,itcouldnotcorrectlyclassifyanyoftheimagesthatwetested.Whatcanwedotoimprovetheclassificationoftheseimages
Atthispointit'stimetobeabitmoreintentional.Afterwecansuccessfullytrainamodel,whatcomesnextcomesfromunderstandingandexperimentation.TobuildabetterunderstandingofTHISproject,weshouldstartwithourdata.Tobuildabetterunderstandingofanything,weshouldstartwithprimarysources.
Onekeyobservationwe'lluseisthattheimagesstartas28x28grayscaleimages.Whenweloadedourdataset,westuckwithdefaults,whichwere256x256andcolor.Youmayhavenoticedthattheimageswereabitblurry.Inthenextsectionwe'llexplorethebenefitsthatcancomefrommatchingyourdatatotherightmodel.
Let'sstartfromscratchusingwhatwe'velearned.Thistime,we'llloadourdataas28x28grayscaleimagesandpickamodelthatisbuilttoacceptthattypeofdata,LeNet.Tocomparetoourpreviousmodel,usethetotalnumberofepochsthatyoutrainedwithsofar,eg.the5in"myfirstmodel"andtheadditionalepochstrainedfromyourpretrainedmodel.InmycaseI'lluse8.
Here'sanimageofthesettingsthatwouldcreatethedataset.
Feelfreeto"explorethedb"again.Inoticeimmediatelythattheimagesarenolongerblurry.
Next,createamodelusingthesettingsintheimagebelow.NotethattheLeNetmodelisdesignedtotake28x28grayscaleimages.You'llseeshortlythatthisnetworkwasactuallypurpose-builtfordigitclassification.
Woah.Youshouldhavenoticedtwothings.
Wehaven'tdoneanythingtoaddresstheproblemofmorediversedata,butifwecantrainfaster,wecanexperimentalotmore.
Inourlastattemptattraining,weonlyused10%ofthefullMNISTdataset.Let'strytrainingwiththecompletedatasetandseehowitimprovesourtraining.WecanusethecloneoptioninDIGITStosimplifythecreationofanewjobwithsimilarpropertiestoanolderjob.Let'sreturntothehomepagebyclickingonDIGITSintheupperleftcorner.ThenselectDatasetfromtheleftsideofthepagetoseeallofthedatasetsthatyouhavecreated.YouwillseeyourMnistsmalldataset.Whenyouselectthatdataset,youwillbereturnedtotheresultswindowofthatjob.Intherightcorneryouwillseeabutton:CloneJob.
PresstheCloneJobbutton.
FromhereyouwillseethecreatedatasettemplatepopulatedwithalltheoptionsyouusedwhenyoucreatedtheDefaultOptionsSmallDigitsdataset.TocreateadatabasewiththefullMNISTdata,changethefollowingsettings:
ThenpresstheCreatebutton.Thisdatasetistentimeslargerthantheotherdataset,soitwilltakeafewminutestoprocess.
Afteryouhavecreatedyournewdatabase,followthesameproceduretocloneyourtrainingmodel.Inthetemplate,changethefollowingvalues:
Thencreatethemodel.
Withmuchmoredata,themodelwilltakelongertorun.Itstillshouldcompleteinlessthanaminute.WhatdoyounoticethatisdifferentabouttheresultsBoththetrainingandvalidationlossfunctionvaluesaremuchsmaller.Inaddition,theaccuracyofthemodelisaround99%,possiblygreater.Thatissayingthemodeliscorrectlyidentifyingmosteveryimageinitsvalidationset.Thisisasignificantimprovement.However,howwelldoesthisnewmodeldoonthechallengingtestimagesweusedpreviously
Usingthesameprocedurefromabovetoclassifyoursetoftestimages,herearethenewresults:
Themodelwasstillonlyabletoclassifyoneofthesevenimages.Whilesomeoftheclassificationscameinaclosesecond,ourmodel'spredictivecapabilitieswerenotmuchgreater.Areweaskingtoomuchofthismodeltotryandclassifynon-handwritten,oftencolored,digitswithourmodel
Youcanseewithourseventestimagesthatthebackgroundsarenotuniform.Inaddition,mostofthebackgroundsarelightincolorwhereasourtrainingdataallhaveblackbackgrounds.Wesawthatincreasingtheamountofdatadidhelpforclassifyingthehandwrittencharacters,sowhatifweincludemoredatathattriestoaddressthecontrastdifferences
Let'stryaugmentingourdatabyinvertingtheoriginalimages.Let'sturnthewhitepixelstoblackandvice-versa.Thenwewilltrainournetworkusingtheoriginalandinvertedimagesandseeifclassificationisimproved.
Todothis,followthestepsabovetocloneandcreateanewdatasetandmodel.Thedirectoriesfortheaugmenteddataare:
Remembertochangethenameofyourdatasetandmodel.Whenthenewdatasetisready,explorethedatabase.Nowyoushouldseeimageswithblackbackgroundsandwhitenumbersandalsowhitebackgroundsandblacknumbers.
Nowtrainanewmodel.Cloneyourpreviousmodelresults,andchangethedatasettotheoneyoujustcreatedwiththeinvertedimages.Changethenameofthemodelandcreateanewmodel.Whenthetrainingiscomplete,theaccuracyhasn'treallyincreasedoverthenon-augmentedimageset.Infact,theaccuracymayhavegonedownslightly.Wewerealreadyat99%soitisunlikelyweweregoingtoimproveouraccuracy.DidusinganaugmenteddatasethelpustobetterclassifyourimagesHereistheresult:
Byaugmentingourdatasetwiththeinvertedimages,wecouldidentifysixofthesevenimages.Whileourresultisnotperfect,ourslightchangetotheimagestoincreaseourdatasetsizemadeasignificantdifference.
Augmentingthedatasetimprovedourresults,butwearenotidentifyingallourtestimages.Let'strymodifyingtheLeNetnetworkdirectly.Youcancreatecustomnetworkstomodifytheexistingones,usedifferentnetworksfromexternalsources,orcreateyourown.Tomodifyanetwork,selecttheCustomizelinkontherightsideoftheNetworkdialogbox.
Atthetopoftheeditor,thereisaVisualizebutton.Pressingthisbuttonwillvisualizeallofthelayersofthemodelandhowtheyareconnected.Inthiswindow,youcanseethatthedataareinitiallyscaled,therearetwosetsofConvolutionandPoolinglayers,andtwoInnerProductswithaRectilinearUnit(ReLU)connectedtothefirstInnerProduct.Atthebottomofthenetwork,thereareoutputfunctionsthatreturntheaccuracyandlosscomputedthroughthenetwork.
Wearegoingtomaketwochangestothenetwork.First,wearegoingtoconnectaReLUtothefirstpool.Second,wearegoingtochangethevaluesofnum_outputto75forthefirstConvolution(conv1)and100forthesecondConvolution(conv2).TheReLUlayerdefinitionshouldgobelowthepool1definitionandlooklike:
TheConvolutionlayersshouldbechangedtolooklike:
layer{name:"conv1"type:"Convolution"bottom:"scaled"top:"conv1"...convolution_param{num_output:75...layer{name:"conv2"type:"Convolution"bottom:"pool1"top:"conv2"...convolution_param{num_output:100...Note,theellipis(...)justindicatesweremovedsomeofthelinesfromthelayerforbrevity.Theonlychangeyouhavetomakeistothevalueofnum_output.
Aftermakingthesechanges,visualizeyournewmodel.YoushouldseetheReLUunitappearsimilarto:
NowchangethenameofthemodelandpresstheCreatebutton.Whenitiscompletetestthedataagain.Theresultsshouldbesimilarto:
WereyouabletocorrectlyidentifythemallIfnot,whydoyouthinktheresultsweredifferent
Inourexamplehere,wewereabletoidentifymostofourtestimagessuccessfully.However,thatisgenerallynotthecase.HowwouldgoaboutimprovingourmodelfurtherTypically,hyper-parametersearchesaredonetotrydifferentvaluesofmodelparameterssuchaslearning-rateordifferentsolverstofindsettingsthatimprovemodelaccuracy.Wecouldchangethemodeltoaddlayersorchangesomeoftheparameterswithinthemodelassociatedwiththeperformanceoftheconvolutionandpoolinglayers.Inaddition,wecouldtryothernetworks.
InthistutorialyouwereintroducedtoDeepLearningandallofthestepsnecessarytoclassifyimagesincludingdataprocessing,training,testing,andimprovingyournetworkthroughdataaugmentationandnetworkmodifications.Inthetrainingphase,youlearnedabouttheparametersthatcandeterminetheperformanceoftraininganetwork.BytrainingasubsetoftheMNISTdata,afullset,differentmodels,augementeddata,etc.yousawthetypesofoptionsyouhavetocontrolperformance.Intestingourmodel,wefoundthatalthoughthetestimageswerequitedifferentthanthetrainingdata,wecouldstillcorrectlyclassifythem.
/data/101_ObjectCategoriesFeelfreetorunanypartofthislabagainwiththat(morecomplex)dataset.
Thereisstillmuchmoretolearn!StartaDeepLearningprojectortakeanothercourse.TheNvidiaDeepLearningInstitutehasacomprehensivelibraryofhands-onlabsforbothfundamentalandadvancedtopics.