About Keras
文章推薦指數: 80 %
Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow. It was developed with a focus on enabling fast ... Star AboutKeras Gettingstarted Developerguides KerasAPIreference Codeexamples WhychooseKeras? Community&governance ContributingtoKeras KerasTuner KerasCV KerasNLP search »AboutKeras AboutKeras KerasisadeeplearningAPIwritteninPython,runningontopofthemachinelearningplatformTensorFlow. Itwasdevelopedwithafocusonenablingfastexperimentation.Beingabletogofromideatoresultasfastaspossibleiskeytodoinggoodresearch. Kerasis: Simple--butnotsimplistic.Kerasreducesdevelopercognitiveloadtofreeyoutofocusonthepartsoftheproblemthatreallymatter. Flexible--Kerasadoptstheprincipleofprogressivedisclosureofcomplexity:simpleworkflowsshouldbequickandeasy, whilearbitrarilyadvancedworkflowsshouldbepossibleviaaclearpaththatbuildsuponwhatyou'vealreadylearned. Powerful--Kerasprovidesindustry-strengthperformanceandscalability:itisusedbyorganizationsandcompaniesincludingNASA,YouTube,orWaymo. Keras&TensorFlow2 TensorFlow2isanend-to-end,open-sourcemachinelearningplatform.Youcanthinkofitasaninfrastructurelayerfor differentiableprogramming.Itcombinesfourkeyabilities: Efficientlyexecutinglow-leveltensoroperationsonCPU,GPU,orTPU. Computingthegradientofarbitrarydifferentiableexpressions. Scalingcomputationtomanydevices,suchasclustersofhundredsofGPUs. Exportingprograms("graphs")toexternalruntimessuchasservers,browsers,mobileandembeddeddevices. Kerasisthehigh-levelAPIofTensorFlow2:anapproachable,highly-productiveinterfaceforsolvingmachinelearningproblems, withafocusonmoderndeeplearning.Itprovidesessentialabstractionsandbuildingblocksfordeveloping andshippingmachinelearningsolutionswithhighiterationvelocity. Kerasempowersengineersandresearcherstotakefulladvantageofthescalability andcross-platformcapabilitiesofTensorFlow2:youcanrunKerasonTPUoronlargeclustersofGPUs, andyoucanexportyourKerasmodelstoruninthebrowseroronamobiledevice. FirstcontactwithKeras ThecoredatastructuresofKerasarelayersandmodels. ThesimplesttypeofmodelistheSequentialmodel,alinearstackoflayers. Formorecomplexarchitectures,youshouldusetheKerasfunctionalAPI, whichallowstobuildarbitrarygraphsoflayers,orwritemodelsentirelyfromscratchviasubclasssing. HereistheSequentialmodel: fromtensorflow.keras.modelsimportSequential model=Sequential() Stackinglayersisaseasyas.add(): fromtensorflow.keras.layersimportDense model.add(Dense(units=64,activation='relu')) model.add(Dense(units=10,activation='softmax')) Onceyourmodellooksgood,configureitslearningprocesswith.compile(): model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) Ifyouneedto,youcanfurtherconfigureyouroptimizer.TheKerasphilosophyistokeepsimplethingssimple, whileallowingtheusertobefullyincontrolwhentheyneedto(theultimatecontrolbeingtheeasyextensibilityofthesourcecodeviasubclassing). model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.SGD(learning_rate=0.01,momentum=0.9,nesterov=True)) Youcannowiterateonyourtrainingdatainbatches: #x_trainandy_trainareNumpyarrays model.fit(x_train,y_train,epochs=5,batch_size=32) Evaluateyourtestlossandmetricsinoneline: loss_and_metrics=model.evaluate(x_test,y_test,batch_size=128) Orgeneratepredictionsonnewdata: classes=model.predict(x_test,batch_size=128) WhatyoujustsawisthemostelementarywaytouseKeras. However,Kerasisalsoahighly-flexibleframeworksuitabletoiterateonstate-of-the-artresearchideas. Kerasfollowstheprincipleofprogressivedisclosureofcomplexity:itmakesiteasytogetstarted, yetitmakesitpossibletohandlearbitrarilyadvancedusecases, onlyrequiringincrementallearningateachstep. Inmuchthesamewaythatyouwereabletotrain&evaluateasimpleneuralnetworkaboveinafewlines, youcanuseKerastoquicklydevelopnewtrainingproceduresorexoticmodelarchitectures. Here'salow-leveltrainingloopexample,combiningKerasfunctionalitywiththeTensorFlowGradientTape: importtensorflowastf #Prepareanoptimizer. optimizer=tf.keras.optimizers.Adam() #Preparealossfunction. loss_fn=tf.keras.losses.kl_divergence #Iterateoverthebatchesofadataset. forinputs,targetsindataset: #OpenaGradientTape. withtf.GradientTape()astape: #Forwardpass. predictions=model(inputs) #Computethelossvalueforthisbatch. loss_value=loss_fn(targets,predictions) #Getgradientsoflosswrttheweights. gradients=tape.gradient(loss_value,model.trainable_weights) #Updatetheweightsofthemodel. optimizer.apply_gradients(zip(gradients,model.trainable_weights)) Formorein-depthtutorialsaboutKeras,youcancheckout: IntroductiontoKerasforengineers IntroductiontoKerasforresearchers Developerguides Installation&compatibility KerascomespackagedwithTensorFlow2astensorflow.keras. TostartusingKeras,simplyinstallTensorFlow2. Keras/TensorFlowarecompatiblewith: Python3.7–3.10 Ubuntu16.04orlater Windows7orlater macOS10.12.6(Sierra)orlater. Support Youcanaskquestionsandjointhedevelopmentdiscussion: IntheTensorFlowforum. OntheKerasGooglegroup. Youcanalsopostbugreportsandfeaturerequests(only)inGitHubissues. Makesuretoreadourguidelinesfirst. Whythisname,Keras? Keras(κέρας)meanshorninGreek.ItisareferencetoaliteraryimagefromancientGreekandLatinliterature,firstfoundintheOdyssey,wheredreamspirits(Oneiroi,singularOneiros)aredividedbetweenthosewhodeceivedreamerswithfalsevisions,whoarrivetoEarththroughagateofivory,andthosewhoannounceafuturethatwillcometopass,whoarrivethroughagateofhorn.It'saplayonthewordsκέρας(horn)/κραίνω(fulfill),andἐλέφας(ivory)/ἐλεφαίρομαι(deceive). KeraswasinitiallydevelopedaspartoftheresearcheffortofprojectONEIROS(Open-endedNeuro-ElectronicIntelligentRobotOperatingSystem). "Oneiroiarebeyondourunravelling-whocanbesurewhattaletheytell?Notallthatmenlookforcomestopass.TwogatestherearethatgivepassagetofleetingOneiroi;oneismadeofhorn,oneofivory.TheOneiroithatpassthroughsawnivoryaredeceitful,bearingamessagethatwillnotbefulfilled;thosethatcomeoutthroughpolishedhornhavetruthbehindthem,tobeaccomplishedformenwhoseethem."Homer,Odyssey19.562ff(Shewringtranslation). AboutKeras ▻ Keras&TensorFlow2 ▻ FirstcontactwithKeras ▻ Installation&compatibility ▻ Support ▻ Whythisname,Keras?
延伸文章資訊
- 1Day 02:撰寫第一支Neural Network 程式-- 阿拉伯數字辨識
Machine Learning 框架(Framework)GitHub評比,資料來源:【AI關鍵技術】三大熱門 ... 完成一個Neural Network 模型,非常適合入門學習,因此我們就...
- 2[讀書筆記]Deep learning 深度學習必讀:Keras 大神帶你用 ...
Keras提供的循環層有SimpleRNN、LSTM和GRU。SimpleRNN理論上應該能夠 ... [讀書筆記]Deep learning 深度學習必讀:Keras 大神帶你用Python ...
- 3Deep learning 深度學習必讀:Keras 大神帶你用Python 實作
書名:Deep learning 深度學習必讀:Keras 大神帶你用Python 實作,原文名稱:Deep Learning with Python, 1st edition,語言:繁體中文,...
- 4Keras Tutorial | Deep Learning with Python - Javatpoint
Keras is an open-source high-level Neural Network library, which is written in Python is capable ...
- 5Advanced Deep Learning with Keras, published by Packt
Please note that the code examples have been updated to support TensorFlow 2.0 Keras API only. Ab...