tfmri.losses.ssim_multiscale_loss
tfmri.losses.ssim_multiscale_loss¶
- ssim_multiscale_loss(y_true, y_pred, max_val=None, power_factors=(0.0448, 0.2856, 0.3001, 0.2363, 0.1333), filter_size=11, filter_sigma=1.5, k1=0.01, k2=0.03, batch_dims=None, image_dims=None, rank=None)¶
Computes the multiscale structural similarity (MS-SSIM) loss. (deprecated arguments)
Deprecated: SOME ARGUMENTS ARE DEPRECATED:
(rank). They will be removed after 2022-09-01. Instructions for updating: Use argumentimage_dimsinstead.The MS-SSIM loss is equal to \(1.0 - \textrm{MS-SSIM}\).
- Parameters
y_true – A
Tensor. Ground truth images. For 2D images, must have rank >= 3 with shapebatch_shape + [height, width, channels]. For 3D images, must have rank >= 4 with shapebatch_shape + [depth, height, width, channels].height,widthanddepthmust be greater than or equal to(filter_size - 1) * 2 ** (len(power_factors) - 1) + 1. Must have floating point type, with values in the range[0, max_val].y_pred – A
Tensor. Predicted images. For 2D images, must have rank >= 3 with shapebatch_shape + [height, width, channels]. For 3D images, must have rank >= 4 with shapebatch_shape + [depth, height, width, channels].height,widthanddepthmust be greater than or equal to(filter_size - 1) * 2 ** (len(power_factors) - 1) + 1. Must have floating point type, with values in the range[0, max_val].max_val – The dynamic range of the images (i.e., the difference between the maximum and the minimum allowed values). Defaults to 1 for floating point input images and
MAXfor integer input images, whereMAXis the largest positive representable number for the data type.power_factors – A list of weights for each of the scales. The length of the list determines the number of scales. Index 0 is the unscaled resolution’s weight and each increasing scale corresponds to the image being downsampled by 2. Defaults to (0.0448, 0.2856, 0.3001, 0.2363, 0.1333), which are the values obtained in the original paper.
filter_size – The size of the Gaussian filter. Defaults to 11.
filter_sigma – The standard deviation of the Gaussian filter. Defaults to 1.5.
k1 – Factor used to calculate the regularization constant for the luminance term, as
C1 = (k1 * max_val) ** 2. Defaults to 0.01.k2 – Factor used to calculate the regularization constant for the contrast term, as
C2 = (k2 * max_val) ** 2. Defaults to 0.03.batch_dims –
An int. The number of batch dimensions in input images. If None, it is inferred from inputs and
image_dimsas(rank of inputs) - image_dims - 1. Ifimage_dimsis also None, thenbatch_dimsdefaults to 1.batch_dimscan always be inferred ifimage_dimswas specified, so you only need to provide one of the two.image_dims –
An int. The number of spatial dimensions in input images. If None, it is inferred from inputs and
batch_dimsas(rank of inputs) - batch_dims - 1. Defaults to None.image_dimscan always be inferred ifbatch_dimswas specified, so you only need to provide one of the two.rank –
An int. The number of spatial dimensions. Must be 2 or 3. Defaults to
tf.rank(y_true) - 2. In other words, if rank is not explicitly set,y_trueandy_predshould have shape[batch, height, width, channels]if processing 2D images or[batch, depth, height, width, channels]if processing 3D images.
- Returns
A
Tensorof typefloat32and shapebatch_shapecontaining an SSIM value for each image in the batch.
References
- 1
Zhao, H., Gallo, O., Frosio, I., & Kautz, J. (2016). Loss functions for image restoration with neural networks. IEEE Transactions on computational imaging, 3(1), 47-57.