The model has three main components
sobel
to create horizontal sobel kernelsHessian
to calculate the hessian matrix per channelSmoothness
to calculate a smoothness value per channel
The smoothness value is the negative mean, of the sums, of the squared elements, of the per pixel hessian matrices.
The smoothness module can be applied to neural network outputs and the resulting value can be substracted from the loss to train networks to give smooth outputs.
loss = loss - smoothness
The example generates a non-smooth random image and uses gradient decent to smooth it out.
pip install git+https://github.com/tasptz/pytorch-smooth