compute pixelwise gradients w.r.t. to classes