简体   繁体   中英

difference between tf.keras.losses.SparseCategoricalCrossentropy() vs “sparse_categorical_crossentropy” as loss

I'm implementing a multi class classification problem,

  1. when I'm using my loss as tf.keras.losses.SparseCategoricalCrossentropy() , I'm getting very less accuracy
model.compile(optimizer="adam", loss=tf.keras.losses.SparseCategoricalCrossentropy(), metrics=["accuracy"])
  1. And when I use loss as "sparse_categorical_crossentropy" , I'm getting much higher accuracy
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]) 
  • Does this have to do with batch size?
  • How to get same results as "sparse_categorical_crossentropy" using custom loss layer?

it's because when you use

loss=tf.keras.losses.SparseCategoricalCrossentropy() 

metrics should

"sparse_categorical_accuracy" not "accuracy"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM