From b66e1ad13e4331299c0bfca46f2f43c9b1c278bc Mon Sep 17 00:00:00 2001 From: Lixing Xiao <111164872+tryhiseyyysum@users.noreply.github.com> Date: Fri, 12 Jul 2024 16:56:48 +0800 Subject: [PATCH] Update loss_utils.py Updated the function ssim(), the optimized version of ssim() is ssim_optimized(), which reduce the computational complexity. After modified, the function create_window() just need to be called once in the main function in train.py, no need to be called in ssim() in every iteration. --- utils/loss_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/loss_utils.py b/utils/loss_utils.py index 77a3f10..ebc929a 100644 --- a/utils/loss_utils.py +++ b/utils/loss_utils.py @@ -26,7 +26,7 @@ def gaussian(window_size, sigma): def create_window(window_size, channel): """Create a 2D Gaussian window.""" - _1D_window = gaussian(window_size, 1.5).unsqueeze(1) #此处高斯窗口的sigma固定为1.5 + _1D_window = gaussian(window_size, 1.5).unsqueeze(1) _2D_window = _1D_window.mm(_1D_window.t()).float().unsqueeze(0).unsqueeze(0) window = Variable(_2D_window.expand(channel, 1, window_size, window_size).contiguous()) return window @@ -63,7 +63,7 @@ def _ssim(img1, img2, window, window_size, channel, size_average=True): else: return ssim_map.mean(1).mean(1).mean(1) -#-----------------modify----------- +#-----------------modify------------------------------------ def ssim_optimized(img1, img2, window=None, window_size=11, size_average=True): channel = img1.size(-3) if window is None: