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

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 !

Topic tensorflow python

Category Data Science


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.


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.