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
Li-xingXiao wants to merge 4 commits into
Conversation
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().
AsherJingkongChen
suggested changes
Oct 15, 2024
| 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]) |
| #----------------------create window------------------ | ||
| window_size=11 | ||
| channel=3 | ||
| window=create_window(window_size, channel) |
There was a problem hiding this comment.
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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().