简体   繁体   中英

Pytorch CrossEntropyLoss Tensorflow Equivalent

I am currently translating a pytorch code into tensorflow. There is a point that i am aggregating 3 losses in a tensorflow custom loop and i get an error that i am passing a two dimensional array vs a 1 dimensional into CategoricalCrossEntropy of tensorflow which is very legit and i understand why this happens... but in the pytorch code i am passing the same shapes and it's perfectly working with CrossEntropyLoss. Does anybody know what i have to do to transfer this into TF? the shapes that are passing in are (17000,100) vs (17000)

Try using the loss loss=tf.keras.losses.sparse_categorical_crossentropy

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