Files
nerfstudio/nerfactory/optimizers/schedulers.py
T
Ethan Weberandevonneng 7e9a56fac4 Config restructure (#283)
* starting docs for pipelines

* working on an example

* clearing output

* starting to implement config changes and add documentation

* wip: removed cicular imports; porting basic config into python; todo: get python setups workin

* circular imports again

* wip: pausing at dataloader sort of working

* break for today

* running vanilla

* wip need to get all the config docs working

* laptop about to die

* instant ngp working

* added all configs for all methods; not tested yet: [mipnerf360, nerfw, semantic_nerf]

* unpacking later

* done with pylinting

* mostly done. just need to do docs and one test

* added import order to docs

* fixing near/far plane and other config things

* making loggers also instantiable via configs

* docs

* lint

* making --help work with dcargs

* moving configs back into flat

* convert list to tuples; fixed post init function with mutable params

* lint

* made run_eval and benchmarking scripts compatible with new config/dcargs

* lint

* added option to load configs from presaved config

Co-authored-by: evonneng <evonne_ng@berkeley.edu>
2022-08-26 17:25:10 -07:00

52 lines
2.0 KiB
Python

# Copyright 2022 The Plenoptix Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Scheduler Classes"""
import numpy as np
from torch.optim.lr_scheduler import LambdaLR
class ExponentialDecaySchedule(LambdaLR):
"""Exponential learning rate decay function.
See https://github.com/google-research/google-research/blob/
fd2cea8cdd86b3ed2c640cbe5561707639e682f3/jaxnerf/nerf/utils.py#L360
for details.
Args:
optimizer: The optimizer to update.
lr_init: The initial learning rate.
lr_final: The final learning rate.
max_steps: The maximum number of steps.
lr_delay_steps: The number of steps to delay the learning rate. Default is 0.
lr_delay_mult: The multiplier for the learning rate after the delay. Default is 1.0.
"""
def __init__(self, optimizer, lr_init, lr_final, max_steps, lr_delay_steps=0, lr_delay_mult=1.0) -> None:
def func(step):
if lr_delay_steps > 0:
delay_rate = lr_delay_mult + (1 - lr_delay_mult) * np.sin(
0.5 * np.pi * np.clip(step / lr_delay_steps, 0, 1)
)
else:
delay_rate = 1.0
t = np.clip(step / max_steps, 0, 1)
log_lerp = np.exp(np.log(lr_init) * (1 - t) + np.log(lr_final) * t)
multiplier = (
log_lerp / lr_init
) # divided by lr_init because the multiplier is with the initial learning rate
return delay_rate * multiplier
super().__init__(optimizer, lr_lambda=func)