Splitting up types of data in a keras loss function (equivalent to if statements in loss functions?)
For anyone that might stumble upon this question later, I realise now that I worded the question poorly with respect to what the actual answer is. The question is actually answered by "how to calculate gradients and apply them as separate operations in keras"
My solution is to overwrite the Model class, create a new train_on_batch method that accepts more than one dataset.
Then apply however many calculations and loss functions you want inside a gradientTape. Then finally use optimizer.apply_gradient() to actually apply the gradients to the model
Is it possible to write a custom loss function in keras that says "for all data from dataset A: calculate loss like this... And for all data from dataset B: calculate loss like this instead"
My current implementation has 2 separate models with their own loss functions and then the 2 data feeds are given in separate train_on_batch calls.
For context, my system is a GAN that is tasked with creating a domain indistinguishable representation between two datasets, while also performing classification. However with my current method it feels as though the "domain indistinguishability" task is taking priority and my classification accuracy is not rising above random. (whereas if I turn off the domain task, the classification accuracy rises to approximately 80%). And one issue I'd like to rule out is multiple calls of train_on_batch with non-shuffled data per training loop.