Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the implementation of ssim() loss function, reduce the computational complexity from O(n) to O(1) since create_window() is called only once in main function #886

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tryhiseyyysum
Copy link

In the 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.

In the train.py: Updated the main function, call the create_window() function for just once, since the window_size is fixed to 11 and the channel is fixed to 3 according to the source code.
Updated the calculation of loss function, call the ssim_optimized(), instead of the original ssim().

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.
Updated the main function, call the create_window() function for just once, since the window_size is fixed to 11 and the channel is fixed to 3 according to the source code.
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.
Updated the main function, call the create_window() function for just once, since the window_size is fixed to 11 and the channel is fixed to 3 according to the source code. 
Updated the calculation of loss function, call the ssim_optimized(), instead of the original ssim().
@tryhiseyyysum tryhiseyyysum changed the title Update the implementation of ssim() loss function, reduce the computational complexity from O(n) to O(1) since create_window() is called once once in main function Update the implementation of ssim() loss function, reduce the computational complexity from O(n) to O(1) since create_window() is called only once in main function Jul 12, 2024
def prepare_output_and_logger(args):
if not args.model_path:
if os.getenv('OAR_JOB_ID'):
unique_str=os.getenv('OAR_JOB_ID')
else:
unique_str = str(uuid.uuid4())
args.model_path = os.path.join("./output/", unique_str[0:10])
args.model_path = os.path.join("/mnt/data1/3dgs_modify_output/", unique_str[0:10])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not cleaned.

#----------------------create window------------------
window_size=11
channel=3
window=create_window(window_size, channel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your window is not passed anywhere. It is a local variable in train.py

Comment on lines +67 to +74
def ssim_optimized(img1, img2, window=None, window_size=11, size_average=True):
channel = img1.size(-3)
if window is None:
window = create_window(window_size, channel).to(img1.device).type_as(img1)
if img1.is_cuda:
window = window.cuda(img1.get_device())
window = window.type_as(img1)
return _ssim(img1, img2, window, window_size, channel, size_average)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your window is always none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants