Thanks for reply.
I’m trying to solve a muti classification problem called phase unwrapping using a u-net. The final layer is 1x1 conv followed by softmax.
There is a relationship between image m_label and n_label, n_label = m_label + constant*k, in which in which m_label is network input ,  k is predicted class (an integer matrix) from softmax output.
To make a good prediction, i minimize:

the diffference of grad of m_label and n_pred
the difference of n_label and n_pred (calc by n_pred = m_label + constant*k_pred)
the cross entry loss between k_pred and k_label (calc by round((n_label - n_label)/constant) ), not mentioned in code