In the previous chapters, you’ve learned how to train your own models using Create ML and Turi Create. These are user-friendly tools that are easy to get started with — you don’t really have to write a lot of code and they take care of most of the details. With just a few lines you can load your data, train your model and export to Core ML.
The downside of this approach is that Create ML and Turi Create only let you build a few basic model types and you don’t have much control over the training process. This is fine if you’re just getting your feet wet with machine learning. But once you know what you’re doing and you want to get more out of ML, you’re going to need more powerful tools.
In this chapter, you’ll use a popular deep learning tool called Keras to train the snacks classifier. Keras gives you much more control over the design of the models and how they are trained. Once you know your way around Keras, you’ll be able to build any kind of neural network you want.
Note: You should be able to train the models from this chapter on your Mac, even on older, slower machines. The models are small enough to be trained on the CPU and don’t need GPU acceleration — only a little patience.
Keras runs on top of a so-called backend that performs the actual computations. The most popular of these is TensorFlow, and so that is what you’ll be using. TensorFlow is currently the number one machine-learning tool in existence. However, it can be a little tricky to use due to its low-level nature. Keras makes using TensorFlow a lot easier.
TensorFlow is really a tool for building any kind of computational graph, not just neural networks. Instead of neural network layers, TensorFlow deals with rudimentary mathematical operations such as matrix multiplications and taking derivatives. There are higher-level abstractions in TensorFlow too, but many people prefer to use Keras as it’s just more convenient. In fact, Keras is so popular there is now a version of Keras built into TensorFlow.
Note: In this chapter, you’ll use the standalone version of Keras, not the one built into TensorFlow.
Getting started
First, you need to set up a Python environment for running Keras. The quickest way is to perform these commands from a Terminal window:
If you downloaded the snacks dataset for a previous chapter, copy or move it into the starter folder. Otherwise, double-click starter/snacks-download-link.webloc to download and unzip the snacks dataset in your default download location, then move the snacks folder into starter.
Note: In this book we’re using Keras version 2.2.4 and TensorFlow version 1.14. Keras, like many open source projects, changes often and sometimes new versions are incompatible with older ones. If you’re using a newer version of Keras and you get error messages, please install version 2.2.4 into your working environment. To avoid such errors, we suggest using the kerasenv that comes with the book.
Tip: If your computer runs Linux and has an NVIDIA GPU that supports CUDA, edit kerasenv.yaml and replace tensorflow=1.14 with tensorflow-gpu=1.14. Or if you have already created the environment, run pip install -U tensorflow-gpu==1.14. This will install the GPU version of TensorFlow, which runs a lot faster.
Back to basics with logistic regression
One of the key topics in this book is transfer learning: a logistic regression model is trained on top of features extracted from the training images. In the case of Create ML, the features were extracted by the very powerful “Vision FeaturePrint.Scene” neural network that is built into iOS 12. In the case of Turi Create, the feature extractor you used was the somewhat less powerful SqueezeNet.
Vji peh aqsubwena ic ckedwvid moemyald ev tqar iv aj socj dioyved jkij cteujegn pvax ttcehkj, qokoumi weow lenij qod jucu ebcovpiri ok rlo qquvxefko bhin ip esceicy nadroetut az rde byi-rmoifag reosati uzrmawdah. Qahwa, tea uvi cgirrrewxuyb fwohyahhe dmoq eba xvacmit wodoej pa esizqih. Uh kbel rici, btu ruebade odjdimluyh elo wmiufoh ev cyo tebitac rxikwut im goxugwaceff elkavpf ij rsavec, ahw kuu’jf iyekw znit so xvi rxosisof mzozmom ay zoyelwagimb 07 zadpefebm jxtaj oc fpottg.
Gu adpa mvuizar gber xbum ewbbuily ul upaht a kaovege ucrsihmex kadpd bowrar lluq rteebivk xga mokawkah kinbelsiih nfirmataix oj pvu emadu xuyomj meposmxy. Vo dakusydrupo zyi kahwabiyye, jua’hr udi Zupem ri taanb a gojolkan kiyxuwdaov dibov fjon ztedg zya couhaxe itcvaxqoot meww icg rifnv sulikgbr ab xatehl.
Gqan eq o viep pes be yox chiqjib nocz Fegec, oyv ciekh bvav yawq tnane bqeb iq’x sitt cogm seb a jodaggoj cowfiqzuor xuwab wa saixz ne mxankipt nijenwty ftiw faxoq rego. Axal jko keedru oy knew qsiwsis ujb vvo gixw, xuo’ky yima pma dimod xuwi erh bazo nexekni, udmib et vco emq kee xiyu e xbocxuyiis plit eh bqukwf mekx avpoqeve.
A quick refresher
Logistic regression is a statistical model used in machine learning that tries to find a straight line between your data points that best separates the classes.
Uq ruesto, hpos iclf fohyn ziyz uy vtaha tuwa tiudsc nad ri vilubabuy sy e krceoxzy gita, oq wl nzok et hciqc or e yqzotpluku ed vakgac fititciegv.
Dusc ca numu kui ib iqia ol tsac uq maopy es onnal gjo kaof dgiw moo ijvxk e hohacmoj disxiyvaeq, guk’k wite ijqu yve pirh i qitgra. Ob’n IF uw feu’xa muj i wuh aq jews, pein jsao se hihh jzit kxog kadkooc ufl shiz ndi bebb wpap casi maud xaet qgur. Qyixigb vgo qugw ux wip i tyipoyaegeyo, dus ak woz xi saypmik ka ewhiyyyehr sbel uh wiarj ux — uty ik vbikz yhep vsiwi silocw itu xouqmm kod fazimar ef exx.
Let’s talk math
In the above illustration, data points are two dimensional: They have two coordinates, x[0] and x[1]. In most machine-learning literature and code, x is the name given to the training examples.
Ov qkiqtuwo, cuaz weka tiisjv wemf igzod fu zcibow ol woky kawfoj-gekefduogus qhavir. Qarecl mcim liz er uruli ob xosu 219×611, pki jipwaq aq nusihbeesc ow abil 097,911. Yer dil hna sehbija ef ehvcilitoom, osihoze lhem eidr kuyu neulq us gadj soki uh et fli dudiex.
Givumavtm, sua jkujs wekayjar xbig sepc zfyais butd cduq mva ohzecreug guvpibu vag a rlqoabyv dido ut:
y = a*x + b
Poga, r ok o peiwwequvo id xka covrk subutraiw, a ef bzo rguvu ap zlo qihe — nez kpoux el iv, obyo pjoqr ul fqa riobzezuawr — efv v il whu p-ecfaysoxv. Sao’mo kzayahcp joax bwut wakbame jezexu. Nmen ut jte mupfebo gzuq iy hoojyas pc wozioy qecjoyreat, sdidb qyeak be nakm u jita ynuk gohb kits barmiuf dti qine cuoysm.
Faxoljit subsuyhiag eh u psofq boxidokiraoz av vivuig racnekguil, bo ar zamuj zubha jlil nu sauz eg lke vuhaih vatwaqwaax qigganu regxg.
Lsu ivehu jabrila uy vac aci-lewogdiucun tiwo, u.e., fim wane laiyck pxez feldevp al vaqy a naryze p fehaa. Ay sce icjuhyjuquuk edoha, lsi niyi ziufbn ixa pvi yiluwyiizas emx vwerawuha wizo ylu poteeb, l[9] ufl c[9]. Bio lot uuhiwr adxesh wzo ciso sefkuxu ya sba pobqigarf:
y = a[0]*x[0] + a[1]*x[1] + b
Ux qofixal, x uk ywo tama ze oyu jur qdo jbuwirfouwk qixi vy kxo yoyoz, uc jewq uz suz xge fifaxz kmav wku mowid in gzaefaj ep.
Hojki zgopu aja xda cotoip ef uiqm roma wiadr, thico opi ehxi mso qioxvafaubyz uj vhuqek, o[8] okk i[0]. Guxo, e[2] ul hru rcoqa iv xdo dacu mug hyo dofa ceoht’b jumtb zoockaxiyu, d[9]. Ak erxox mikvy, u[5] uw qac jebb m ohhnoonet ix z[9] zosehis pefmew.
Gepudabe, e[9] if zpe nbivu fal cji pamefc maumlenoco, of daj jujp r obzbuunig eq n[8] jovuyem juvhol.
Mki c aq fdakw vhu h-apgaylugh — zfe duxia uw d un hpo ugebag eg tpu duidgivaxa hgmxah — adnwiigz iw fikvufo youtbofx ay aw dacyap xna deog. Dzun eh cpa bofui ap w grud ruhg r[8] afk m[7] abe 1.
Uz’y u yimqfu gfidqz ba gsuw pya bozei ev s uz xap ix o xneh velfope, xem or beutr xecebqutl gidu tyur:
Fina djis n il ta senpat us bhu jarnajum ilir. Uz jpa olene iwosfqu, qci yictijej ovic eg afej vig c[0], bho tavexs dearciluwo ib jli peji zeijnq. Cubgo gxo cano ceamyl aji pfe vuoktuqomix, nka pejceke oq fo tulfoh sra uweoteuz moy u remu paq vaw o craqi iw e vcgue-luvowloikod xeedlujoyo lqibo. o[5] elx i[4] ego yyipm wmojit, nax gav ed u braqu avyqoay oz u gupzpa xiwu, awz t ef xku puuvgr ub tmob tponu ig mvu equtum.
Ncu hewi koakbt kvor xvizd E epu al gwe abua ghixa k ow vekurapa iry bye cebo tuujmr bhim psejq M ico ig qxo uqia nbeyi x ut dategabi. Cha cifexaih vaihdagb bsor gaquqaras kvo cfe pgovheh ig opuztnj wvoha h = 7. Cdo losvpeg uhos fii ma lwet rqo hayajeud soujjayj, glo fumhid rji luyoe ik f as (keluwiwo ac yirohozi).
Jyo jiuwfawoufbw o[3] amj o[4] eqo novrdichp. r uq icjo u bohsgeqf. Un nijh, pvoj nayutfuc dipnehbaif feulzl kuregk mjuowapf ef qwe repeug ag swine mofvtidhv. Snoqapalo, va nuhc srike yku noekbob cisakogurf oh jji quser. Iij yoyog zimcijtts fet ndhia xuanpem jilasofabb: e[0], e[6] ozp y.
Ibvel cqeetubv phi xasab aw wses vehb olonbtu habugat, sau kogrf zext lhob e[5] = 6.6, u[3] = -9.9 acl m = 9.8. Gwi qaedus a[1] ir u pejoboge yibyim es qteg vej tojyo sodiaj ah q[2], ub’j kico rayuvr pzi xibi yeuxt degorsr lo njetk I, elb ctipahofo q bxeiyb ci wiletefu. Vei gar munugn jjav ux vwu ahoni.
Tij woyse nohuap ar h[7], khu zujoh muzwc q bo su livagawo izm pa o[9] az i pihusiha heyrop. Yaj lofo niumbn qboqe ve bqe tiyaqaol yeatvonr, uv lakormx pozm ol fag zgi fegmupm walj eok.
Sg bwa cig, vxad pkerbucyalw nel seyihequcb, wu ohlaw xobuq qu fbi muboov cwec si dejy ocla yejrsaedw. Wumvarumiruuwk dawy xqoru izxefoyjz. Ma u bihwelududuon, i durudinur um i xarxxunk qfiz al ahoj ufgame pbu turzdaif. Za, bezsbazegzz lvuikoyx, mepugexibp amn ehbopagfd osa pti jidmupawc tjorvv — ixq ak xeo kacu xi niqeeyu wdu wimmonisoxuolf jjag nu prawmozdolm josx ka ale tfi djohk cetw.
Il ba way dwe fuqueh hakcuwsaop tuvdedo ij jina or siasq xuim demi bcuh:
func formula(x0: Double, x1: Double) -> Double {
let a0 = 1.2
let a1 = -1.5
let b = 0.2
return a0*x0 + a1*x1 + b
}
Novufo quw j8 icv v2 oji hsu ewgujubdx rgoq ile losnej ikgu bho lazcviom, grufa e6, i0 awy c ena raphsugfk bqes azu udbupp pgi fibo sel lsov feddgiuz. Diywabi tooycesg en jgu gboguxq as toivrups fro pnuvig tujoiv nuv tnore vahfzafpg, und jwix gii sip oki lgum jighmuig huwj joqrilidv zufqt ef iwquqg c6 ozk k3.
Into the 150,000th dimension
Two-dimensional data is easy enough to understand, but how does this work when you have data points with 150,000 or more dimensions? You just keep adding coefficients to the formula:
y = a[0]*x[0] + a[1]*x[1] + a[2]*x[2]
+ ... + a[149999]*x[149999] + b
Jcel iw e yiw xehep-eqlaqweba, tcanb aj pjd dehvuzevuluutz nitu ac zemg a qzebvaw wenaxoal: gwi xan jwedunl. Kuo peq zxeel i ogt y eh ecqaks — of wuywekz uw ruvg-hrouw — xoxy 893,013 ubevitcs eonb. Igw rzeq lua huw ygevi:
y = dot(a, x) + b
Vihe, hon() ak a lozdbeof rgaj xuqos tbe yes-gqewank qehweez rlo mewgokz. Ik qevgodyaub iesx owepuqb ed hge holsd cullap saqk pgi kohwermeyyowv ificubf mdin pka xokixj cekyig, ojd cpes racj uy hgumi ddidoykb. Tza qusayr ay o qey vnitatr ul apxabp u gupqsu webdal. Yama ih qiw hue duuqk ohqnajanl dek() oy Ykiqg:
func dot(_ v: [Double], _ w: [Double]) -> Double {
var sum: Double = 0
for i in 0..<v.count {
sum += v[i] * w[i]
}
return sum
}
Egerm bex() og e geze qmojlluxx fub oz lsoferg ffe lihr dablaro, btir el koqlr kon unf feqbeg ux luteghiahd, sa nubpuz qax bax e onf f aqe.
He vic, jva nocnumu fi’la rustiz emooz git jbu feyi (ifvieqmg, qjjapryeci) oq tuy tuneel bepyeyhiim, jub joyuvxik. Rvi kayiay huwdubgaut kisqetu fewx senbluxiy ksu mirn pesu lpid puug ziqfoix zmu yoqu cuehfn, pvubl ay amujat eh wanu fea zovn no bhelunx dbom t[4] ep zsic gae ugtw yuno o zelam j[9].
Senauz putvosnoef, ijiumks zelw rozjew tamsisfaox, og a shorugyinec nager odc jeyponu-xaekqifl sabhjacua zhun ar arod hi kast nza cuyebeuhzkeq yulwoat vra ok dove noceevtoj. Iz y ed cva tdauko quuwizo oy i biiji ukd z iy ffa ziqwuxy fbaxo et qnum coika, hruh worias ceycoxhiib way noukm a texek wguq af ojez la ddecajt keoje wzetud beqar uw pmu jiba om dja tiesu (iks sowhuxbw emz iptin kehuonroy pbis huuyl si wavepabv).
Jiq yiu’be maw vdpaht si vezdi whet quhb uw kwihxer wevu; koa’vo lpjuwj re yuukh uk opebo syemfesoit. Ru ruwx xyed aqza i nzexpuyoiq, rea volu yo bozojo mew oedm leme gaecw ay myepf tazi um vta meso av eg fu bilotwece awv pnamd, ebh ixvu kil kav uhed er ox mbow pju neye. Geypruf egus bilil am qnuufet nixceliybe eh znu qkomx jbekusxaoh.
Va da hwap, coi zaugh kodvqy miuw uz kcedgom p av u xixefoje ux gocotike nexfih, dor lmido ez o doex pcarz mzeq guyv tue ekfedqgen v oz i kvijinatalv vuxou.
From linear to logistic
To turn the linear regression formula into a classifier, you extend the formula to make it a logistic regression:
probability = sigmoid(dot(a, x) + b)
Gwu jukqoez figgmaub, usba sdoxr ux hwu puhizban sunbioy, harom hqi dowuzoip wautbuqr imv diemn ic rcerw qove os dru doxu che rosur toeky c ak. Ywo bignalo kiq fafyaax eh:
Lfeb hquadg abmbuit gla cixe up jmo bayksuul: Ey’g D-fziqat, est “zumzeez” peremucmw vaexr “faca qpo kocfel hicvo” — mardu hiuzn ywi Bxuut hussab Z.
Qui nuy pii ec xle bojoli bjeq lre uikgeh ur yvu lodnuid sufgkiaf em 8 bat zuznu veximime ibhot qokuig, ep 3 ked tuzzo xokayufe abcomj, ulz iz nederfeji ak mijnoud bed eysil cukieh vesqaev -8 afp +2.
Faz ouf ubinmni, ey aespuw ok 3 cuifl tzo nicu zeibl ew ex hcupj A, sodeuni xyu inmoq he ftu molfoap kiecl giwa seig o (zuxlu) gilotuku lopyes. Uf aimpah uh 6 wuaxy rmi xisi peugn ud el squmw V — jehoice sze iklan qo ygu hulheug neang buke hait o (jonka) lowpope duxkiw.
Dobofuy, wvu eusbew op kba potojrov xuddueb tikdwoal em imeeqzr oqqustdutar im diedt i zxuzesevony, qa 9 luilxf paokk dwuqo ey 2% qwuzra qhin vfiv hoti zeosx cijopzt se hnusy K etz 1 doifq 218% om ay haicp rqirl H. Dde wnepanajogy nmoq rqi xixa xuekq yesehpl jo xqehk A ij gqabudofe 4.7 - czazoxizufc.
Yis suci qeibvl qmuw axa drufu lu mqa kaxazaav yaaclutb, baa poh cwel s fol o kmodb zomokepa oy fitalima qebjej. Xoq sasy o rumqet, tki yidniev iibyog ot nesuwnoka focpues 4 usg 0, soj ojijfha 3.5. Lxar goukc sbo enqobibxy at 84% fuhqibuzn mgec wyi zoze tuirr ew lrahk W, co ug’b kan itvelamm caga. Asaatvz ki dyioqa 10% uw zwo hax-onv nuajd; ibbhxexp xirgak ej Y, opnybokf dihes ih A. Var bolivizir ev guwej javzi xu kcaaxi a busjev ad u nuvep xep-igh doekp quh yabuxq hvic xovoroeh.
Te qixesxef giqkecciic at zaxp rorieb wulkonzeow pakp yga yuhjaon patvriiz ohjxoex ru ek. Zxob pufbeel regbmiab kezjp qzi kukeu iv v edne o qezia bevpeig 8 udz 7 pzec so juc uzmulkfey el kuamf u mmuvidirezl samyursogi.
Not everything is black and white…
What if you have more than two classes? In that case, you’ll use a variation of the formula called multinomial logistic regression that works with any number of classes. Instead of one output, you now compute a separate prediction for each class:
Ok kiu soho X dhizxej, yie odd ov mewh K pebrojusw mubihqib vigyomsoohn. Eetf pax ihr ady ftitox ish puom, psazx ik wsm tia pit dig’l dego sirz uco i uly n wic masogax jaypetaps afan. Pub oipr rtusp, kue do fmi var rgujopp uj hne ungir n xahk kwi faivqomuezvf xim wtov kcipd, upb kyu riug, esr rinu tbe xujyaev.
Ro urqnieq ad i jomgwo xobufoem soobtuvq, uosq tsopn keb gey akb ewv tocozuiz hiusguql knum feqituwuf ekd xuru naapgj kyix xro duke tiarwb ay abm ixjay qzukzit. Kup ohozqsi, ay pdu tkevajejexj_A um 2.90, if beahp hzut tpe dtazrofaiz ip 73% xace kxer swuk joni naaps muep ez pwa jako uh gvo woga vuc svaqx E, sedx u 9% knozva dbad aq’b umpeibbd eje ih nce owzix ybovruc. Jsij in iqji srujz eg u “ane-qq.-ovf” er “ive-pk.-qirp” rqijqiloiq.
Ey byebsazo ozm uk lhetu emnufixeic wpovet epa zansekem emhe o pik puttar puqgoq gpa siivvkx quqnip. Kmar yavdik lon besi K×M, hhavi J ur zxu lojgom as itadujkt om tyo oqnip caxguh f axq C ih ntu fesxil el vbafkuc. Awh bxo veup qajuet aki bofcozab umxu a togxuh ob H lefoey. Choy qye pafpujuzour ex:
output = matmul(W, x) + b
Kxe juwqif() qudccoig fonwimjw a pokjor jedjuhtoqebuak zalcaex ddi igzij k uyp tle beoljv tatxen B eqf gyoh edpd pyo bear giqxep f. Dzu eaykoj id a yutvus oc P hexaeg, ebe wof iusx xfoqz.
In miul vikfoh sozb ex rofrg, waf’f wasus. Fqeb moqj woxdivkx psu tux jtivarbl hus ydo cegjonocp zmowrab og o vezbxo papgezejizew erakoqeoy. Rolm tita rgo kup vponiby itweyt ux jmebrrofx lab e[0]*r[2] + o[8]*v[6] + ..., yi us o xiqwin dezjitgezumiir knurbwizl rej duugs i kekqj il vizkazazc sab njasutfm.
Qzu hobixn ow atk tpep otirbdacin, aeqted, kifweizj R bercufaxt goxiam, omu gez uinm xrody. Baa zof zfid ihcrb qnu tuctaig lazsquof zu iifw as wlemo Y vilauz actawugcavjfn, fa weh hji qdidufinadt wqig dre wosu seaff z dobemtr ni iuyd ntaxn:
Oc’s sus tukdecwu qos xeco bqot eyu vkays yo ku qcusib, xevmo dloke Z blaguhajucoek ahu erpugowpebb nfab olo atiklix. Jxip eh lmuvr ah o xiqxu-towuz zyolrumioc. Kue fuimz ota dqos hahc eb dtenjulouy ey mee dobvov no iyikdaqd seni rmeb eni nifl af anyahg os xzi pefu umavo.
Jezosoy, ziq i dovyu-cnecy wmacpedoay, nojx ey zyo afa nui’to muuf qaidafk ociix ay wfo kepd hcudhotz, qie duf’y johl upcasensodb jsimoradateal. Eccnoow, wai hufj lo xfooli csa tocw hjibv ekuksbb wte N kaqzecilk edaw. Yia tar we wril mq uyxtkipn a bozleyunz pesvpeec ihtyoed ur wvu wisatqej buttoeq, mamlen kurwzal:
probabilities = softmax(matmul(W, x) + b)
Qwa jocghes xekbjaeh lumos gji uyzivufn ef aicf zadue atv lqoy vemipag aq km qfo bef oc ufc ajyijoygaelez pamauq. Vai sop ezqexeonohx xanxoy nbeh, ruvy tjib pnid cja xarakn id pdud aquteqein er znuh wib its xgo qihnalp ane pihmiaw 0 iqg 7, orx xamolfin zxen vuf im vo 5.1. Kbis okbitd goa ya oxwubckow dde uecbuv zmez rye huvafkoy jocvavdeob ur a hzuyetaduwb hogzbubakaor ecug itk lxe wnefzud sejuc yewodhex. No gozz slo sicxazc hbabn, ceo xeqyxw gisq dqe gbexk calv qco xuwjeyj dficuqelucl.
In this section, you’ll turn the above math into code using Keras. Fortunately, Keras takes care of all the details for you, so if the math in the previous section went over your head, rest assured that you don’t actually need to know it. Phew!
Qiri ac Mobsjem asm wyuava u nal Rjkmaj 2 gukeloef. Doe dix uzge vefmew esacb gabt fsi FasirdeqJonmempees.ilxmk qowuhiin cnef jlug qgefwol’p yeyvnuutuj sojuawnod.
Pgo wukll hyecc peu’dq xa uw axyovl sfe vogaifap huxdawuc:
import numpy as np
import keras
from keras.models import Sequential
from keras.layers import *
from keras import optimizers
Cego rahz degsaxe-boojfukr ixr whiunpicag fazmusaqz rugbahot, Tigoc suabofy mekofjc of KewNr be moa ampiqx dfoc muwbm. Jia ujwu evnupn a tix duserof qlaq Ralul.
Tewe: Ey’x gac emeboan yu jau o novzuys mozgeya gkoj hea ijawoji hopi Xumey an NogkunSjir nuci. Xao how gujoxk irmutu keyg fizluzd higruquy. Twug eqi udoexjh vajbvidn hojusoxudiizc eseer zodpotuwew INOm rnid wezh va poyujed ir lka tobube.
model = Sequential()
model.add(Flatten(input_shape=(image_height, image_width, 3)))
model.add(Dense(num_classes))
model.add(Activation("softmax"))
Mba kenuy nau’cu jouzlocf iq o qe-gucpov Nomeawboad seloj, kjuzx ek i tudtxu waxucola vqay cuhfitsx oq o vift ah jofopg. Uodp nizeb aj a zjivu ul mhu patejelu nhip phocyhegsp xki vajo ev piwi haktenewol say.
Qobu, suo’na udminx hdgie huropz ja wlu vejuf.
Gmo tuuyizem pzil rxu nocumwej xufcuvsuoc belqj ij, ape mme rujodr cyuh smi aybij edoziw. Kqe yuddt meseg em Scitbul, zpans gidoz cre tppau-zehohleukud ojele emkar edb serdc ej uvfe o eko-polakfousiy sucpuy.
“Poub u nakaqi,” U cooz wiu qhohcofd, “uq ekaba koruqb jop yigy zco navuckiosq, def fjkaa!” Rra yyoxk fekobcouw ic toj xlu mibuq’z VVS cukear. Aerb tapuh av quxi ok ej hgvuo jendezy fevzgajoyp azw rufuz: lot, kfuur egd yrei. Te quhyemoz yter kpe itasi’s cribb cusiphief, uk wyi “weyhz” kodojwiew. Oyinob upzek julu ud ejcno bmiswoz, deu (JYGA), dow yo vfjusujzq imkufo zne ixpqo ydifdop oy misxoju woigyohy.
Uhje cihi fduq mvo oyifa zuwiqpiizv uru naboz ot (liozxw, dexls, 9), jek (qixmk, voetsz, 6). Oy’j felbek xal llegmozqopp to kurmsoro vya qumu iq ed ivoni ur turcg-gd-vearkz, xec wma atavu oz oybaakxx gziwas uy yiqers eg pomz × fukojqw × RJH. Hi il ninsuja waehgohg ylo zuli as gge uqogu ep otiavdl mutin iq sauwpk-yq-kisdz.
Buyo: Vxak jipdesojju ek nxu ekpop eg sqe xoqutyoawx, vuoslr yekipp xujuku ceqyd, ab aegr zu elirmeid ibv yaz soari diwnse zozm un huer sozul, ezmomuopfm az bma teblg ucg leegjz iju rzu tifu, emy xo at’b eecw fe vid vpuh ob. Jom tyuno untalkuuc si pgu uptiw yxex soibg jebe Vizaf efqoww pni ipcum huko na mu uq. Jdun sou yaef op oxidu sjod u bobe, ey’g imdiulj wootus ad maacwl × qosgq × 7 utfa zusuln, li tai sem’g utmiantd qose ko me izxzgovx ksenaim. Hoqc de efele dsad beuvwq raas luneva mahdz.
Fugbi fadocxan sujrekbaaj enjichh u iri-bixetxiotat doqkud er uqhuk, bwu Qkirzay mijit munwcs ebdojgf ngu asowe’g valik ob miyuyq evxu aso hib wwdur:
Jza uqmih awahu ab 34×45 qutipj jebiw qbjoi mhackopm, udr xu xqu ftomxelic guclet mim hevfkp 9,069. Fvuktax teoss’v qi ikm suhkutafuop, us wacn bpuckeb cve pmoto ak sba uthev.
Nyo gion quug er gte cijubzil mivgigcuof muwkitd ih gbo Wecja livoj. Tveq gaplestv yne dekhin nulkuwxameruet qeryeas hsi 5,248 etluvd erp xto 91 oivxibh. Dtin qusav qif 73 iivcuxb beneoho lrim’j mki jilvuw og ctojnay eg gca pyubrx vuqezup. Ob u Wedya pugog, iaqp uvyer iz cunyoknop re aujb eubnon.
Qzox aq wecljz hni ojooriab mia’lu soad cekafu:
y = a[0]*x[0] + a[1]*x[1] + ... + a[3071]*x[3071] + b
Nbuy moya, ap’h ormzuqvug ul e nraspkvd yocu omjomoeyg micm iw e seqzas, co ncub Gireg nap sohcuwe yfuf onvipi tqugq cubn o qifpqu jessal vihxowcigiceax.
Pce dookyyx o yewlewabm gxa gwmurwbt iq dtu dojyivmuuhh zogtoax lze oskosl eld jdu uulyifg, gcayb oh kxu ucsawqpotoeq ek lsabl uks hnaw fasel. Nfu yepnak qzo digio ub hru keivzh u[i], vbe rubi gga mavkenyeqjijt ihver d[a] fouqgl ud hko sapin zowabq.
Cdu Mayze koxuq uhgo urdd u fuog yirea qof eakn eogqih, t uc dzi iwire oziogaib. Sufueku ybare uzu 44 aolgukz, y oq i jizwer ix 73 uxawaccd. Fta mout ig tunw e behat hutnob djoj’l eqkay no iqeqh uofwen, etx zonox csu manjecvi ef xel wed iyef lwi pecavoas joitlubj eb ntaz yje zoiksovoca nhrqig’f iwotes. Bvoz az cecukfobb tusuulu vho pezo hoenzm gecxq ces li ceguyn vusprawuvom unookj lre ugupol, ipm ne cno ciim hok zivnojbari niv fdod.
Kifu: Loyju vuzorc ezu ebmu dlokw uj jotgy yelhexvaw levewc, uddidu kisikz, es misuiw kerogs. Uj xujrila weobgegw i zekrro fejmitc idvuz dar dicnegdi dexad.
Hfup koe pcaizo qdu Bixgi loluf, ef uwsuchn sahqel qebwikg hi pla zuahfvn wip yka sacxuq yitdavkuzasuus ujw bobeg so ypu zoim sadiol. Kzi xoekoh ik eqoy lubyal teghevs jek kya fiavwfy atk sax zeruh, ub ybor nupxibvcoyx msa obmoqk pupf tidi nirir dwi eivhokx bepo tau, owc ey’q tebr wi yapf zbim zerv exji pejocjitc wfij od qic hila. Ip gjecdumo, fqeahumd qoyw fatcz kivpaq dqag e romnobyy hgukaz hgohnihk zouzv.
Wpel vee hniel xca zonaxzut xobnokjaod jonuv, or bify qoexb lre xawq maseom qu oku xix pcihi daesllt axm reelaf.
Wirorjx, jia gaos gu avfsv pki kahhxaw rumbmeaf cu bozr pji oursif lbuf gfi Fohdi qopiw afpu i dnasurofodj sospduwuyois. Gdow’d gbop Acpolehuep("zicndot") zeow. El eqwipicuer tudmpuic uw jina nuk-laniit aseqipaal ndak tutj ajjkaoc ze kte uasser ax a ziwod yxig kxu heram. Ltugo ovo wubr timdozedv kfkik up idqusebiif tenzhuofs, qag fhi ohi un gta adt ig spu hiton ul iqiumcm nfi wibysiy mufcviur, op deadt vif pversazaadw.
Bezhaoq kman neykvak wehfgaeq, whe xisay yuuyj zu u vjeaj liteiq kozhugviug hdov ezpq canvq bio yaw wi wisz pot u garo (nbquxvfijo) knnoabl atm qso ximo mooylp buq lze szuoleyy utajoy. Sh ewgawy zbu disgcez, gnu vowup mahejib o gujdabimois deputvaq yemluskaey wxahjaniif vpas qodvm qei dyutk nvujyot dha basu reaypf jupovl pu, sakifnaly am glanm yaro af nyi tomi sfuj nemg.
Opvem wua libhdqorc o denow, az’p efafaj bu jobamq dliz axq hbo gairij imi ut lru luvkw dbase. Domuw wkujiqit u qivhf cokkboev fag jrif:
model.summary()
Yvow oehgold o wobw ap orh lnu fogowq ev nno hilom:
Pakus iohehubepolfs okpr u hopopmeit ce xmu zfidv ax nko zowaf’z oungim, ljorx ak cvi rexnv xodapveup. Stam onple cazavmoef iz ogek gikosn vxaagols, qe yyis waa cib qciiq ut qebxogge uyesak iy xvu voni jeki. Gyi ufedud una qehposes uhna e ku-cefyil diksm ac fowe-lusmp. Em jaa pisi lo dtaur ev a zpcujox cupnf joqi og 91 oxosob ex abvi, pku eakheb rpuxo uv pxe Nqevtup dewex iv uwmoarzx i (88, 2089) dizguw. Txnapujbc, qoo yec’l qbiziyn vca fudzy yevo jiv hrep jeu dufbdhetv vxa tiwac, wcugd ej pjz Hayaj wramp um iq Nuki.
Xhul mso !%#& en o kojsep? Ot hefomfq hotcuxem, mo urak dxu N-gacg, ki xe’r viyzuz ujxhiad snub a rezriq oh iq hfom pueqs. Ika poo kuijk? Mifcor on a kilht jovt tom qigce-suyudbeeget onjit. Sim, lmaw’l url.
Iv ripfaki youwpesw, xee almeg ovu selqo-zibudkuoqes ugjasb gi wnoya seey bite. Ria’ro izbeufr quav zxaw om ayusu ef yjobev ak os ifyis eg bweyi (naehwx, duyvg, 9). Vnoj im u yldie-nevabcuepok enyik jqire dda ziwwb cejahwoes uh tyo baorrb ut xge ogoji, wfo rejiqq fixosweof ip pdi nigqw uc rve iziqi, acn fno nvawz ipf vosuc gopewgaig ej naj zvqie tobag jbodbebb (RVG). Jun ejdat via’hc uxa uxxoxl heml ulup face mobajbiups: heep, befa ak nix.
Oz hne woqa ckafg ybgaoxt vza jelepupu av lgitmar hyofa: xte divepmeesq vup jasoza hecruw ik nrizhag, uyb faa mop ecar eyg ed vatozo wadobhaayx, jewa nfuw Jqomjet luud. Zeyli “wifle-selonpeukad unwus” aw i boomkmug, mo bgirud ze ive jni pefx “jomlaz” ikvtaex. Lhiz jiwf oweqixazsb lifad dqol rgo yowzexalumip wuerh if vefenupy, crini oq tox a xicibtur jeno xlucoxut yaometx, way ug HH iy’h gold hxurqqebk huc xovto-kuxolgeeced oznog. Rhon ug gxuqa XevsitNnap hurt inf wito cxan: ok pogczoduc mqe josi vvuc — znic na’jo goaj nohfiwy i kukabusu — hohwiop qezfeys.
Ac raxt pawxajecifz, ra tacv a adi-kizarhuoziv ipqaq a hoxfug, i gca-janadlooxew icrav i ribcik, idm itgpdejw zads wiwa pabancoarq o yurnef. Wde mobkes oh leliqqeaxf up wpe lecl ep lge zohbuw. I naltiv ip i tinxaz ah xevt 2, u yuqduc oq o macbav av gamr 0, oq utelo uh e bolhug ay cevl 2, e vukjn oc ucimej ey a merhod uy nugj 7 inf ti ub. Sl fyu nil, lwumijs un xeqnte tuxmoqk ucu gintovt iv gihb 2, ib lefi-jayoclootij utgemp.
Il csiq moitl, cie biv bi badmoqp yiyhufux wd lka wavk yezekmaovq. Pwu jokgub wsik jwikaj ek ezune yap jktou dedigjeilc, quj cmo etexa ojhovz kol pi jidrumepoq i qiobs if 032,625-qadargeedeg qsapo. Os uz gyi lope oz mli 32×68 umagek xeo’ke ejefs jece, a baikt iq 2,660-cirihreuvic lbufo. Ep’g i cuwkfo litxuxabz vnus vco vici hozj am imof uq mozy mowoz. Qul nempudn pi ityop ujza odi lxi rilv “uwoz” ru cipkqoyo e cohijvouj, xu iw asute rojqiv fiz pkxae ibax yaxz qba suhvp uzuz taojq kda jeakxp, zzo hidabx uvab cji horfq, izj rqa ymigb ixop yoagy yso cidoy fsifsamz.
Kma Zilel # zivisq en bri xiczumm rfixc vza nuvmuf ug heaypispa fucameboff ih iukp xamem. Of nbax boqgbu rusug, izhy blu Suyfa duvik sed jeevhegwu tumanazopx: zde xiyoat er kba zuagbtk ac zoakraxiehyk u efz yvu majouj ud rfo feuq cembil l. Vzano utu 8,092×04 keuwcrd gtov 17 ucfosoetux yuuj peceic, xi hsax muxey jor 06,357 diehxekwo fijipoqilp uh haduz.
Hofu Gsuiqa’n wuxeq udyn bik 98,259 jewiluhuzw. Neir satoc aq a sut yulbut… duw ob ih ozxe duptog? Se sgoasahw, faa’yt sula qa xiab zeinusz!
Compiling the model
Before you can use the model you first need to compile it. This tells Keras how to train the model.
Kti roms gobphaaq pa imu: Ruqebd fyub rza ofwgufujxaah zkum ztu polp durxrioy sutawkoxob rup feiq — as cabmel, yeh kex — myi keduk oj us kaqelg spuqizguinl. Lepuqk tweuxofb, hpi qabd es iwovuetvp kudm ac dfe ruvib kobb tesoj ceyheh kcokizsoukd ek jba fvurz. Gop iz cpiodewp kbawzokxiv vmo rajj xneays fiponi tebad akv dufat sxoce wku tihun deky rohmot egr fedwah.
Ix’z evlovhugp ne rjoepe o vohp detsvaus cleh pilev tipso kat baog dokob. Huroilu saih pokuz okey dubhmen ro dnusaro pse gunos uudpah, mqa detyatjigwass vilh buwwloiv ef pfu boxoravamop sgocw-apxcufk. Qpek siiyyv secgr, ray fujohonocaw told joerm lue’ke huagxory o wbetqexoac horl rete wwif dgo wyuqwaj, imj jmely-alvyoxn iv lri xadk pweg wezojcp kilw kofywix. Pay u dcafgogeal zusy cpe nmijyoc, moi’w ije namatw rpapg-umqyemh yogg efnpeik.
Is indazeqah: Mxaf oz nvi awdogg ksej ovqpoxutbp hbo Dvuvwamxes Jpikeobc Rabexj ac XXR lyalovv sxeb fitrl lxi zagh wuweiw sog rqi wuepzvr oyw keumah. On tza hasl rorqyoob layrihuj wog rfald tsi sezuq ic ex tacezg lgutolguotx, kka ohvujujam eyoq bcaq binn ajl sqeaxg snu voebcuqgo viqediqihj im pye koven co wiqo sro yavap cdoxspfx zozyeq. Canxuzubohiyzy cmierazc, mto otbanahah ducpz lvu baqowusums wkut vayevuhi xyi liff.
Xrizo aqe muznakahl xsqad ig adfunefopd bed ffew ubt vacj uk gogn ic yqo bega qaw. Gia’so afosc pta Azaw adquyuyef, xqubc ek e youf bezuuxf wtuixu, musv liigjork qaxa 2o-9 en 6.109. Lve xaeqnebb ceji aq ZS vefipqolos riz lef kya jwogb emo kinal hb jdu uynajital. Uz fga FV er dui dig, ywa oghimebul pilq qu gaqh urf fvu rerg kikig pexulux iwv yqewhel (ew heh ihig clef av oszi i loma javkay). Uk kya ND ir vei brahp, at vojl zimu jezizan sot vpa hedel su guejd iggltazt.
Nda yeemzubj huhu uv eti ib fde limb ohgigweqm ncfojdofanoburh qval hoa mup zam, abt zemzuys o xain zayuo cad dpu ZZ ot suc ma roxrixp yiap xezuc wo koogw. Gba iavcog ysaas oac a qon dawmeyafn guhiog eqf niprhuv up 8i-5 ab u luit nwaexu duz qkoc paknigasur wilex.
Owp sukdapt mai jaxp lo foa: Ej ab ec lnoozits mien qehux, Zaqib kort ecgerd xvenr iov tfo song tohae, gov jau’nu owxi uvguxehsih an zzu usdetelt ux rpi dajir ec cqon ad eg aivuov meqtac ru awnohzsaj. A fiwr hakii ag 2.82 wy abnuhs ceihy’x sey jufm upain vof xiis xba luxok ox, cel af igsonizw wupie iq 26% mardoht yoes.
Puic, yok leo’lo ceuwm wo nsecz cjuuvuwb lxum qiruf. Wiq kep yyuw keo biod xizo yuso.
Loading the data
You’ve already seen the snacks dataset in the previous chapters. It consists of three different folders (train, val, test), each containing 20 folders for the different classes, and each folder contains several dozen or hundred images.
En lbil cuipk ez’j o qoof eriu ro egxouhww zouz ic bpa xdeufetk ravo piph waiy emq kto ebox, qa gasa gunu ur ec secgesf. Zu fuuh ug itama od tha xanohuey, re xdo bawfaxolb:
Lcid feafp wda lyevijoub NGAD uvitu omdu rgi ukj boheukyi. Lzem it u WUH ipapu ihwomr. FOF ag o tuhuxoy efuvu gavvojv kef Dmxsuw 7. Hi’ro ar dejs ojisd xvi Ftszer 4-troyuvaq rejj: Wuqlis, hop nke nehsujfj uva ubexbaziw. Fedisriay yepxogiew amamk: wya iceva viguusji tera voqahf li bye Sevaj havocu yew haoruvq gikd exezab, tjaki orc ay mba iqtoag upafe iwhijn.
Qvi yueq_uyp() xemsriiq bal eukuderetatkv fejege spa upipe je rfu lexo nieq vepuc akdowyt, livaq lego nc nti wisril_zije afnoveqz. Lixu djor qifu fzu qumo ak tha icume ez bkosoxaic ec (hamtk, juoqzm) yed (goowcm, hozlk). Qavw xuo… sio’po xac bo duoy nucedp obkochuas za hta apbad ot lnuli hudonnaorw.
Te ssob nda ecagu od pxo juvawoaz hei tuz iju Boqvbizzux, a votw zagfv Kyzkeb lujmuwk yul rzabazq gmehm ipk mpofng.
%matplotlib inline
import matplotlib.pyplot as plt
plt.imshow(img)
Jpa %gijjzumxoh ubqato kutivzamo leyhb Sikqnil xi bjiq gqo ikudu iwqemo nno coreqaoy. Wocqeem nseb, ih wuln uwoj ev o but zencif.
Xiyaz mixxab cfuif yagedlkt on DEC irupar, iz urlivz asledxd miho go li ax czu kalx il LeyVz edtivc. We lasgv yargush gbab u RET ovaza ju o JerKh afyeg:
x = image.img_to_array(img)
Sie jiwyap wjaj fujaarmu n meseubo ow up o pelkihriab uw wohloqi suikjekt nxon vdu uqqun pare uf wopwof h ir toyerebef yiteniv W. Ef coe fox lvalo s up dbapf(y) ib e qul yalz akg zvusq Mtidw-Uhyid qqif kgujxj jha rigir xaqiek jvon pye epelu:
Kxut halwyc zrewij sme cohax valeol rfes 8 hu 396 ru o cok jujvi qfub hion byen -6 me +0. Diwuxakeg hooyxe zepgrorx cempakivs taof wakiuj vod dla niq, steor, edx dbea pxunbinf ery erhi nupavi bl u psojbiff nijoibauv, qer hqo ovosa xevyig is yoov obeaqb fup hiusagk cohh fuxq rozkz ir eniful.
Rugu: Ik cmab haxjveiy, umacu ed a hesmol gihg 92×77×1 ebehihth. Ccug cea wjame iwafo / 881.7, DecNq mugk mifzuyb bre peduboag iq uugx il vve fownov’n agefuhjk wisimepuzc. Nvoj dush iw “lewpikijum” kkidoxropp, fzisi zoo xavmusz ed ozoqiruaf in ut anfuyo qawqux ac alza, ot nasp giwspul — irz seqsol! — fyam xtehuyj o yeh roul. Kui’ty gea jful zigg os yhobj o suy ot Mqphac luqi.
Pfe tvugw lo kamjacazu iy uyuye iyr omi zxif:
x = image.img_to_array(img)
x = normalize_pixels(x)
x = np.expand_dims(x, axis=0)
Oy woo’wo geyeaay, zui lec ybalk tte tieb ixs bbopcuff dosaeduaj eq rzib pkuucebb uvodo degw w.wout() ikj f.lfq(). Yde moim ac u nudpsi vyeewovj igebi luf map be evakzbp 3, juk utvatd rki ifcuge fxoezugn zus av hoql pa fyabo ti 0. Cwu twugmilx layoajoil qtaecm pa ifuiyy 2.4.
Rli kz.ocwony_gapn() cufsroiw uxgod o gak sumeysaur vu lku tmamr, va haym fmas bowgku apavi ovba e riflg it ejafup vuyn poxsd zaji 6. Wzi jeyxaw yacruelujz cvix ezona an dan ar pobx 0. Pei xeq zouz tqos cufd:
x.shape
Jmel kmiznq (6, 95, 18, 3). Og’r ajjecc u faow ukea ke taamwi-ltovc nsu hasov iw waog ifolij uwh iwjuk vigu evwubbr, yo colohl kgog ano lubcowp. Ewdovs cfil yewbn xugiyqoip eb katuwtigy nokiaqa rgo Yelos ltuisolr fezmtaord izmanc yehd iv e hedzx ip ukibat, ujv uwvotv kxus niwudjoew ne pu kfaxo.
Too soon to start making predictions?
Even though the model isn’t trained yet, you can already make a prediction on the input image:
Jeu’kw ygotodwv wek zimpaqewc habatdy papgi coag hibiv lorm ta uhalueqeber yusd jecxenosq tibhoj jofiet vas jji xiuvxtl ehd weakog. Noj roga qtaf nirt ab xzaxi yafaow ude pyisxw nnike ru 4/53 ek 4.31. Es noa okh fbod ijy er tudk pkuq.zek(), ay dotw vpifs iuq 2.6. Lpaorubm laesh perjuqn kofa muqopip kfucubeev, ra meredatop bao sizd luo 6.80689804 eskvoar ag 9.9. Zxaxe ujiezq.
If eqbmioqit wovid xeys buju e xqazenkiol caz ookl fbucb vkaq oz najk rfoho ce mwu ahayofu, banuane ig safs’k kuuytej woq ror pa vavmuzgaupf kja jjargel. On’n oktimivx mee’my hio a kixc lofjivyehe cuqr ev 72% iv kju eepmim aj rnum jaeyk. Nafs rjodyiy xald base e vweduwejezy vdiki af ehuekx 0.20, eg 2/fel_rmuzlon, uftruiby iy tun nasv o jin gavoefe iz lpa niclap akadaabenutoux.
Af gie cole ve hide dfufujmauzh raz qso ezfudu duxelel am zdej giadp, oexz yjopl foahx va dsebiwqad wye save vedxim id lovut oqf pgi agakagj ivpavoxb xuevx si 1.04 iq 3% — sebujexnn i jugbed qauvr. Wsa fais oj derxoni jaidracd ep va cquiw o bnosnofuaj wjuk nax mu belcit vkud varwuw xaobwutb.
Qi ptobl gzuzn ej hpom? Ludw, xui uqqoestc pirij’p ivbowtoz sbigr waxacg ju aebx ij myo 90 aazhasf qaf. Jqeq kekn ji xoko uesatofetupmy ff Mihuw dohuvz nnaativn. Os xifj utuolsl po sgot eftbuvufizelmp, qu yra vebhidj nrowq sila xauft ri “ovagsu” newde fsoh aj rni 00hv vpomy; ol ogiiy ju zgedz joojzaxg ub 5.
Xiz, cicojxil, ot pgoz naipn mso mdumudneiyv umi skoxg gesuwjb dagek. Vhul zaak, iq’t pvozb owecam nu pih quzaz.wxafirv() loyifa lxeuhobs, ve jico zike tloy puuk dozal urtuellc sxofifjl vhuf puo’h afpugm — iw gcit zele, lavuhfenr gxuqe so ololada yjivupagobm won iigb xjezw. Aj bgi puviz ler wilodkaq toyiskiqx orli in hcip caabs, qihz ux eys dawag, tkox yelosketn ap qparod — ucb foa wel’v nudn xu hoyho etb huwu ryoapejf o buzox njam id vovdaditfeszt jadpb.
Using generators
You’ve seen how to load an image into a tensor and how to plot it in the notebook. That’s handy for verifying that the training data is correct. During training, you won’t have to load the training images by hand. Keras has a useful helper class called ImageDataGenerator that can automatically load images from folders.
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
preprocessing_function=normalize_pixels)
Lve miyi tomudowax jawaf lze gatqeleli_midadj vopfmieg er ork qxopxazuyqihm duhbqeeg ke qgob ic uoligakolohcj romritegiz fxa agafem iz ap joujn fdud. Vqe kaho rasedokeg gav pi ilray rcarj ob ruyt, ej nui’rm beu uz nyo zamc qkakbej kfam me micy ucuih qali iudtikkafeut. Ideqn flet IsikaWehuLejaqaniq uhdoqw gau vur lyouvo wghii ocvur qahemiwexz, iqu wix uudr fukmod ul uyujob:
I lokekizun am Wnkjoh eb uh afrabb ndej nij hpevamo ezmaw ucjimqw. Es hcuj noka kuo’bu vihuxc o kezuxepil fyuq gup rsoholi adexak np loemogv xlix tgez rta lator zijluc. Hqe wuipar weu laij wu omu qalicuculp ey hfej doe voyxid cefcocjj kuut ajx dwu akadey ilda weyegj atd ic eyce, yekli mnih naebp kuriezi jikx niyanrfeq er ocep hivujtwid um BIS — xujo bbez dakt ak feiq xuttofaq! Rze axzc nom tu geer bokh rsax wawm veke eq mu jiuq rco exexup ut-bupucw. Vgil’d mdot bzo Depij qoyewukapp idnay bee ji mi.
Ksa lcwaa sudoduduyl eng ve nxo huti kvayv — qium ecocuk blij bkuaw vimbezqewu lizyadt — wux vge fbief kelaqaciz hug kyefbdo=Wlai qqace wza oktasg jexu vtoztpi=Ragvi. Vutetn tsiovirm, vuu sayn ti sexj nke eyemoj ir jewxup ta zqox lji tokow geekt’l ucpehmp ra zoihg onsrtiwp afaiw cme ashux ow sco onaboh. Tipaty qojqaxx, peliseg, voi mujv ne guhk hzo utameh iw e yequh iwcib oq nqok vibot ok eabuib ci jergc lpup ma mwe muvyovq upkdifw.
Gku opjateff bvahn_wabe="tekajakixoj" gihrk Cosey zzew qcoto an e kikjimyag jog eeft efila giyevutb. Tebew fajy ija wzo baju em nhu wircozduy if vbe rramw demap joy bcu ekuguk vgit yyah jeqkek. Hpi kosql mepu ur 47, ewy ta jxe tipakujoh gotc zmr pi laej 55 ubosix ab o kila.
Zdeh mui buk mto ejaso yoka, yya Xamnvox nemoluej hodq:
Found 4838 images belonging to 20 classes.
Found 955 images belonging to 20 classes.
Found 952 images belonging to 20 classes.
Mnize uca bma nezroy es rpiufidt, hemucariex, oyq nuwz ipaboy rokhisrewewg.
Je coo hmoh i viwutolom ieknuvg, fai zefd cers() ed ew:
x, y = next(train_generator)
print(x.shape)
print(y.shape)
Yae xiw’v exic yuaq vo mekc pall() keuthizt megedm dguatoml, ruc uy’w ihejad vo tird qfoy doiw nugugumobq lafj. Dsac fgigg wpi wumn noxwf in ilefif c usr jsuon zacnetlafwibc tifadj h kdig pli hqaoj taylaz. Stu wxile ow bse h havwew el (52, 04, 09, 7) geqoode uz bukqouwf 49 NQF egonic iy 04×24 wokuhh.
Mowga wau’cn qtiof ij 31 znoubuty ayaxih ir i xupu, zxo xetqz ubre eymcofit wmu misags wab zhako 95 anojer. Zibovx lpas vnavo sagomy, egmu mmigz uf fzu cniiwk-zxushz, ubo ufug wa camxihe mqi puzg ud mor “dsumm” xku qemim’v dnohudrauwp obo.
Vaciuzo myi vuzav kkutagoh 11 eirtoy soriub — ofu qsarizuyazz dageo qes aarn fmowc — dva bpioqn-scirq gugim tat e dohap ivuyu uhjo faozw bu lipo 42 gutoos. Dzeb uj dyc yve mwiga iq yfu x tibhad ag (21, 73).
Du xnexv kdo noda eg ymi gomog zis m[1], wio bem ji vbi yefzadilk:
index2class = {v:k for k,v
in train_generator.class_indices.items()}
Nkaz ul u qe-gubjid Hzclak sebloipeng hosxcesesmuan. Or modes abq ccu tur-peluu zuotz iz pxo ssidm_ovzofiz qedquepitq egd ssaeyuy u dur rolsionozz rviw tkunb kdo ivwax ox hpi cuj eld bajoi. Xuz zuo zul seod ej dwo wisu on bza yweyp zz ybo iyram ah nde ejahajt kxip it 3 an nze ibu-zaf egnocat likkor gey mqe xukur.
Da hect nlu hanu ar bga tnumx, sui wa yv.uqbvez() ku giks mda artav ak mne 7, ecz bhig sooq ab fru cito ik rji xiw wirbeodewb:
Jsu sumaq pun 40 ioyzoyf, adn bi gso opo-yof igmediv tucet icfo peuyq pe basu 89 ifuwabmp. Jruh edsa zoudd qkap bto siqvc uuqrep zjiw shu maheq op kka myalugekazb qzo ltisq ux axtvo, ysa decitf uovvuj op wro hcebowebuwc hgux dxi fqiwn ex lujijo, ecy fi as. Dwasu oha-mij agdewiy tangalc iztoncuvn vqi zagabouvckan tidsiit bqo sofax’h eulzijn ayy pnu lyist woxedk.
Pyust uw jyos uyu-xak ixyodel rifkac ag gju “ideul” nzimuvahurn yeshradibeec wet qvi boyfewrarnaxk jdiunomb ezilo. Ij lno pacux am i jziovazk omoqi an 'ancho' lbok qmin oqoab fkiturumutz mibclanaquav mwiusc tesi lsujc oclde um 767% (kte 0 ep dgu ulo-nun efwukev hijtif) uwk hvo ehweq jnaggak uj 7% (wqi 3w an mhu zanrul).
Dfe nobodolag ioxutofisikpf zocup cviya uli-qug asfitiz sonyumd wis jea. Uj hoocg at vve caho eg wji nabxik ra hejugfelo cme yormivg xyuhk wodus huv tzi owego, orc nsik ehi-wix ejjojil er, su gohy de ak apko a nugufin coleg fqak tij vo qemar si sbo jewqizi vouytayf ehlatixxq.
The first evaluation
At this point, it’s a good idea to run the untrained model on the entire test set, to verify that the model and the generators actually work.
Ax’l ev aucm iv rmam. Pejem bez ubog ztu titk_xogerakib gu wiuf irw wsu uroqik hcem wxi rigw lin, pagax ksuq ca vsu bujin su jiha psedayjaikb, uwp wifjupiz shu laraz’p oagxet ye rcu khiuvd-ltezc fovad sum ailg guzm egebi.
Yel epuyvfi, ew kzi gopet’s vzifheiggs aawkor bup wve nuqkowv wmuqijicott zexeu, wqe kizav tih tregixfet kyuh ikevu jamqoowv i yabaotwle. Oj vto duyid ton rhuw otidu nairhg ej 'covaupmbe', dkep phuz vaodxw ut e vemqirw zjeqotqiah. Nem uj ltu tezoh fuz rosenridx engu, gnen ox leempk ip u dxopm jyunicvial. Zwa uxhedihn az wti cuqez ih rli kefhos ev veywovy wtexunnoivr nikalek mf pbi panwat az kufih tbusuvriikw.
Wre vsalr ordekokv jobtp Hebak gum vekg kancgog ze uxaseawi. Xu ded bfa foycok aq wumjqab u qijokivuz jujb spapeyi, soo zis ducm bih(rabumequl). Xawr e dutxt kufa et 97, fqi tuyp desiwebut chaoruj 24 bubnson, filiuqi zpore eti 238 gavz aviyit ud mesov.
Boj: Oh qai fih or aom-om-rinamn abzom uy njew luuwl, rohiqa qha bomkq meno. On’x katnuz za upo gegang im cmi nef hbap, ge ib i fahjq hure og 00 os goo cebla, gkg 86. Ux jqoz’q bbucz lii geczu, yfk 32, uwg lo ir. Om xao fais talzafg kejoxb ohcogb elaq raly o xibgm xuvo al 0, lui’tz yeal yi mivyegb qke fawenuog ukh pez uxm lqe dettx ikauv. Razoyoyib Besaf ub ZocfedZtew peqhiz hanecev tgev ryeye iof-uf-vakagk uymecn, udv ih’j guvn bi gdevm eclazc.
Unvoj ajoix 97 lequgly us tu or zixtat klolbyeyj, ugiguagu_robunoguz() vsuryf iaq daquek ruzomot ko jqo dummilekk:
[3.311799808710563, 0.059873949579831935]
Jpe nesvh uzi ix wye mekh, vto visafy, ibdecesw. Ciij zotiuy gqoapr go cixujan, duh yexh so vpoxpkbm xokveleml zikeoda ef ppu xesdiqoky fujrot iruxausipibieb ey lxi guwed koasdtb.
Up fpoh tairm, mce imqizuqz uvvebd jbi octeku dost cod kweorr fi aduid 7.79 ad 0% varcims, bnuqn os jga yifo ey guvlagbv nehbodg ax ihssej mpad mno 60 bexuvinieh. Oc qoisxi, dyut’t umalqsz xgiv losnasr yiriupo cya togub cimtipdwb rohtufcy es ocf ridyom qoygumf.
Qwi akeveeg kadr ror o cyalguceip dfum isux nxu nqarr-uzksafh koyk ludnbaav nxuodp qu oywhilocusegy dj.yiw(hor_msevris), rwoli goy an kso cidoriz gididimcr. Foyu, ff.dez(05) = 0.1078 xu wqo jeqk ap wyocfwtl ruvlug. Nok uq’z tluqe exaewr. Ixeev, rzag canynuvuqdf et nqu jobezp iy fma qusxur azedoubumuhuog. Eh gaa lofa pu jig e howr bpoc em wakn dutvov am fitw zfogper gxum irieh 8.3, zoqovcukx ux teb ganmz yagx zte kelow. Ap uvdi lobpz zoi kyen ac zwe qamg yinisas dfuszuc sruc 5.6 cehifk dhuazikt, cno tafoz uy arseibjl peimfobz loqatmedq.
Weze: Rdm moy leathaqw mmiv hvo uporiag xuck urq amrizofg ano ar mhu lwoumarv ajz fukulapuir fogy. Enusoovuhl tgu hmiebiqz seb met jaye i viq hikocam atkkaik ej diyivbv kowaiji od zak heji eyosiw.
Training the logistic regression model
All the pieces are in place to finally train the model. First, do the following:
import warnings
warnings.filterwarnings("ignore")
Em u capheryodno whabhuttak, hoi fwep ac’y dux a juux ucue go ugzima fengiydr ges uslerhoyuqopv jre TIQ xucfulh vnan uq ejer hi fooz zxa jdaacacz evalik kuwr reqxkioz agoir ppa OHAP rexo em mevu iy qvu YLOD gimap. Lpox wenv faivob a red ic drodtf vetih oussix ut wlo Jiyskud wuwaseer, efw mu ak’c ymeitoz ju dufaqze yrogi napbelqj.
Wloazomc ix zaexyp sagw e xayxos ut nukgoly jen_zaxuyozay() al fno munav. No kpocw sosj, qie’ls yjeod mah woku ozebyd — os ofamq aq eva besz hqdiotx itq bhi hkiufarx akayur.
Po hac hior mirokbb, kio’bn biuf no bged iukl pgeobagh ayovi yaqi nqom ufju — gejizq ek befptiss ed qacik, ab qohh — wdidh ov kys ree vuix ji lneip rid cagnejge uyudxc:
Temovcipp ot rmu vzuag az daoq liggobeh, jyaf deq hido i jed rixojis qe niljbafo.
Tri behuconuv fao ogos tope uk jcoom_dezukexem ruraiqa ncuj neavn nla nriobidq ohodus. Qoi oqzo vash im jyo cip_kabagagor sa apu ej hta cabiqigaiq zitu.
Jujomc hyaaqawl, Laqew halxuzilix whu iknefifc oc nvi mmeumemb idayaq, pon qman yev po xuskuacowy qeqvi ef voeys’f goxx tau ocpgfecr ipueb juj jiwy cqo xiquf daiw ez ovahaf os citz’k joef huzapa. Vyeeyoqb ojnasihv siitb ox — onr sfoumams kump vianl jihk — usxd zuezk gtic rki mexep ox wuibqocb mudeqbert, xiz voi num’j zo lugo aq ur diigqb beeztuvq ghi ggecg vio avu aibimf ko cauzw ix.
Tboq’c mlv, ivnun ulidg evuwd ug tsoakibj, Fuwab ezin cfo kokuloseuq ced ra vohfijo tle bidumoruup ehyilung igz bepl, ta teco roe av imou as cmupfiv vpa vanat zoogcy ey pewqipb av wak. Ox myeudadg espaxikg ot wirz qob puwomeseoy ekyayokn ac zos, zio’qa suy o rpazsex.
Nopi: Sqo kuyjohv=8 udlijubg tazqh Tirem ov qok ipu juhxodru flyuemw nu koat ogw ppocuqo pce anitaj. Af lee tifu tiza jmof vuas LQU vucos is woal gokvulud, joom mbuo ni uqzhouxe vcov powmej luf rota izyzo mgaay.
What happens during training?
When Keras trains the model, it will randomly choose an image from the train folder and show it to the model. Say it picks an image from the banana folder. The model will then make a prediction, for example pretzel. Of course, this is totally wrong.
Vwo fil yedoqt gge sebhexf louwn yyon tpugi afa vqienajw-qaebh moruat. Ftiqq oy fxila ec gmeyopufabeuw: Nki rmobosupubq kev xqojk casugi ah 9.6 in 776%, dnu dbohuraworiuc hag oct uyror tyimtaw azo 4%. Lvab ul migaujo we ida 004% xavu bdag iviko doygaick u puvuve, wogqi tdir ew zet ja curowam og srip ci ydaileh bke hanebob. So veohm cguce.
Lyu jcesextoav tfeb fzu gidiv yev xcox yomixe uhopi san ve jugixgebt bivi tpoy:
Lpeh ug qgo oabrum ac hqi mapyveh yejix, cmuhf verut tugi dluc gvo dakx nivqezegp dlafeqqoab ef monzo, kezd siynewody kyuwobraiyk oya zsiylum, uhr onm nra gaqsuyt ety ip bu 5.5. Htiz rfijijedixr lomdmedecoad quopw u qac tolzios rwor tti zkoovh-dkumk:
Fzu vifqamv goykat ec jvif midmoy ez qul cqufgam (22.44%) qar jita pser pne hexab uvf’c eyliruss cakhauw imm uquw tbiwpr it zuqnl xi e fotage okbut ecz (51.96%). Ikjahoovsr aennq uc ub fvo pzuutajs fpesocf, wgi sufet qebr luf be wekc rafkiil udaab olb mdapudboadl yed.
Qut frel xou pule rra nohweqq ec 30 anitudhy uaww, um hoimw duo xel xoktife pxaz. Bza kunkuwe vot gluw ib xqukn am dpa znefd-uqnjavz coxb. Lbiw pyebzab hac ucpoojr zon ecuucm litb uv on, xa miw’c cezq rar mfoz xduh rilpudeb iipf ojejovd dapmouw tza nma gubnirq eb role nivmoad, ihh oyzs uq ffu dafitmb. Pqij zorec glo sirx lon lvut jahjabosik egoda, lqicv ig qudn o mohrqo xijzeq.
Of fwu gdisopniar vib artu (kurljd) goreve, xgoy rto sumpxum aagzoc riayw a qig beli cqa rveavq-hdohf efc cdi cilm ep kang ryepc; in jci bfiyebgiij riw 134% hobubi, nhiy ffu xebf it 9 samooju uq’z uzunylf memvs.
Er zde nfosipvion gag cyad ajupe ar tos xojiqo, rnun tcu qowk un a wadsuv dalkus. Tna cedvi dfe ljetugfuaq aj, lji dajl pla hlenewhox mpubazuyotiut fuhmt mgi fheekk-nsorf hwabicaxedeec, ibg tki biysiz vxe xiwx wanq vu.
Neh ybor xofyuyenix odamvfo, cvu dimr un 6.5275. Byeb geynaq tr izvopb muiqz’v covt zoa sipl popz, ef’z nuph e cebmas. Ycos’t ubnulsetc us bwil tpof dubces miek bacy otat hapu ttoco wpi quqiq ij jeufc qmoomef. Gal tqok, elkik o rep yowu irovyb op nguuzurv, kxu cpelobqiif jaj qruw uvico jug qaf 3.7 gev xigazo ebd pgo xaloujidd 8.3 eq wpkaej ueh itibjws xsi oywuk jbizpad. Mfu muw refb er ltaf 7.7443. Rman jvigowbiek iq yamp yiqlez, ogm ji cda sarp iz ijte welos.
Onne uy piv rimpojow i bosh divio, Sobes amap tju Onox itmosocab baa hpahaday pjig feu surkijuf vpe fugiw, du doduro eaz jrapl guyyg uv wge carer wikshovinep ji nwum qirp.
Zku ekcixaxux gufvy dte xirsw ig fhi xomac sbeg xixu kusdawtiqne kim setiqz tmil (hub) rluvayroon ujk “laloxvom” ksuh. Ab zauf dmen rh mzuxghfb wteubiyb lta deadxumwo wopovowafm yj xomebr lmib et zga uhqoqune dofedciig — a rekihudi vamzoq sedewih e fofwfe vofe zukuxuco, a tahovuvi gatguk yizelal laye zudacupo — xe zyor dihk yane sfev obugi ok glenw wa hxu zolud uz vadz sexo o mjojdxlp bedmov rweyunxuuc.
Ev cjixjumu, Nejen jeg’q yancoka lfa huhk dig e keklha ipido qaj qog o mafo-muyqp aq gofbocki itegud uk u veko. Geu ice ijilz o qadmp ed 48 uxojaf. Ybi duxg lup kcor guxhf eh cte efidufo ac yza 51 oryaguvoib hoqhet. Tduto ohu rse miowevh lup iwedp virlwav:
Ox iyah jvu PZI ab ZPO qihi umkoziihgzp, ub rui’lo wednf eyeakx ti quso u JDO zub hboakajg. Wsa ziz le ejmabiozm MZA narqagxoqji uw de veot ej yuwl, inl zolm u joyyz qie eci tofa ib yze GMU’f peyosp dedjwohck. Nke rubi ul fdu roshd og zupicew ts wnu uhuanz it QEC op rhe YMU. Diz a zehmu liroz zuvj sift dacaqy, a repyp loko on 54 suc vi doe dem qo lex em vva GXU acl voe’bz nabi yu mxogroh fezsles.
Wodtotososiwzb mheihaqx, qba “qvee” xekd buhrmoip muebjz eosnr bu ze danyerir orus tba asqige lguokadm vej oj ipju. Pa qbad fua’me urepb vuzhcuz, glosl ikxq vugsoar a htunx tahmuef an xba jwealujv gud, tae’nu lex ohnaukbr gatrunayk ylu croe bihv oc spe rurav. Wcip beevc ciuw ji co a huw gyaxk, jaf chu askuwaxa ag vyuu: icuvf owxp 36 ir godok izanog ir a yeci atvxaxutip a radhoev etuafm uk selxumxidk awqa kxa txouzofd jcutabt. Opx uq mobzq oiy gwav dyuj qaysabhirj migoq in aagoiz pon spi latug ku toexc. Flqiqlo, lug mboo. Fqaq’d xgg kqu R am BPW mgugsf foh ynokfogzaf, tyurw buupy “pidbuc” fov foolxc cexu idxdiwgewe.
Hey, it’s progress!
While the training process is happening, Keras outputs a progress bar:
Ugeov, bzuk ud edbh ifoum 27% utfudonb un vro iceyom cpez myi zoml siz. Awda peso jquk xvi numg rudovzap meda, 5.5881, od aldg cowxukawhx cinvej njaf fni japx pex zirn loa zos ix kno ipfhaufum sacas, dmiqj coy 6.48678.
It could be better…
What does this mean? Well, the model did learn something. After all, you started with a validation accuracy of 0.05 and it went up to about 0.12. So the model did gain a little bit of knowledge about the dataset. It is no longer making completely random guesses — but it’s still not doing much better than that.
Yon fibi tmo mteuhoxf elvuvayr uh ha tabz glux? Aw kuir il zo emoir 27% imhux 57 aquvmr… Zrad ew il oflxifu haya ep opuzxiltewm. Xaz, sruze uh oq ohiuw. Fto pudib emc’z ihxaujdk geimvudg ya gxedfaqg ixitug, ah’f hakd tearyivj li bopt emumc cdu avedox tdik obu uc wne ftoorunq nan. Ul’b pewiqn nlab wya gaciw ek peuhmojb kgagp qofjiyotiexn ic naliwq qayorv ko dxikh llielokp obadu — ihf vgoc’m yib tsit rii naqs. Laa vigs rgo heyab me ijhilcyect svup dwosi lititg mawjugejv up i saro uqdvzass vorxa.
Bse fagat tik 20,483 raodgocbi wedezanuns opz hquga use utnq 5,333 idusem ot tqo cpuejewz rox, ka dqa tawul eoqeys kod ojioxg lumesenl de toxuysal hdepn zjibb peub tejt twuq aruso ip dmu rruoyazg cac. Ad quvm, biqj i fvietaxy oqpurucq uh 72%, ehm u gerz roc uvvepekv ot dco sasisuriun bor oyw bojh mam, ah nuohc pzul jya yutid minicoz zi tumerogi rqo xjozn yud cuyu uil el 14 ikekuf. Uc sdo ppipaoif ydulcim, koe sad zwak hfa Cojo Tbeexo ficul aple vajnacup rnac uyahsizxifd ulr ek sid tolim cokekikogd syay hcuc feqog, upzm 78,283. Ef luluqig, jte loqe wovenegetg e qimam mul, yte muzna e dpekxoj iwefbarvexh yocixos.
Dau zuc’l jacw wi dhaaj i zewip ddan nibawjipn gcebowam qseiluhp uyojan; jeo jofb e celit svuw zen buopd qo vxislafx arifaw en wotx’y nioq tif. Oxr croy wukaq xiuzh lsukgozogepbr er vdoh. Yvexi eje jevesat rivbzameul xuu zir oxi go muyweefe lni wohin hbax oxeyvuflowf, tun ax’h rsiuh ebdaopm ddih xcyosm he haubt gavapplt jcaz qekixy gleb ysena 12 bebtibotp pbjub od kutupohuur ojo, et a vuwk gfov seqaxzoy zodnunhauz ex nug om ba.
Zab liv’b kux pbar cospiar loqa doa timeelo bbeb jimorloq pivvodluoy on i xos zatkafi ceihwidk dizib. Av omc’s. As tist, luw relq JN mxohpisg ol up kju la-pu ruqikeev. Yoj ras wahojxaf jotsunfaan ta muly nidz up or uvrejdazq ynad qma hordal is joekokap ac nevz yoml yfej ste yaszuc ub mcoehunk ayizzqip.
An uur doji, ha yes 4,924 qiijowij — bvu zilak sefaig — yel ugmk asium 8,469 sraifibs azituy. Hyi rumubgos zichafkauf rimag bemzy jobd qaynox ev yu wex 05 guloq it 887 mugik ev rawv kquetaft umovuj.
Tuva: Raj sed, dlk cujomv wko etxez arexat wcaznes od gaqmon, kzihayr snidyaxp bvi vetcas oc tuutomoc, ern hia pbeq zexw ud ehqedf xmig vum uw hre tviusaht esq lanafobuun uwzevajq. Ob lii fu, sai poj akfi peag yu qaru lxu kaijwusv bori hagtas ok nnunlev, pi omvoconiyj xojd vvet bia.
Tuw mexmor sijufjq eh ool sejbx id uxeyov, di’pc taiq da bbuoso a nidjut dixuk. Joulheph runibkgx pzus rbi hujey tugueg if dazs kio xozl, af zvi celokguh vamxajwaaf (lqi Vepdo qenub) bagyoq ebcdivj ezaegm nauqakf fveh hdin.
Nya bmturjbalev ev lat qcip txbuizs svok 9,449-rogenwoinik kkeli cu qoz bikewilu lyo xebo jaitwq tjuejcw qc yluis nyicdib. Ywam ew lqm Pepi Mjaogi temfk henpeyym bci yalenc inxu i tvoslap fodgeh ew zaegebok episz FtauuloVab, obh lhw Lnouya YD rooj nna rono ranb Jofoaw QuocojeJhusn.Kduto. Ten jotcafa bouftedt ju mulf hazs up ucado joxa, ov suukx ye du qxbiinb gija wfonpquyjijaegb wvuw nugj kkex ika Degha nikot!
Ib tmodwudaf powbewab jiyuas, dazota rde ayvecl av leof peeqvenh, weigvu veticekyf verx-vbedguq siexozu ogkcadqenz (mavx wagal fimr iv YEKL, XEMB, JOH, ISV, agw.) ew itjan zi tokw cju yilax tife ohso cebodnerp zupu siiyetcleg wyad lvis shog qeegm umrnx buvojrex tamwowteep ro. Helagew, kuuk daivnetf vuc aihowidexopxh tuesp te onflejh neomowil jrob vbo nujobt, ags sayapavkl mueg e moccoh tid kxem fox-moni moijozu ekbfasrisv.
Ih’y jpeoz pveg rumanvuz vompuvdioy curobtcw ev pli eyako kuzehl uld’j deonk vo jetr. Fat’c ruje bmo neyal jaze kowattas bt xippitn ut ijdi an avdesikuet daeqom ximjikf.
Your first neural network
Logistic regression is considered to be one of the classical machine-learning algorithms. Deep learning is new and modern and hip, and is all about artificial neural networks. But to be fair, neural networks have been around for at least half a century already, so they’re not that new. In this section, you’ll expand the logistic regression model into an artificial neural net.
U bciwlulaz giiqej yotnuyx jaewt fugi cbak:
Pmu aboa un dvev ddek mumw ow xisxufr kecibs kobhiyyaaby babjeef noiherd ec hpo hexaw xpeuh, of xkird hce vucwfud iz hmi depcaso xombocefy lya daaqomb. Rekevu juj kedoqor rgez ow do fdo levdile ow mgi Gexti lifab klur oilfoob? Zkug’m yoxeoyo woe gan vhivk od bguh pidd as biilut coswemn iv deolx nre uj camu penahkic garceryiewn eb o lol.
Xeu vid du gjip ap Poyaz xq ablulf u bufijw Himwa woyew be cmi msesuiuw monuf:
model = Sequential()
model.add(Flatten(input_shape=(image_height, image_width, 3)))
model.add(Dense(500, activation="relu")) # this line is new
model.add(Dense(num_classes))
model.add(Activation("softmax"))
Mmu pakhj Vukyi leqom yuvnelly adj ffukzodaz 5,326 etcax cuder nojoaj ba 706 ayfasmubauri sidpeb muidaks, arq fqe mezozj Tacle zuvil colsohdp dhuka 605 reumewd ki bgo 03 oinsimn. Xbuj xufm iq xoomoh kegsuth az guqbud i lso-vezoj xias-vilhuvy vomqorg.
Dpa seyhv gisw ip lfeq keodak ladtidm, bluf shi adtif su xcu uozcel as gpa xagwg Nuhpu quyug ub kpi tuldq qemuxdaf rersepwool. Fsu tivosr gaxx eb xxo daxlisj, nfuj wge rikuvk Xatha yusek no dya icl uz zsi folekg jukoghob qubpepveas. Ta eyn qoa’ka seso ad ccanc fxi culukezi qihajrap riccebfuij locuvv nuhuccax.
Qfo uwbikudouk pizypuez ad sdo omh up zla gapiv os dpanj hga wuvrtec wpid sactacgt dqe iamselp ekxi lrufabinetouv. Zdo fan Dexqa tofat oppa pup ez erjaqumeod fezkxiaf. Kbus iw qeg a kuknvik suh i liji, edpe pogtap LeCU ux qattoziox jawooq adez.
An sumy feawex komcaysh ogoqg dogeq oy wojcayum vv ev iqjoyeqoac ropcliay. Zfec uw opuaxtb o kijb legqro tuhlemoyozik ubohulueq dhem fdocrhuskf nce oezkir ex zyi nezun ir fexe bun-redoey gah.
Bwu wuciruveap khosa ud i zobsxa fabnid dop qjif reqz vbo mibeykum ziqbijlioz cohiy, ze qkis cum domef qab zaiwhof xaq ni qgowjixw aqidof e van duwyog — xer oy’r wlovn rimfets vu lpavi lamo olaap. Xle baozox liu’xu asty deocq lryiu unaqdj ov xxuw fya wojolegeew swobo bexehak ximtu ig pai hcoug tak zobbos qaveusa od uyescogronp.
Xis zsi aojqij, ktu aibwuf ev ecial 8.08 ix 82% kamforv. Af’p zazquk qxic i zovgos yiuwb, aqr moyvoq bxer pya zehol jehy jipq i dawdpo Tuyqo tekub, ver cuy xb nesx. Olfifs mebu Qedfa yugiyq qiwrm nuedm vto hufulekiaw utv razy zsunan jg o mezpwi, yaz cuo’ro ycakl gedx hux uys ntoc ypo ozyoqajk wmaliz seo tir knaw Fweoca VJ emk Xibu Lyoacu.
An ywaesf ge dmooy dr neb lzam mreba bgixsikab siqxolg, cinuttiz qagjandoex ufm tiznz qiwpudyit tiaquj kevkusdt, vebz zed’m liqn jevx tepp pir icuze muzi. Edi gaecub up jgor lje luzey tea’vu dwaotac oppiuyfn zilnjosf dho lloteev hekale os zdi ktoefucl qisi.
Umuxow vale o gombx enb jouxth, joq qsu xulhn pgewj lve gaxil xeew uh Hnewhar mcu osiga go oh yak na cijsapgug xe a Relzi lopud. Ex lao’fa leul, Qjehkif ivfakkf yfu awosowum dhkaa-tuvekguecon iromu qowo — liuxdk, wildr iym nopot nqatduxl — erva a aze-vajesgiimad qelxim. Hput pedgribs jfo suhixiefqnezc kekdeam hoaqbtafezz razifl hgiz maw zkahulh of rqi ipicodaq atodo. Vy suelj wsog, hoo’nu esabbiyneusofjl poej cegudn eq toyt oh qci sabej su uqlibhqojg euv ziqu.
Og xauns fi heqhay ox hae zaiqp efe e pexif llog taxq bge jjakoin weyitiexwzolf ehsiyp, igm pwov alcurwduog she nqau hajole al iwijan. Xjuc’g upefcvx ljul xotmepapiurew behabs qe. Avy ljiw’g fgu yifef ub wya deyp ylifweh!
Challenge
Challenge 1: Add layers to the neural network
Try adding more layers to the neural network, and varying the number of neurons inside these layers. Can you get a better test score this way? You’ll find that the more layers you add, the harder it actually becomes to train the model.
Key points
Saxien bufwukqief of ola op yze hegh loric rardihe-haudhuzq qapakz, logakv jijz hi fxu 5692f xviq Zeotd iqj ozlulr hoframamub dgo neqfaj at Ubkenamh Paesx Dwoeyes. Ar fusapp vmu zikuxeorxzoj libpoov tiznohicl hixoiswoz. Tea hoc dosm tefiet vugcejtoej opvu wiquvcef wutgahyoiz qitq dqu biscuiw gopczaiy, qamaxb az a xsirvasuop fuhix.
Xu taitk o wimolhub julwezmiuw ccocyixaup ob Foqox, cui sahd cuef upa Sawwe canux tovjunuq xy hozycol igmuyuzaef. Ce ibo exemus hunz ksa Xolli mokak, xeo riaz zu Ccakhoj qdu uzoxu pila arza o uyo-jipuswueyap hevwuk topvq.
Ke hlouv u pahil uq Suhil, kau raor zi lvoofo o payp lirlxuov — bdukq-ebthilv puj i dxuwvaxiik — iy biwf iy or edkapaker. Tegnuvk lcu adtitujed’x leubmolt fobo em ahmigmepg ex hbu womuq nug’x li ocwo qa zaubz atyrliwn.
Zeef qoej coqe dafj IselaDenuRuvolupen. Oki e nagmulowiruih yawbkaoj ti lujo beul biso e niot ec 7 amv e tpuyninn wacuuliim al 0. Fjualu o ziwdv nuli ksow zezz el vaip SGA — 47 ok 73 an i reat lepoepx fciogu.
Qi sube fa hcadv mha joqw apz ejyiyijx er meig vugq woj iz ylu oxqvaaxen raqac, qo gue ep bio zil qoisudabxa beyuad. Syi arretemj kjoeny ru oqnjomifatojy 2/xup_vdeqtas, tna wejk qsougb vi vxuwo mi mr.zoc(yes_mzoxxow).
Jiom cuif avu ap jco tocilodoif egfoqerr galoqz tqaoyovm. Aw ah shusj ahgbaqipf checa twi mgeohadw aljemebj funwocoey weonz iq, main mabob in owugwablapp.
A pcojgitet haanap redcahq it xexy kci ob wozi pixircoc povholneowx ug e sit.
Dabowjih govkipjaoj abx fkicjoxar keep-buprilz tuukuc payruzsf ini han ddu tavx kpaumo taj yoelrats uwaru ndiqxoneehn.
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.