-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shakiba Kheradmand
committed
Nov 29, 2023
1 parent
6d6b273
commit ddf7ae1
Showing
7 changed files
with
339 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import torch | ||
import torch.nn as nn | ||
|
||
from nerfacc.losses import DistortionLoss | ||
class NeRFLoss(nn.Module): | ||
def __init__(self, lambda_opacity=0.0, lambda_distortion=0.01): | ||
super().__init__() | ||
|
||
self.lambda_opacity = lambda_opacity | ||
self.lambda_distortion = lambda_distortion | ||
|
||
def forward(self, rgb, target, opp=None, distkwargs=None): | ||
d = {} | ||
d['rgb'] = (rgb-target)**2 | ||
|
||
if self.lambda_opacity > 0: | ||
o = opp+torch.finfo(torch.float16).eps | ||
# encourage opacity to be either 0 or 1 to avoid floater | ||
d['opacity'] = self.lambda_opacity*(-o*torch.log(o)) | ||
|
||
if self.lambda_distortion > 0 and distkwargs is not None: | ||
d['distortion'] = self.lambda_distortion * \ | ||
DistortionLoss.apply(distkwargs['ws'], distkwargs['deltas'], | ||
distkwargs['ts'], distkwargs['rays_a']) | ||
|
||
return d |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import torch.optim.lr_scheduler as lr_scheduler | ||
|
||
def create_scheduler(optimizer_name, scheduler_type, max_steps, lr): | ||
if scheduler_type == "step": | ||
scheduler = lr_scheduler.StepLR( | ||
optimizer_name, step_size=1000, gamma=0.847 | ||
) | ||
elif scheduler_type == "cosineannealing": | ||
scheduler = lr_scheduler.ChainedScheduler( | ||
[ | ||
lr_scheduler.CosineAnnealingLR( | ||
optimizer_name, | ||
T_max=max_steps, | ||
eta_min=lr / 10 | ||
)]) | ||
elif scheduler_type == "chain": | ||
scheduler = lr_scheduler.ChainedScheduler( | ||
[ | ||
lr_scheduler.LinearLR( | ||
optimizer_name, start_factor=0.01, total_iters=100 | ||
), | ||
lr_scheduler.MultiStepLR( | ||
optimizer_name, | ||
milestones=[ | ||
max_steps // 2, | ||
max_steps * 3 // 4, | ||
max_steps * 9 // 10, | ||
], | ||
gamma=0.33, | ||
), | ||
] | ||
) | ||
elif scheduler_type == "none": | ||
scheduler = None | ||
else: | ||
raise ValueError(f"Invalid scheduler type: {scheduler_type}") | ||
|
||
return scheduler |
Oops, something went wrong.