def build_loss(self):
image_dims = K.ndim(self.img) - <NUM_LIT:2><EOL>start_slice = [slice(<NUM_LIT:1>, None, None)] + [slice(None, -<NUM_LIT:1>, None) for _ in range(image_dims - <NUM_LIT:1>)]<EOL>end_slice = [slice(None, -<NUM_LIT:1>, None) for _ in range(image_dims)]<EOL>samples_channels_slice = [slice(None, None, None), slice(None, None, None)]<EOL>tv = None<EOL>for i in range(image_dims):<EOL><INDENT>ss = tuple(samples_channels_slice + start_slice)<EOL>es = tuple(samples_channels_slice + end_slice)<EOL>diff_square = K.square(self.img[utils.slicer[ss]] - self.img[utils.slicer[es]])<EOL>tv = diff_square if tv is None else tv + diff_square<EOL>start_slice = np.roll(start_slice, <NUM_LIT:1>).tolist()<EOL>end_slice = np.roll(end_slice, <NUM_LIT:1>).tolist()<EOL><DEDENT>tv = K.sum(K.pow(tv, self.beta / <NUM_LIT>))<EOL>return normalize(self.img, tv)<EOL>
r"""Implements the N-dim version of function
        $$TV^{\beta}(x) = \sum_{whc} \left ( \left ( x(h, w+1, c) - x(h, w, c) \right )^{2} +
        \left ( x(h+1, w, c) - x(h, w, c) \right )^{2} \right )^{\frac{\beta}{2}}$$
        to return total variation for all images in the batch.