Problem with using Tensorflow addons' metrics correctly in ...

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

Problem with using Tensorflow addons' metrics correctly in functional API · OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 / Google Colab ... ProblemwithusingTensorflowaddons'metricscorrectlyinfunctionalAPI(OriginalURL)Systeminformation OSPlatformandDistribution(e.g.,LinuxUbuntu16.04):Windows10/GoogleColab TensorFlowversionandhowitwasinstalled(sourceorbinary):2.1.0-rc1(pipinstall) TensorFlow-Addonsversionandhowitwasinstalled(sourceorbinary):0.6.0(pipinstall) Pythonversion:3.6.9 IsGPUused?(yes/no): Describethebug IhaveanLSTMmodeltoperformbinaryclassificationofhumanactivitiesusingmultivariatesmartphonesensordata.Thetwoclassesareimbalanced(1:50).ThereforeIwouldliketouseF1-scoreasametric,whichiswhyIcameacrosstheTensorFlowAddons. InowhaveaproblemtoapplythisscoretomyfunctionalAPI. IfIuseanothervalueforthemetricargumentaverage(e.g.,average=Noneoraverage="macro")thenIgetanerrormessagewhenfittingthemodel: ValueError:Dimension0inbothshapesmustbeequal,butare2and1.Shapesare[2]and[1].for‘AssignAddVariableOp’(op:‘AssignAddVariableOp’)withinputshapes:[],[1]. AndifIusethevalueaverage="micro"Iamnotgettingtheerror,buttheF1-scoreis0throughoutthelearningprocess,whilemylossdecreases. IbelieveIamstilldoingsomethingwronghere.Cananybodyprovideanexplanationforme? Codetoreproducetheissue importtensorflowastf importtensorflow_addonsastfa fromtensorflowimportkerasdef create_model(n_neurons=150,learning_rate=0.01,activation="relu",loss="binary_crossentropy"): #createinputlayerandassigntocurrentoutputlayer input_=keras.layers.Input(shape=(X_train.shape[1],X_train.shape[2])) #addLSTMlayer lstm=keras.layers.LSTM(n_neurons,activation=activation)(input_) #OutputLayer output=keras.layers.Dense(1,activation="sigmoid")(lstm) #CreateModel model=keras.models.Model(inputs=[input_],outputs=[output]) #Addoptimizer optimizer=keras.optimizers.SGD(lr=learning_rate,clipvalue=0.5) #Compilemodel model.compile(loss=loss,optimizer=optimizer,metrics=[tfa.metrics.F1Score(num_classes=2,average="micro")]) print(model.summary()) returnmodel #Createthemodel model=create_model() #fitthemodel history=model.fit(X_train,y_train, epochs=300, validation_data=(X_val,y_val)) Otherinfo/logs TryLightruntocollectproductionstacktraceswithoutstoppingyourJavaapplications!Comments(6)bytillmo+3Therearetwootherproblemshere: themodelusesbinaryclassification,butf1-scoreintfaassumescategoricalclassificationwithone-hotencoding,seehttps://github.com/tensorflow/addons/issues/746#issuecomment-562963134 f1-scoreiscalledateachbatchstepatvalidation.Thisdoesnotmakesense.Therightwaytodothisistouseacustomcallbackfunctioninawaylikethis:https://github.com/PhilipMay/mltb/blob/7fce1f77294dccf94f6d4c65b2edd058a654617b/mltb/keras.py.Seealsohttps://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2.Ihavefiledanissue:#825 bySquadrick+1ThenewerversionofF-scoresfrom#502isn’tincludedinr0.6(theolderversionisincluded).Installingtfa-nightlyshouldincludetheF-scoreswiththreshold. bySSaishruthi+1Willcheck bySSaishruthiThanks,@Squadrick. Iwillpostthesolutionhereusingnightlyversion bySSaishruthi@seanpmorganIamnotseeingthresholdparametersinthecurrentrelease.Itisthrowinganerrorwhenusingit.Belowisthescreenshotofthesame.Anyideawhy? Thisissuecanbesolvedbythat bySquadrickcccodeowner@SSaishruthi Previousissuedev-serverdefaultportisnotaddedanymoreNextissueUnabletosetInfraValidatormodelservingcontainerresources



請為這篇文章評分?