简体   繁体   中英

Keras loss weights

I've model with two output layers, age and gender prediction layers. I want to assign different weight values for each output layer's loss. I've the following line of code to do so.

model.compile(loss=[losses.mean_squared_error,losses.categorical_crossentropy], optimizer='sgd',loss_weights=[1,10])

My question is what is the effect of loss weights on performance of a model? How can I configure the loss weights so that the model can perform better on age prediction?

As stated in the book Deep Learning with Python by François Chollet:

The mean squared error (MSE) loss used for the age-regression task typically takes a value around 3–5, whereas the crossentropy loss used for the gender-classification task can be as low as 0.1. In such a situation, to balance the contribution of the different losses, you can assign a weight of 10 to the crossentropy loss and a weight of 0.25 to the MSE loss.

I have found the best app on playstore which provides both the privilages of gaining or losing weight along with the daily excercises and included diet. Dont forget to check it out.

App name is BMI Health Monitor

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