TransWikia.com

How can I use different loss functions for images with different labels in tensorflow?

Data Science Asked by gypaetebarbu on April 15, 2021

I have two types of images, meaning two different sets of possible labels. How can I use two different loss functions based on which image I am currently training on with a batch size of 1?
Thanks !

2 Answers

This is not possible, for 2 reasons:

  1. It doesn't make mathematical sense. The Gradient must explore one loss function that is optimized to distinguish between more than one class. Using a loss function to classify a single class is equivalent to not learning anything.
  2. In ML, the models you train are meant to generalize on data they have never seen before. Because of this, you can't use different loss functions because once you test its performance on test data nobody knows to what class they belong.

Answered by Leevo on April 15, 2021

One option is multi-task learning. In this case, multi-task learning would allow a single model to learn more than one independent label for the same image. There is a separate loss function for each task (i.e., independent label). Those separate loss functions would be aggregated for a single loss function to train the overall model.

Training on a batch size of one will result in overfitting. The network will optimize for each image individually. Increasing batch will regularize, increasing generalization, across images.

Answered by Brian Spiering on April 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP