1
$\begingroup$

I am trying to simplify a CNN model. Currently, I need to train 3 different models (with the same architecture) to estimate each parameter. I am just wondering if there is a way to just train one model that outputs 3 parameters, with input images containing only single parameter label. Say the three parameters are some kind of measure of symmetry (sym), repetitiveness (rep), roundness (rd). Each of my input images will only give a label for one of the parameters. For each parameter, there is the same number of images. I am thinking if there is a way to accomplish this using some kind of dummy variable to block out the unavailable parameters from backpropagation?

If anyone who has experience with this scenario could give me some advice, it would be super appreciated.

$\endgroup$
1
$\begingroup$

Yes, this can be done. Basically, you define a custom loss function, and then train the neural network to minimize this loss function. In particular, you construct a single neural network that has 3 outputs; the first output is a measure of symmetry, the second of repetitiveness, and the third roundness. The custom loss function should look at the output for which you have a known label and penalize the model according to how much that output is in error (it ignores the other 2 outputs). For instance, if you are currently using mean-squared error, your custom loss function would be equal to the square of the difference between the known label and the corresponding output of the network. This custom loss function is differentiable, so all the standard training methods (backpropagation, gradient descent, Adam solver, etc. etc.) work directly, with no modifications needed.

Many libraries for training neural networks will let you specify a custom loss function.

$\endgroup$
  • $\begingroup$ Thank you! I am working with Keras with tensorflow as the backend, would you know how to block out the unavailable parameter when working with y_true and y_pred? I am thinking about multiplying them with an array like [1,0,0] if the first parameter is available... in that case can I initiate a numpy array inside the customized loss function? $\endgroup$ – somebodyzh Jun 19 '18 at 19:44
  • $\begingroup$ @somebodyzh, that's a coding question that is probably best asked on Stack Overflow - but I can see there is lots of information already existing (e.g., on Stack Overflow) about how to write a custom loss function for Tensorflow and Keras, so do some research, try a few things, and if you're still stuck, ask a specific question on Stack Overflow. $\endgroup$ – D.W. Jun 19 '18 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.