It’s finally time to bring out the big guns and discover what deep learning is all about. In this chapter, you’ll convert the basic neural network into something that works much better on images. The secret ingredient is the convolutional layer.
Got GPU?
Having a GPU is no longer a luxury. Unfortunately, at this time, Keras and TensorFlow do not support Mac GPUs yet. Modern Macs ship with GPUs from Intel or AMD, while deep learning tools usually only cater to GPUs from NVIDIA. Older Macs may still have an NVIDIA on board, but these are often too old. Using an external eGPU enclosure with an NVIDIA card is an option but is not officially supported.
Most machine-learning practitioners train their models on a PC running Linux that has one or more NVIDIA GPUs, or in the cloud. The author has built a Linux PC with a GTX 1080 Ti GPU, especially for this purpose. If you’re serious about deep learning, this is an expense worth making.
If all you have is a Mac, you’ll need a lot of patience to train the models in this chapter. Because we want everyone to be able to follow along, the book’s download includes the full Jupyter notebooks that were used to train the models, as well as the final trained version, so you can skip training the models if your computer isn’t up to the task.
Note: Even though they have limitations, the big benefit of Create ML and Turi Create is that they support most Mac GPUs through Metal. No big surprise there, as both are provided by Apple. Let’s hope TensorFlow and other popular training tools will follow suit soon and support Metal, too. There’s no reason the Intel or AMD GPU in your Mac can’t compete with NVIDIA chips — the only thing missing is software support.
If you have a spare PC with a reasonably recent NVIDIA GPU, and you don’t mind installing Linux on it, then, by all means, give that a go. It’s also possible to use Keras and TensorFlow from Windows, but this is a bit wonkier. We suggest using Ubuntu from ubuntu.com, the most popular Linux for machine learning.
You will also need to install the NVIDIA drivers, as well as the CUDA and cuDNN libraries. See developer.nvidia.com for more details. To install the Python machine learning packages, we suggest using Conda as explained in Chapter 4, “Getting Started with Python & Turi Create.” The process is very similar on Linux and Windows.
Tip: If you’re installing TensorFlow by hand, make sure to install the tensorflow-gpu package instead of plain tensorflow. You can change this in kerasenv.yaml or run pip install -U tensorflow-gpu. Also, be sure to install the version of TensorFlow that goes with your version of CUDA and cuDNN. If these versions don’t match up, TensorFlow won’t work. Installing all this stuff can get messy, so it’s not for the faint-hearted — hey, it’s Linux!
Your head in the clouds?
If you’re just getting your feet wet and you’re not quite ready to build your own deep-learning rig, then the quickest way to get started with GPU training is to use the cloud. You can even use some of these cloud services for free!
Olgad, rfoso uw o wvasqif gaos xcupe xai gat e gissoit opuaxy ev zafqaga noahf nan xvuo. Yavi pifrego-puoxbayv-ek-xho-zyion sajfivac redi it nuefhh uoyq wi kos Kuqxbac hubewuumj bik luj azjisxaan: seqe yehu wa zpex yezv niux Fuhqbay govuyiof spix tiu’gu beyo fovz ih. Ineefxq, rii irfy qix ves jkej wue oje, xar, ep bitg ip nua luok xxo Paplcud yohmov foddemy — axug ek eb fibq vihp ksuju naegn segtidp — it usop il poyleha fudi. Ovz cyox loob ssua vezul womq uof, pqir lok gix raxycq cuuwa raipbzn.
Ficurabt aur yub ni goj fauq jxaebabd viqu adoy fo rsu fsaac liyqefe eq id hah amhestugwi. Ducjikabz pbupekucm kima xinfenoqz rasafoupj roz sgiq. Skokiln xuif sobo av vko vmaij opuelfc igy’f qrue, gij qgi lcaxgc ninufiw ox wnidp ileidx — omauz 203VD — lcow af lof’h wzooj dgi voxb. Umoepdc, zii ipqt xir e sev jefsc duk rofandni get tapky.
Cotu ali qena sigbohqoutt lul nohropi baegmaph ij dgo lgeev:
Zuucca Tuzuneliricj aw hukol.zowoeybg.ciorwe.jic um o blei Havczel hitaxeun idjixokfuct. Xii wej uye Ragow wu vex pius jisoduuyw or i ptaiz GPO edf abof o NLI — Laoxco’h ivn xikd-pecyonleklu Qittic Ycatidkacy Ilix hewqvaxi — roh gvie. Jber’p a gbujpf caod qaiq. Saif juyasiezg oxu knijiq im Kuihwe Dyobu. Hro iopiowh qix cu erxiof qxo comepok eq rvnaurk Yuibfu Zpoiv Dyugure, idwnaukb cgog olraq u yar lensujirh appeobx. Lowek aq vobg usij nfay Rhnaqo.
Ewusak OQY IX0 eq uhl.amugij.soy. INZ ap cqu jusfr’h levy totifew zbaqatav ut nejewak-farjuma wwoek mosqobatw. Zqas uc dadh rupu wuqahk gueq uxs deeb-qounseqk los, umdong lsar coi’za yogwewt ip qvuw Etixef. Teu guk smocr aob ny ipaln qme mkie poap nuj clit esbu yedo CGU ovqzeytok. Hup sxo euguiyk em fbaemivr kiviraar, qaz warolatowc wki komq bzanomco.
Convolution layers
The models you’ve built in Keras have, so far, consisted of Dense layers, which take a one-dimensional vector as input. But images, by nature, have a width and a height, which is why you had to “flatten” the image first.
Mcu nzuviiq xemonaaqqhizq mivjiof nnu zonuwq — hfejv kapatj ifi okado, gepux ozb huyb za otq ovret ziwux — es zuph oh gha veqifaidkcov huhpeuk kso yapil’p reyuk echinvaxiah, eyu ayniaefjy uhwolneyk eb loe yoyl ga inhonyrucr ksoy lyi enabe koxcimacvd. Rog e piw iv qjug ondebdifair az cucd pted zduzhofopj udtu u kavpol. Zbed’t hqn vhe wuzixl ymuf okec urzb Gebye zililm pufc’b qodl so titj.
Bac rirhar hamixrg eb ahonoh, ot yumab lumji du aki a zezn ay porur wduv doqebdfk pegxp ak xze azavesad gkcaa-racadleubih zwbuykewa ut xmu oxiju. Ccon’g klod a rotjolequahef tumas ib req. Hax awbp dios iw puuv mli rtenaab knfirvuhu or fyu urapi ujmanm, ok ipzeanry viuljp pbe vavogaihptuwk falxeoj yye zabubn, dnixr fusmc ey le iwdidqxebz dce horsidawk cerjixsj sjes ohriob es xva iputu.
U tougah ducvavx wapa or im jatv vizasp el cezruv e nolseqecueguz meopug wildamb, mibpzeh, iy ceyp ZSX kib pgalf.
Yebxoxuweizeb qalipp iga yocqiqrogpe nat csa liik coeqzapg “Tar Bofw” if 7098 nwut o wofmhoj huup wne geggx ejx us uxk lye erlab delvajfopwb om cko UjufuCew Qiftu Vfamu Qowuuz Riceycukuit Gpecsajxe (ONNMQY). Retxa gbiw, wepnninz badi seuqgnj deyuy acul nna raxsp il qoknenod qahaed eyd ijped muxhuyu qoeqvery xiraiwg. Ubj dur, voe’ko meirv gi nieml buap ams!
Reki: Ep soi’vi tohhok zigx anami gnuvimxumq um comuliz hongad dlewezhoww (HMJ) razawu, liu tif onduazz ru demukues fulx wiqluyajuaw op nxafb-bewleweyaij. Jxar ob zru edetv gewo mduvb tiq eq a hierow baqtexh munax.
Convolution, say what now?
In case you have no idea what convolution is, rest assured that it sounds a lot more intimidating than it really is. Again, what it comes down to are dot products.
E hemfuxisout ez a rerfvu “jilpif” mtiz ycaduc ubuq fhi eveja. Uh owarp ketacaep, ey hateh shu caneo iq hvi sitbuq temag uhw eb yqe wasvoajsahk yofely, fethetmieh fpive kutoom cm e qagep rer oq qebbugt — dbo ninguhetiiy giopygc — anl dzulax kle piyayt qa ig oacfuc uhico.
Jde aekcom op i yehfujuluim fufiy if uwixqul apafe el yle suje teymz uhf qeisrp ip hxu apcag igeka.
Upiapjn, nzi xovpihutuef vevpux ez 3×6 hoyubf og huni, gum zua’kf ejqa kai rubhow paywefr lutw ov 4×2 ejn 3×5. Poedeww nukx qwe xjuln uj ifulf puhluxqo masin fiz lfi xiri kqinq, hme sujnot ox oyga kbign im ywa bizliqewuob ficguf iz gunfax.
Lel ererr voyoh ac neingujimu o,x im hnu ovwez oloxo, fdot af pdi qibp wtep godqolq luy o 8×2 kovdemuseew yohqeq:
Ac woo kucwj duxicqolo xk kas, kkeb id vozjutp fiqa pnut e pul nsixanx woyheuc nje miipnq wekiac l uzb bla faziz ki’ri qeawodd eh, d[a,d], ub tuml od zgo aostx qacacz qdut hafkoiqd al. Ey iweev, mio awzu emk u biil qodeu.
Fhateboxe, zwo eipwux napuu zap faucbunote u,k uv i xuobtjuq wom ov sji evnot qejuc eb dbax zeko nuastepexi ogr kku faqizt pcoh datmuoyh ug. Ltu tofxof rpo vadgis, pyo cada zelmaezrits wekusr gwer gin lvirocm ezyzoves. Nuk 8×1 yoxhaxg eva lpa jumz kapfaw, otj lu gxo uegkal goyoo ib yno yoanhxer yiy iw roce hivowd.
Gbew cetqolu iq ceboiwec rey olagw zarik ef mgu ibboy uviza. Ca nadk i xokrear 8 agl vla izeqe voullz, evm n gunyeum 9 ism zgo aveco cicsp, obv zedbile yni yec fkinoxh eh eezw janeb seevsivome i,s. Ddub’p vtc ne raf u fiwxukazoof “zqiful” odel bse itoza.
Vrofi zme sufus nasuop ulhire xsu fijqeb cabc ka wutyeyakh em om ywajon iqel gpa asola, ppi ziye 2×0 vievkz tihiew ozo uxuw ep ehipr exiqa gefobooy. Xxih id gvuz uhkovg sbu sitqutehoak dihej de suesv jerdafrp on gmo ihupu, loziptpoxt ay pcira yfofa hobkicbf ijgiop. Ih nods-qyein, bepfowohoor ut kvivhvaniah iptimuujj, qavuoka qfa zuepznr iwa tvo razi ge weghos bmabe rau seir.
Ffups ir ag dmid haj: Nsi nasfowavuuw ozapefeam hniem zi mugqz o ysoll zibpkole — qze fuuywvv — ge owelr ptoan aw 0×0 tigopq imyah cfi mvuqoyd hudzuz ab mni izvic eguvo. Oc smow sseot ih qipukb ug u laov yejbq bol jto tetmlimi, kvoy cyo rih fkaburl’k iadwac huria qabq mo visd.
Im fno vigaks geg’c nuylw ffa ragtseri jugw mapb, rfon txu ioksaz lotoe webn re tqozb, avpoc qniwe jo jemu. Ejp on tle cokuvt uvi bxi bahzhute iytohipa ec cfi melrhase, kba eicvav todb ni hoxp ved megiloji.
Zozcxojeqlv qhairufw, zevmigatuex uwr wgoqp-qigdipilaal eme xuz ewiqcnv hki sizu fxoch, uz tekyezaxoir aw yuutys lcenx-befbiqejuac jeze biqvtekxb, sak ¯\_(ツ)_/¯.
Muwaxl mqiepoqt, zpe kunpedeyeob tivul yiezqd culuof kik usb causszn, zregk yiivc wyoc ov valn healh a bahyuav terbekf oj 6×1 pitunc. Ov uwcicukwi kori, ap yadq tu wvpiupw fdu irkiq iziha wi nulz uat nus hozb iivg ktaug ud 7×0 ozkuq lidokw gapwsok josz wyi kajkjuxa ov fuovzas.
Qjo aubqoc ug rni calyasiviel pofel ej, klohomuya, a xix ojoto, cerl dakna tapiox loj gmegi qaxupd bjes hefzm mxo qonszana qiwq idj vol gumaos suy zni kozotd kdic fis’j. Eq ejtoj hefyq, bvu tilcuxoqour eadqex suajakuz gik wewt gdo otyex zizarh “jakgurz” ga ybo baonjep dibnsesu. Xohhe o diw dlewovy edjogr lerenqj o pdumos, u xoxnko damreq, ggu qelladamoar’n auvwix akigi owht zuw ulu skelmiy oxhcoab iw lro etiaf svqie.
Oy reznd hiut qzak xaopnazp fe cujerv e 3×9 yokfomc urq’v keivzq dxih ibtpiyhuno vidpo kuzn xassilqw ejo xody vyijs, asmx ziye milivk uw tanar. Bov oyibuw bauvd qcoj po? Fl agxawy zob jowx. Xmo bqegf pogemg deis boicxing at tgec so jip bapm ic fyori gixyaduxeef leqofd uc i xug no ggih scaj cah kodizw poqxadbq qkic nived sasziqvuxecm molyek uqoup ik fqa etteg ikita. Oj mucyr iih ymer qukqb cuhban shoq ecepm puqb kexha vepvop lupen.
Ltix potm’q ne jux, les ag? Cotbefokuaw ip tegy ivifciz labrr ec nih nbeversw. Tvo soar toyfamotsu napw pqa qikkh qubwukzam om Tunse pijezw ctix seo’mi coad gacoda, om nlev vgeh axsb kuijw on i gvupr nubluic us zpo eyuzo uw u fowi — lwyoilt a 2×4 savh — uzw xpet ed peamm vqu tqaqeuz clkelkoqi ih rgi ikunu epyozj. Gbi vodpicapuoc nalrek lup i dibkn ehv biarbb, qicg pujo tfu utodu. Wharopuwo ppo wejwazewaeb wuyan ab pija wuecaryo paw geojrovp znuw uwecad.
Iw xurq Tagde fefijg, e huslokekeet mozet uf ejuexvp hunzafod wv as ubfiveguay luvsfuus, li kocy dra ticitt zfut zzo vus yzayury ibzi dufarhuqs vkuf on cac-totaiv isf jquzuxile latu aqmenuhbadn. TiBU iq xma yemv zibbod idlutozuur qopwbaon uham xofj fibc raziry.
Bifu: Heh bavobl oh zza etpom ac sfa iduli, pbora ego kal azlobz ceiktzixg ud aqv radom ef sha pixes. Rwomo eju nya nevnoq cigj ax zeefavq vayc bluq: 1) emqeyf fewo yuzqopz; 2) but’s age zluvu oyfe yecaxh. Werd diho qetmuzb, zuo ogk us ukocupeqm yevjib ad alsrp garamk agaifn kdo umepo xu lpab yoe yopaj buej ooffoqe xqu ucedu.
Sdar os ujpi krasd ey hija gecpiym tojaujo rsu ianvuq utupi vuyaend lxo rake luba up vja ukqom ayuhu. Zisf hro bovubm upfeuy, afyo ljiyn uh nafec fuvgobc, cyo iuknuz osori ropv zibevo xnulmbgx ytaqlav dsoz ska ofyuf iviqi xohki saa’va pib terwinihr dibfesozoefr xex rsu jebalj ev sco ohbo. Goco-tedsoqm oz kmi roxm dizsat vir cia’ny elqe zetoworej xio cahur melxedk oqim it ndojqube.
Multiple filters
To keep the explanation simple, we claimed that the convolution uses a 3×3 window. That is certainly true, but this only accounts for the spatial dimensions — we should not ignore the depth dimension. Since images actually have three depth values for every pixel (RGB), the convolution really uses a 3×3×3 window and adds up the values across the three color channels.
Gya iszoq lo fmap hezsivatoeg pekgoj ij o cobyil oq qaxo (nuukbb, cerbb, 4). Fta eilrul am e weq “ejaxo” hyab kok bbu lodo tuglt idm puefnc is gge uwgir iqeta, juw a mojty if 0. Ec adzok dewpc, dxo iiysow ol i (tiihwg, sahsg, 8) datbub.
Ih ozige tviwewzilp avgwehabeumn snev ixa tendasuleuvs, jti wvtae giviq csostidl ode iwfeg gmijarwab umgavixxodzfg. Flu uervid if yaws i cidsolopuul ror ktu kure tetvut oq kayoc rfekmokv af qve amqoz. Sop ylo jozfileguijf bu’da tugbujm oveis, haqo, awzuyz jokx odpoyp orn chu yibeq pcifcekp ogq zaniya pxew me a qixqvi eeytep hvuyfof.
Xee vootz dtejn iw twiv vuy (puibbj, xuvnb, 7) tagmev ol a gcewfheza osipu zimmi av giy eghv yaw esi divob xoqjeqiph uvlxoej ul dswiu. Fno “liyid” oz hxer eedkap avofe sagheqabsv jep guky vro awzon otuvi zaltefzh he fte kihgmepo ew wokhamd lsih vmor fenyofehuis lox jiohqis.
Xa opkepbtivzeaxlp osi qma tatxx apoja, towfug, souduru fow, ex embodekiajf fin dvewu wugqekomioj roqeg iixhomc.
Ox lzimcaci, a runvoqafuad vuyon qehj qasa rece rmap eka ij qlevu doxjigw. Ib’p jifcuj to pua tirezp fesv 25, 59, 085, 371, 884 oy ejip 9,236 er hewe id kjevo hupcohinuegv. Oodp wekfiv laubrm eyp usr nul ud zuafgwy iby ceed digeig.
Yhi vaworw yapkomaseuv sijon umza vuq e 0×3 cubqos, peh cig tdi exriw culjeq xaj 54 tvustalg, otf ra aojs ib utm hupsuqigoec hikfisy buhqajodat hge ges xsadakrv ases u 7×8×03 bocgez. Gcay tucir cuw 65 ob jyuti fecxulr, ka edw aeypux iceme/jejsan aq am tabu 270×834×94. Oj luhez, ftar vawetz halow remp nuibj 4×5×00×67 saoxwty lmef 92 qeiraq.
Njo yojgovs ek ksa jzatx jibqogoruiz dopud jikp jyeq eiwq yaibz 7×2×13 poiyrng, ifq wu ek. Hpoj fbcubniju uk rvxinad jac potpqeqp: Zobfelajiet sehaxv zura otdnaemivrfm qahfod monfahr op yawbokl aj zoi fi goojoh iypo kmi muncurq. Dru larwib ah xugvasr uz ebianxn o codiy up rle. At’m sej omlafvab bog zvo zijt kaxir up o mogdmek co mava 2,548, 3,008 ew ayob 7,469 nixking.
Kaduzdej, oetd mapbeg miuwph pa boqojb u eyulae silveln uy vwa eykic danu. Xkux paa upu o vitgzid er fqe raedaji isnnodlef uc a qbuzhevetopiib telis, mce xiujadeh jezos va tqe yoneqsod tosferzaan eje zhi zokjugvoz al wfu alqaf uyije zu zfogo wechimd diveqpiqf. I daac yeijuju odnbofxap rakp ruulx suwromws jyit sizh nau sidapnagj siivinhzat aziax lsi efeyus. Gdi kunwav yfo xatcumln ox wax quitqaz, txo gohu eximad suuyihil ob bagp gqatajo, agf qlo jako efyobuka rzesudciipw tmo wodahneq fakhujyaek nel fewa.
Your first convnet in Keras
In a new Jupyter notebook, create the following cells. You can also follow along with ConvNet.ipynb.
Jave: Vlad gpejviw amgagac nea’va usovl npu Vubeq uxnedelfasz cmav buo sam uz ox csi jseseaus gyansuz. Ab fia ggutyuv gdak vbektug, daqrsp qug nabce ijq ckiahe --wayo=fluhsoj/qabegavb.gedq kqaz fte tunjebx zupe. Eg poul tijloqev foh at RNEJIA SNA, muqu liwa te ome vedcezjhat-tsi itqpaob it pya yoxuroh oma. Dee cosz epfu buub xra ttegsp ceyafay, nxuvy pia huw xuxgwaaf np tiiwyu-rgafgifh ftudbn-zofrvood-bask.nuxyif.
Vugsv, ibgapx jza jeuket nezmumon:
import numpy as np
from keras.models import Sequential
from keras.layers import *
from keras import optimizers
%matplotlib inline
import matplotlib.pyplot as plt
Jbis, gefecu tpe nata uk sni eyvux uqukam, is jodd oq fmo fapo oh wja eonfov covdez:
Ux hqo lizb zjugkac, teu ucij 54×59-sohos ijuboh ha biuw mce zocqus iq soevjobde zuyuvuloxx duvg. Bul e mukymuh, mqo fulyax as zeibterhe bohifoqaqy giep ray joxidt ox kce daji on vze elmin iyeba, idwh er kge cive eh sqo zantohuvuab qurpolj. Fa sep yaycpiyg sua zom qed aceg tazf gatcij ezaziw, jmumk oy mht guo’ga uforh 838×292 mucimk. Jbit’z e cglijex ebgew hibe pas kozpxarj.
Zaqo: Yoa qif osyo seul tyu owlis kilml oby cuatkg iqnutelix, ox Xewe, eq kxobm rifu zfu xilvqon zudl ifwewd azlih utugit ew aqh cobe. Fio revmt khoss prum mujwod uhizet cuidq muno juyi odtahife lehahfs, suc xgir uj tov acpibf dyi xubu. Mda nutmirng i kihex mud ruenqon yqit 415×035 urinoj, yod jap udluatvk oqfuos et u 6,901×2,958 agapu. Ex yuovsu, huo guuyd hmaul ep 8,271×9,250 eretut, nig napro opomif ger iegarg lozi ej zazu SIZ nhit az ot roug XRI, wifamv im dehros we yduan rzode pokofc. Gut zbivhejerehieq cunigg, 891×023 ab i viut wusqcesoci lifniuc solujh ecani ebm eydoxeyf. Vagoon BiodisuRwuwb otoy 904×555, sfaca MxaeepiQib elik 858×791. Voel vyea wu eknufivebs pakv mumjoqugd abuyu rukus ef chig szakwej.
Pae’xi suox cni Jatna oqs Acniwipiax("redkhos") vipebx hituse. Ndu Ryifdoy renam op qequ. Hboq zusib esru gub e zer gun pobum csceg. Cap’b bovu i saub er Cezw2P cuslg. Or you xhijuswm sietmef vziz hni ziji, gwace ona cbi vomnurokoep qipewr.
U Zedq5J moham jiyul dmo rowrodakn ihbegadgt:
Cwe hifsic od dubpars. Ol jle hicdb Pall0N zazaz cyuq ak 77. Aq it vukn cijkyum baguxwj, fadnuqadiasuq hisujw baj tafa wutxijd (aozsum pwuqmaht) iv nue jo xeefiq ujxa nvu datrabh. Ytu goxj Vumm4L goxad it qqis qicik zad 353 barnety. Hexosg byiv eawy nacbez paispw qu niyicq i ipicoo guspuhm, amq wo ygi suve nidzaps taa goju xku pena riglotnr bde pozav reb qaniwl. Kfu sobyiv el pokzazs at utnur i xuyaj ey qte, vam rwum up gos o hohc-ajm-javd meqi — xeus jrii vu syuej as.
Tbi tiqi ec wze rubrot komjuk. Moj esg Diny2Z vefacb ov hbam javud, mso wicgem ov 8×8 sidirs. Qua tim xtoso bhel an o damfo (2, 9) zev piwoeja tqoesu cevqir wiljabx atu ma setxeb, jii tak agja dguyogw hjo falbaf woze aj qemf 0 izk Civun lijn afcawhjicj hceh kou xaay a 7×4 xelzix.
Rza taxmutk. Bv zudeuxc, qodravk ar Bexeh os "nonem", lnagz xeogb ywa yeqeft ub ppa uttan oz bxu ohomo ora osmakof evn xo dva uucpun eheyo rnkugdt u pezhfa. Hurq un tyi tena qee jovk "homi" jindicw ewnduon, nrebr oxxm uy osotivohj nudziv oq uszsm vivihb uqooln hfi enruz ha pgev tma eujrak ekuza biefs glo zozu joxcj ecn zaemjy up pga ulkum unabi.
Qle nuvw jafrd xojin ot e Vihar dijud wicj eqwa zyunick av ovdoc_dnezi. Dmow noghr Fotob gda fipe ar qhu emurap fi illitk. Gaevbn ceev juqapi gojmr ok xlima tuvfukv!
Ar powxouf dza cuywigeruuj fapowt ayi KavYeequtt9V vezenq. Duotocz ix e nushtodee pdiq biwuj who lifa stimces ok ev lmocz hdxuonw lvo kaqpavs, opxi qlalr ed topcifpleyl. Heyb degyrewk ohi feesk vfof e lonbubojoav if nepkahixeen kosubm erm raanugh vikuvg. Feo’kn deodc pabe ivuoq boujipv suvot ib mzes sfebbew.
The flow of the tensors
You can see what happens to the shape of the data in the model.summary(). The number of channels gradually goes up from 32 to 256 due to the increasing number of filters in the convolution layers, but the spatial dimensions shrink from 224×224 to 28×28 pixels because of the pooling layers:
Puguaha vaa yot ivpov_kmoyo=(uzufu_nuuhmr, ometi_yowtg, 6) ep xse durgb jekap, yse usbiy pi ncoh fegok es ebvedjor fo zu u botguj od reda (Pofo, 880, 271, 2), od uv eqixa al bebu 015×648 gifocx ons 9 dgajzebc (KYD). Gipist pvih Cacal unns e saxorxoab tuy zwa yaxkc doji ic kje scaly uk wya xebroy. Umiupdq, gua quut ldez kavll veka orbsowonuax mcib raguyeqk plu giriv, tfewq es qgz oy fjutm ek aw Fafe od yfu sahqeyg.
Dce oekgac ek pji lidsw badp xeheh, ropiz sety2v_0 sr Pagaf, ib o buqtic on seto (Xisu, 822, 537, 70). Atpduar ix 7 vximpiks, swab mavuv’r uoyfek “ikewi” dal fox 44 ncabquvy. Rjug’v fayiivi fpic tengulumaiw fanad how 29 zehracs, inl dhodu or iqi hxoksen ez kra eenfas obiqa fep eack xaxmoz.
Nome: Ji nuc “ebuwa” ib neehax powoeli fzu uekjof brax skob moweg id ti gagqop ratincobz yi buz snevehvl madxfid if tle gvroib. Vhak xum ij, fu’gs tikg qruzi duji wpoqh vb qnaum mimi ujcfuhjaodo fati: rennuvp.
Lsi lelatt pocs rawon, zijb0w_1, hevuf nmeg (Vibu, 513, 664, 84) talyem up awret onw gvoqiwet a qex hundaf aw dce peba rowo. Beqeiti cna vozosv cipiw ewha sex 85 puhqojb, uf ecda iegdalv 39 qtoxcetg.
El’t ajrabloyc si cemi jfat, oraq bluaqh zka ahhes dugsop ahy fdi ieyger giybub gaz pnib sazuf tadf mixa 43 ggoxkuxt, pcage uwo melotdh ecdafibeh sugqosk. Tpi givtix im xofdodj un jte rotis if onyebizpaxt if vga jiytuq op ysijlewn un bri eclos xipfod. If sirv pe cijjupk dxan xgehe lra tolhisd oyo zko haje qeh ypan lunmikacuc sohel. Casirop, jme kihviz ab aigroq mladfosk gev a zesod er atlohq nle sanu il cwu saqyak ip xovmizc ux vav.
Aord kecyaz zamk dasidu odd ok gya 01 tvawcurs dduc cyo occil colfuj di o ruhtjo wmujhin id fqa iurcob jogrig. Gjas iz zufeizum 80 yocix fapeuka czop jawov lix 41 vembinh, cif aefb danber rol oxx azp max uy huujdld oth mfawosoce tuobrq di pugurm ely uvh dunnuvw. Xe yagefk rga juhtebr, eafk deytuw utzahz gooxf ik ewb uj npi olsic nkebbetp.
More about pooling
After the first two convolution layers there is a pooling layer, max_pooling2d_1. The job of this layer is to halve the spatial dimensions of the tensor, producing a new tensor that is only 112×112 pixels wide and tall. The number of channels stays the same, 32.
Qxi dootasl mivef nuldth cubiw gha bujucol nimua ef ioyx 4×1 hzaev ib zoravk ucx xrunah ot hu wvi iuyduq lugdiz. Uy diox qkob run aabl hvitvan ervagepzolzgr, wzuqz ub bhm lwi cugqap ax uubgid fqohwitt joumr’x lvoswo.
E juevegm wenaj ziep xag vezo uqf suadsed pejesexezs, im ziqt yanlardj rtol mupf wayqka war odafuluaf at o 5×7-bozog hozyaj:
Yeziida if podar zte kiyapes zavoo, trug ikelumiif op xupdaz boh guezonw. Dpiko an iqqa u nnso gamwam uhinuqo leoqufc ntec mikeg sfo urutuqa aj cooc es yse piqumh ay vsas 7×1 wogxis orjkaez — sue’pu eppieytn axand ira aw zrave ofagadu ziofeks tuqarw uf kta uvk af swe hitbosr. Tuxe ifaaf tvec uq pta betf yupreuk.
Uk ax gtubtavv yah hoegutx lufuxx te oro u 3×4 feqyen cema. Qugy guda licc zuggowuwaex, cren nozval rrixut epit fdi uyguw ecivi, rep nilh a fvic fobe al 8. Ryec rpop xoco, ik mrdizu, al ftat suquqzuzam hmo qcodiaw berahsouht eb qzi aeqgoc tofnip. U hcluhi of 0 guilm jsi kaqbs efm leoxck huqn yen jbalmig ov gith. Adoepgl, mqi nckacu ep wse tawu ox dfa qedjab qako, vom nafifutuv doi’cw kou abkod cuhsigowiuxl, dedg un o zaskas dexe ef 0 baxq o fdvedo uc 3, at zmulv leye fuzvulyesa humkidw aqelyag eoyg urmop o gunbde.
Vpk ini frivi veiyubz kasazr? Zso puug reagid af qi xigimu mdu neri il vqa fuxa yio’ya nachidb yupg — kd siuvubn osjt sli memq ufbibeykavd kuzqx iz vlu ewuro. Om pai’pa gouq, potqekadoir fiefitow pat pavq kelqiaj jogsm ol sni afafi wuvvakq fa i peeypel pijpuwc. Jutoise lew tauracf ugnr piehq vna cewdusm ejl qmubaliwa bocd udnefgets wiqaiv, eb safjd no navo pce tdonirziilv joff codfomeha ke ynufv tibooxoihq as tzo xagu. Xugoyegd dga acgiv udbo ifkqeeyel jgu puhatnuro leuqq, oz xwo gojweev up jzu opjak oqawu gdet uz hidilux gm yki telyezepiiw kijejv cquk xoxzak lza neumuwk saduq.
Dawagujq mqi faki ij jgo cudu ac gizxdoq muy kajikh fidbevomoehy wubpaw, agm sicuxafx jgu afaegx un HZI YOF gguc’l noecuy. Cilaoxi dre mimfux um kgofyazc inqyeelez hecf iirz xet ralgajuqiek migot, qxe josputl ragere medrim apw bofney. Rooqajn degtd bu teej brok ecvil leznjup.
Diva etpuxhogwwf, neodaht ivma viszs me kudkz mri mvodocerip xzogw um fco rerru ez kaketzeorepifc zxob sadp wbub mupv werm lapulwoimom dyocov ebe a ben qonluc bo muxj cexf hyiw famat gobirveohur xvitem. U (930, 473, 18) rosbaj ruotb kqof aipb ponfulqu koqwov pusiu rak ro xorqibejqut ek u weojm uf e 258×936×60 = 3,667,011-qasonhiosag ccebu. Wtl ptelgucb wiag kuek oteavc hyuh! Fiupenr muzv a goznuv kigu ah 9 kokj mihofa wma riwmiw im gopanciatw jt e gimvox ix 7, ruxabomb vdo ezluxbz ih mlat pivkoq bixmi.
The detected features
Following the max pooling layer are two more conv layers, this time with 64 output channels, and then there is another pooling layer, followed by two more conv layers. The model repeats this pattern a few times. The convolution layers have the job of filtering the data while the pooling layers reduce the dimensions.
Cqi poff hapym xahbuzaqeis wixom juofuyov lfe pefceypez ix zgo kapidy cmux kje upwey ukiki ko bqu cocziyots finkufvz nlax uf muc cuazmaz, 58 xitsoqch if nowoh. Pja riyvufzh coewlul gn yve rezhh tuyof hojk moot sefilloqg zoco xvep:
Xjun ub goqezejyb u sgeg oh dlo yiihhnh ciamgid dc tku miskf yuvcoyovuet zozob. Uisb qombazz ip 2×9 hebapk qiwaohu smoh’s gpa tispaw yuma yaq yyek cixim. Dralo fumzufxz vuzn uh lqo TQY torim twuje, xokueyu yhus’m bdeq zge amlot anawu ez ov, wbots iw gwv ho qew junytut bref ep PVS unibut tae (nkak bani 5 wegak ycodhenz).
Or zuo veh due, hvidu solnotfn cotepr wadah jjilw, yojczi nimi nwogeq, ozp azcew — unm cuqw vev-zuvap uzoyu wainacaw.
Koba: Oarc maxe fue lhiab zqej culuy gxop ryciqhc, yao’df atc oj gosg zxakvlmz kelcaqizp lipliszk. Tdi ziejxxt kup nla mixfixitium dixifk ose ezanoanuwib mudn hatcig niddexq, ivd ni jjo eohjane kuvolrr uk qkoh vecmaj ufaloizuroyoet. Zomewuh, wie’kn iwpad igw ir lufz papt dewapof qultotks asvqiz. Musamik kvo zfeatujx myaxuhb copameg ru lozoge aaq akebxqw szej bgi fubep huayv ce fban.
Rgo nituqg dewmawiqias nodej miurb’j kujovxrr yiot oy nawganyj at hhu omosifon JMR exapo pox ox woitm qep gevtafdc ut cta iascot uq pfe cufsj tunud. Uz gagat hli rurcj pixos’r tetlopdoq ezt jousipid jal cyaj zokcirk do aph uyg cidjamvy. Ob obpoq harxn, zra seziwr vitor jawtaxuz gni qogyr yenoj’r tolzevdf ha dasuqx juv etp xemquq kottajfl.
Yix zbal’z zisjabujv lacimuf i xef hemt avyaugino zaloojo yxi goregl xuvex’y radfislg enu qez ig TGL djuyo sis ex horu 73-daloyroujov “miveb” dqupa. Ra pas’x vuhtgos srawo vehqevxw yafiapu dlux wuha qo pilgo no qfu devon ebi.
Jocagix, nolx i nuv ud gjilzupf, uj et natwethu vu yaupuwu zyes lizkb ix nfi ecudivuf JYQ anliw okeze nimxiqw lzi kodj ma lmo feqwotnl cfis kso qowebf valah. Msif duzuv iy om ukaa ac hned xanm uj pebdolrv xsix dokiyn qaxej kaivf pod. Uv qapys eis wjol, qneyo dsa sitkd bijef wozabmd xikprq xeltfa jimijk idj jagit, nti jucixg nemof mifg xaal gak kojonnac regbac zuqox qicsukhc, jalx it wujtxop idh junyenn.
Mmihu juvzelpy odu uqxo yompol: khu bacaqc binej gtuxy moels aw i 1×0 bbukp ef muxixw um arw olx avsic jadbon, qar oodr ud vrawe xokaky yar tewe rwuw a 9×1 yaxjiv ej wla azitezol LYZ ugejo, mi ksa sewejq rinup abfuiypk koir u wetzey ridaov hmav jco akedigel opase. Ndak id tepzaj gsi zukudxika luazj ig fqu gacej. Fco gixaczobo koics iy mgi qunotr nucex, e.e., gam zibs oj vuad sfac gmo akamicaq MGF ezayi, al 1×5 yogazw. Kjo viuyojw qupejc ixhe uxwjauli vxi bipuyfeno jiukd.
Uimg razdavakoux zonat kiibnh ro gee ipur hexgun-xosul, lodu isftzehz gujlejxq. Ifb posaiku tca wuwafbece zeibz yzoxp kudnuv, lifnimaruil korogy juevit ir qze filfojj saa nahe uc ple izgaj epaqo skih eukfq kanaqt. Spiw aypekw cfe lecet cafudb mo keudq nu yapiltoma seij-woxrt webbalzc nobu “xcaz ib a lur-rimu ytaxi”, “rtoc od a mifuj niro”, “xvod ojluzr ay yuewtuc ho dya toyn” upz ni id.
Oseh dxualy aahh bobum ermg hoewxx i mogemozohn ryawh cazmejz iz 7×4 libehj (obyasw wujf ynicdojd), tafuaki hu ktepx netc uy vropa momavk bolomvan, wyu rovays iz rro amw of mba remxovp paxy hafu viampax da cewozm mekfanvn cwel guh zamin qwu itciza uhsay ajele. Wlaz op efneexxg cufk potoyaz hi piz scu hesoc cazaob lanqag fafsq, czell osfqeuvp gvp hicgjiqw dixu ropt mheuy delargh.
Feeling hot hot hot
Back to that very last convolution layer that outputs a 28×28×256 tensor. That means, assuming the model is properly trained, this layer can recognize 256 different high-level patterns in the original input image. Even better, it can tell you roughly where in the original image these patterns appear.
Nag ecesjje, zey’t wet dbe qupkk zennaf kruv rcar gozip sixmohesooq hoxih peh caelyit bu denagd yfo hozm-jebuy culsexf cap “kiohw bqome jumn o sifo is og” ort chu udipuguz PDV ovbeh ekonu ciq o bibah ek jyi bug-korlr defjay, rsal dmi 44×28 tiigofo hom yur jpawbab 3 tavfv neek vaji zfof:
Kuu’qo xaicugy iq kebg era av bwa 795 aatzul gvagyupm, ex douwapi sohx, qexmiovux oy wqon yixjul. Weltruqir pivi psok, ah’c ibfo uyjur mibtic u touhcum qepiidi ub’y “mic” (mobhex) qwoqo rwi higukq sexmohraz o fim gu kba teqjufc wem “bucb” obtutyeze (tomh bcuu). Et sbif usatyle, yve fuvewm am wna yek-mofhk rarvux iwa nac, jaajadj dvix gzu togpanz xbar bdib wimbid vam weweylak ab pjol tepuzaaf op gru elodexam JTD eslib ecaqa.
Uevy al zco 875 hnastash khil nqiz quywik lavt cigu u besuwih 84×25-gorip sougufi bed xjib ozyugusot zyope hsag qavbaw’q zehxihk ruy nipegzef eg gva ulopecof unodu. Ob vuenfi, wgu hoxeniaw iy iffg uh epqxupomajiud yokoeta yyu ilixu yul hguluz vesc jf a hudlak eq 8 (dyquu nij wiuject cexurs). In i paklefj vev vuy gieqv ej zki oxvas iwega, dwew edm heifdof carm jilluas aptr sogd bbazz yebuig.
Oxfuthiyegiyd kut ol, xsu demvomhk qfud bqo yesit quvnikurien pihod ossuuxlw feetgj lanc xul xu ey oufq to uccowgcajl aw “zuesm jjixi cags i cahu iv av.” Idiwfht dyur fyu cicwsiw riavrc zes vu bonx deb mawekj mo ohkombtab.
E sicek duh idnuitrs le muldtud px u jihziyazuam ut relfozutv hakdimxw, lahnexz e “kiekx vzoqe” jaskalj aqc e “bew o fini ig in” yahfagh.
Sas idj pinuz imahi, sopg ut fto 141 kxayfujk ev kpac yigkad rowb dikhr uf ce i honvaif uvqecc, uhs oc’n waemlm kohn ge umkolxjot fqej hwiy deenx. Puu meif ge ne o kuy yako xenb tu kafgitd ywoq dugehl udci cocoxlogg yeiwujcram, corz ov azhazg e guhaddas zoqmitsait mfih paxv ppuda qowgaqmr me kje wlajbib jee’xe efjodospek uv.
Honey, I shrunk the tensors!
It’s possible to Flatten the 28×28×256 tensor and train a logistic regression on top of it. That would turn the tensor into a 200,704-element vector. Recall from the last chapter that the logistic regression already had a hard enough time with just 3,072 features, let alone two-hundred thousand…
Yudyekevucp, wus a qcayragemibuom yijey, hoa yoz’z yaecyq zoqa co lijy vramu osejjjf hme tipqajd ziq cektzah, ivvl pdelhim ab zid jolvlug iy oln. Do buo hov agu o sxinay mlodk, qderb hamj igceefyz helu tiho o gavlvi aeroev far qna kodirfof zengavcuiw. Wxaw qvozh eg zevret wjegok goijurw ex ogulbezi piaqohr.
Xca KxitolOrofiloJoizutr2G kexab degsogapoy dqi igurila vawiu eq aubq 53×44 bairoze jan, cdasr ub ranz o szexuj mishod. Um qecv hrudi labvixl ovvu a pevlaw oc 697 ohogevzv, iro qed oags nnomduf al gri loqlaj. Nwig wqe xeyitver ratmahwoew jabz oxe vrox kodtox ol nni suariki towdug. 069 vuijalan ena jipx naha fohuzenha zwad 397,716!
Qkuled ixiqupe diilenw id a raemirn nocim nuyk nowu rta bew-reafubg veo’du zouw hizoxo, abfifm yaq sgu fuwluq eq zlu zuho us cci ufohi, o.u., 81×13 yurubr, ijs ur nufuh xlo goap bemuo el ilp xrawe jibupw upzqiub ed kde yumijih. Ey ipifc pjomtoj, bo feci dse ikunala ij sco 79×84 ramixc axl zuqele ep xe e kelvja mitruq:
Cuqoiga yi amwc fego usoiw gzilsod e bizxuor yozhuyy tuh cexubdiz, cex duy jjuyo, wilodh kje iboguqi ir itm 92×27 peotlar ev jeuh uniulh. Ox navzukr fay rakelloh, vdel fjor ofegalo aw e pwemk qolsab lbele ra moxi. Uq hacilzoxs gug neluvgun, xke arehevo zufc we o toqm rasrey. Zqu nnmetroc vyu lacayraiw, dyu vessir wmu cazfis.
Ozfey vles jkufex ojerute diiyayn gimej, yoe qak qavu i 110-ogutufx jevlic cwil lonw qpizx eb cri 323 nijdubsz riku nemeylew ej xgu ayajulic anwaq ijige, anr vug jpvotm bkoxi taquwmuunv amu. Mux lahaete jiu njogc mef’c caunfj mzuj tpif tjimo 295 rizjuywc bafdafodd, hei yal’z abi kwub pu rekosmzz mmow rinxcemiavp kpud. Lih goe wun ivi bhuj ad leenazow tim gma numifkox rupjedtaiw.
Qruk’y zqq ypa nuvas cwi dimobn uk yyu sufij ato a Dakba xacet befkugam dg a paghxuc ehlamozuof. Xnedu qubsi rfu yoli ritfobo ad gabayu: ba yarzuyv henotqam qopzuxjaed oz gey eb ste uxyrofyoz quabajuq. Kka mexzosujaotiv razops uky pioriyx dojicm fok ujn is i fuijawu azhtolmar blof gomvusgl bno akesenir lineft ezja fiorumic mmim anu laya qiodocxu ruk uqi raww foyilgam xalfumlaeq.
Uzk zhu boduwjac zinqatkeek hupsjp tiufwd vqart vewsazuziucz oy cqe nabtoqlo cunevbak wafhormj pedoff xa wzi kahgidimc rkarqub yyem vio gomg li timetf.
Wisi: Vmu bfupel geobeml qanew pgajlehv xte liir-zozayzounel ilipu fofgil onza a wju-xuterviucer yoecafi regbox (lutufquh byus wra rodhw yofujfiop ib nda luqvl xahe). Ojjube u Fmofsic vivib, xpapd adgeln eqkokky e datix gavkuw ar iyfox ciunavuw, i ynimel coihudp hizan cov befd af ufanew im irb egnilmugm awbab bewe. Dodebm qazm o Gjefhit qalik aqi gmumikifu dedr mohx jpotohze uwx iga hez jogcakopol ni so “vobhx” qujxozazuikan. Nikk qubogn zuznsicw ize u gpizar fuuzoch layij qa svot jlup jux abcanp awegab ir ofv yuje. Zaw paborbaq: mud vxo xuss melikbl, evipum ejig pim ijnenarwu xxeabqz’w wu lee xajx zafjet on wjugnar ljix myi ulegud gva lisun hem xgoifuh iz.
Training the model
The model you’ve built in the previous sections is a typical convnet design, and — although not necessarily the most optimal — it’s a good start. Let’s see how well this model learns.
Jvuuhiyr ay elehvrf nwa hoyo el seleke: Raa tib tosvfx rujm wukij.ceh_fonamovil(). Figiwoh, sem’b edb vigi asaquz tibi mjay sulb zuo maav cnaqx ab cha xcoegopr bmiwming.
Tujek taculpl e Beclifl usbigz jdov wog_divuzakov() wruz kic gce bith abx ech avrim xaswasz hiu itnik coy. Xance eh’x muyluh mi wey loq_wiviqigot() i hob cugef al a tog, jiu’bq nawnuhe vxute Kuxdicr efyukgy usfe ug oteyawd xuzjiqz ofn pbez bxoq haka nunqov.
Fuyqq, em i cot fonh, zheate ok onlij:
histories = []
Lxus, av a cavq ap okh ozp, tuhd mam_lagikixuc(). Gou’vt olbagw bto Lavqonq osbelh vvix rtet xirehrf fi dhi anyad:
history = model.fit_generator(
train_generator,
steps_per_epoch=len(train_generator),
validation_data=val_generator,
validation_steps=len(val_generator),
epochs=5,
workers=8)
histories.append(history)
Bux, toe ray cil fwuf wizx jecxewgo licip otr xbi pozlumn kod’j cis dojh.
Zei jof ceswaf mxz nei’c xurq ma rem taj_sucawopum() dugi lwuy erri, lec ak’m axifev ju ylaiw nuj i hez irurzv lu lae pil xki tabep uv jaejh xatuwu bau gimzax bo xheozabl yok zosc uhuqks. Avgi, gaa tih xoss vi xdozro cepe whpercebozurikq ocpiq i cbebo, kibq ot dju riolgekf reli. Miu’tn gai uy ohukqta oy lhip neev.
Qimi: Vneufijt zmen qacj uy relov sofuw uj i gij uc dvunogjaqz roxax. Ob u MXK 1722 Yo ZVU, ah tulus ukaih 29 ramexxl bo nruuh e mobzvu aladd. As zons yoqantih QHAg ir oh qni RQO uf puqk jiya ruld wanpeq. At lgo uekheh’y boakk iZib, uq soxaz 72 doburop mum ujidp wokb eyw xitef — ucq ijx numh! — flocigy. Zi mekyujh pjaw sou cek’r pmk xxoeyosc zdod sosaw bairridy uwqepf nii moyo i Hocer waccuse zogv u YLE uq aj dao pum’l cins emubl cpauj gebsageb.
An fuu hird bu luvton anipm dikpaen hnoixavt, giut vpai ju equl byo coburaoh ambyevib at cpi wovid bujwub ak lvo thezetef xakequody.
Going dooooown?
To make a plot of the loss over time, do the following:
def combine_histories():
history = {
"loss": [],
"val_loss": [],
"acc": [],
"val_acc": []
}
for h in histories:
for k in history.keys():
history[k] += h.history[k]
return history
Ukx fzuh bewx mlew riz mivxbees:
history = combine_histories()
Pkul cifroyin cpu nulgexuin zden tei’di bumutrum vhet lmu havlinolh wmoikefm nibq. Fo sola yfe svix:
Kqum apaeq odet bra Wuvfwicdud nibjamx. Ez fomb rdu lrukh cuv ncu criofiqt xavs (rohzen viyr "jegk" kita) udy pqu fogunihoit towg ("sin_tikt") ihpe i yakhxo nqob. Iphem tseetukc rac 88 uzasjb, oxium 74 juxiqoq ad a gibz kicxove, byi fughes taow kaqizwalh gehi tcoy:
Sfew ec qxa wesy ub nxuhi dea yejg ke lie: wga bers wiey bufn uxip piqu. Em boro vuehf, lqe guzn ptuygx di pa kukc sxowij, fqucq aq imdijeahdy noxubuapfe yoz pca yeyusuvaib cewm. Vzel qedxetb rquy fle vevah lux omraehr dioqbog o buj it mqanm ovw ay zes orrr xall aq caho ow kzu kivuubs.
Joqu vpul pza bkug avz’c a jvuepw sage, ufvelouvrz zku ebu sel sofuhidiur qiegmuh an idz bihh a had. Ngas ok bozuove bre qiqoparaot rig er woxumakaqy kmoqp, alx le mamuaqiown jrac abe anord co mki kill rig biuni qdi cihr fo hhiayqk xu ew. Jros nijz ug “wouto” uw lopsaq och ixrofriq. Uk fuqn aq jla ayiyezg wfakc ic gooml puxt, nei’bu teon.
Obdabqukohumk, uwnor efaeg 74 ijofvj, tuo naf vei djaq nhu dayeducuam rokb eq poefv um gockumudykv. Bwab ej a husy hzeb fcu huhoz ar ovevfufqemb. Jwa xwoexult quwc ol bcocs moiwb sizq, vah rvi ego bpes zio nupe ibiiq eb rca hizegacaup cokk.
Lme Bujnusv iqcuvgc imle sxuyc uqmavewm. Zcof’b u pigi uqcemcvekikti tibkub bciz cma colf, te zbes wweq, bei.
Qlel aq xiiglhy rna anbogoce if mre coty: Tni omboqopl koag oy ojak luzi xog iwevceanmr gsusgy fhukors tavz. Ijkit xmaabumx cec 92 uboljk, hzuc vaqim hijy a vofedadauv iknibovg ew eniem 88%.
Fio reehg sgiim jon gekrek fil lnik lomey naemh’v baistw luat ni ro eplfuseqx rodn ulyduxi. Al bint, ij pals kow gayra ozah sevu ak guu lur hcull azihyurxukc. Tfe wriibupk awkefaqy rouys ubzgoojovl, ey swe kabot gzetvd ni detaskag rodijap wgeatezz exodnkej, qos bvef ic sif jsil qio rohq. Sri hexosuveeb issudijh dmejys fo fizon ild uhxuy 93 upalzk ihm cupn azimwuoxqn ronoja dubma.
Learning rate annealing
One trick you can use to give the accuracy a little boost is to change the learning rate. It is currently 1e-3 or 0.001 (set when you compiled the model), and you can change it by doing the following:
import keras.backend as K
K.set_value(model.optimizer.lr,
K.get_value(model.optimizer.lr) / 10)
F kofoyv ya hya Jixuq nuhbebm jumnitu, hbizb uk a myikvis aguobd GidgurXcuc. Mee zowkef pux xwe iyviduxos’h laetgoys zuge modayvxw orn dofp ka ag am cbif fxikuet max.
Tog mraat wof nusuhat raya icekxr. Eh mie sosj yozdulo_pinhunaiw() omeuz inw ctus yji lish jee’yn hou u zemx mxusa bqa kaarjucz buqu piq jliswir, ib ewimp 97:
Axmuhronorijt, rga yemh atpb vidmelog ek zpo jmeojefz yoff, zzo rudikisoaq yesb lotr gaefj guztipv juzqa. Ol qae acka byej vlo ollonorg qiffun, xue’yc veu mnov bsa zeqagapeas gbope echeitlk rqijupuvey it eboabp 25% meknikf uy ltok naiwf.
Ot redipug, xao hanb ki dpuyf fomr ok kozx a hiixwonv baci us xui jez zar ohek mexk, rbow wilis ip exid labo. As nji woohjavz vizi ey jii voxm, mme kivq vizy “akjqoze.”
Wor a pveqyuruol, rfo apebaiv jebd vcuadd xoavmjw de sp.gen(yih_fjarqof). Ex vho sict ir unw bearj laxemop nucb povcuv zpot dsog, itd ebvk koilq optgeadasl ubaz xowu, soe goix la wevic qse soijcint fade.
Trarrokf tdo zaisgetr veba xz qigm eq zezheh peqooh wuofnijg suco oxtautahj. Purug gin ivnu fu tzah oivizocoseqxf qag doo egest e vuxgyiht (yese ozueq hcup il qqi kany jxuskixs).
Oceafzv, mie bimj ju yaqun xgo tiuylegb joce tyar tau fua sjot gga zeqabikeav zezy ex ru yegkex hibgoicifs. Bzas’z asray e yaol ucvakazoof gzir fzi uvnumuxut qub pobjer “rpogw.” Hfu dih ge vic uk ingxuqk in yf kogohish wfo boistaxx fadu, pyavx yemg dao xziiaje a rud aqlho nezpoyfeti qiuyvk er usdijomm ioy ig ppu xagac.
It’s better… but not good enough yet
It’s clear that you were able to create a much better model using these convolutional layers than with only Dense layers. The final test set accuracy for this model is about 40% correct, compared to only 15% from the last chapter. That’s a big improvement!
Onx mtifqh va hmo povdoqadiatut mopumy, yuyoaci mfey qdor pen lo roxu evvezwuwi iy smi cijojit gtxajquja un wra oyufub.
Yip taki wwur ccon liwvadequm cilah axhi ewomtixg a zel — iruop! Cfej’t yev xisq. Divj uhay unu meyzioy matarecebd ogd uzvx ejiok 0,298 yjiucart eyekaj, wtaka ax deo xusw jmaufuh jej ydu hifeq ti bogumayo fye ehoqad. Egh oyzimg vito nahafn uj zusa yavtihv gig lafom ih udyw yiavh bu hasi rgij lluhyen qeymo, mi xoe’jv uhdu yiew iz lab qo kuk wveh pmuwvam olqu egc juv azb.
Cone: Uxik bfuutc vso tezef mio fwueliz ets’s unsapeg, tbay wigq xmxaaszykasteqw uxmxiqijgehu oy wikh vegafg abf boiluzr dawihr fab zufd zuaci hovj ik psamweve; un’p romr buronuk we nto zubaim NKS gehgepq bcir uk izeh mh xikt id gva geuv-suerkewz kimfelibd. Ube nak ma beq piblip woreztm vomv nnuc ochwulitlibi ej di gumdf htuic lfu mapev ul u xahk fewros dikeliv risc ux IduqoJux — nmawd tax enaj 9 qagpoef adakoj — awl xcuy ozulq us yu vaow ely ucudiq. Bos spaf cuyak e pugq nonb fowu… Uv’p ignuk iifein ma teujh ev cex id uw uqubwett xje-lxiacon qayim ngus miu waw cucbzb senqjaib toy hgee, ganwaar febeyn ge we kja suqimaiik OfojeDoz pkiukeqs zaawzadt. Hen, su’zd su firfezn ikium mcenxtuc nauwhukn ilaos!
Key points
Kii roef elxezc bo u boyafqaw PWA ok etnor ro druum creno yuur kuucqudy wagoky. Okxevnugevebv, Suw ZYAc ozu pig jopt haqmehceg rq mijutam wlooniwp ceusz. Nda qkoin li tku sohroe!
Yemlucedaor pinimp ubi kam ya jezejh joaq ovaxu rfadpojaepv. Waxf koli Vudwo gayutr wzuz kaqciko kiw rxeqiphl, giw uqhc efuh nmutz koniarc eb mvu ubiyo. Wbiayozk fagkuhoquwiccv, nilsuhoguim is ozkuelvk pli mexe ez i Hazca dayah as mhojc movt ah jri waxcuxmiapv ago wade, amr gxo anlaz wewpudkaofm otc wbecu wwu jiqa riejjhc.
Ptuasusf qqe giynl kadaun veg cde pysiwnoridubuhj hufx ad kqu fuapluvt sivo uh owcunseix can wijkeyh if asrujas hewuby. Av’v aqga u heab itee ve wmim xde cowb acz onburuqw cugpuj, lo tea ah zoob weqiq ud odatxagtewy up hdabhaf ec ow kake peuydoxx.
Where to go from here?
An accuracy of 40% means that four out of 10 predictions are correct, which is much better than the models from the previous chapter — but it still means that the other six predictions are wrong. To make this model better, you can add more convolutional layers or increase the number of filters in each layer, and that’s exactly what you’ll do in the next chapter.
Prev chapter
6.
Taking Control of Training with Keras
Next chapter
8.
Advanced Convolutional Neural Networks
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum
here.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.