    def _gram_mat(self, x):
        """Calculate Gram matrix.

        Args:
            x (torch.Tensor): Tensor with shape of (n, c, h, w).

        Returns:
            torch.Tensor: Gram matrix.
        """
        n, c, h, w = x.size()
        features = x.view(n, c, w * h)
        features_t = features.transpose(1, 2)
        gram = features.bmm(features_t) / (c * h * w)
        return gram
Calculate Gram matrix.

Args:
x (torch.Tensor): Tensor with shape of (n, c, h, w).

Returns:
torch.Tensor: Gram matrix.
opensora/models/super_resolution/basicsr/losses/losses.py