About Keras

文章推薦指數: 80 %
投票人數:10人

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?



請為這篇文章評分?