-
Notifications
You must be signed in to change notification settings - Fork 104
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
1 parent
7d56ffe
commit f8a300e
Showing
5 changed files
with
58 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#coding:utf-8 | ||
import os, sys | ||
import os.path as osp | ||
import numpy as np | ||
import torch | ||
from torch import nn | ||
from torch.optim import Optimizer | ||
from functools import reduce | ||
from torch.optim import AdamW | ||
|
||
class MultiOptimizer: | ||
def __init__(self, optimizers={}): | ||
self.optimizers = optimizers | ||
self.keys = list(optimizers.keys()) | ||
self.param_groups = reduce(lambda x,y: x+y, [v.param_groups for v in self.optimizers.values()]) | ||
|
||
def state_dict(self): | ||
state_dicts = [(key, self.optimizers[key].state_dict())\ | ||
for key in self.keys] | ||
return state_dicts | ||
|
||
def load_state_dict(self, state_dict): | ||
for key, val in state_dict: | ||
try: | ||
self.optimizers[key].load_state_dict(val) | ||
except: | ||
print("Unloaded %s" % key) | ||
|
||
def step(self, key=None, scaler=None): | ||
keys = [key] if key is not None else self.keys | ||
_ = [self._step(key, scaler) for key in keys] | ||
|
||
def _step(self, key, scaler=None): | ||
if scaler is not None: | ||
scaler.step(self.optimizers[key]) | ||
scaler.update() | ||
else: | ||
self.optimizers[key].step() | ||
|
||
def zero_grad(self, key=None): | ||
if key is not None: | ||
self.optimizers[key].zero_grad() | ||
else: | ||
_ = [self.optimizers[key].zero_grad() for key in self.keys] |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
for i in logs/blender_chair_posXYZ_posVIEW_fine1024_log2T19_lr0.0005_decay500/*.tar; do | ||
CUDA_VISIBLE_DEVICES=2 python run_nerf.py --config configs/chair.txt --finest_res 1024 --i_embed 0 --i_embed_views 0 --render_only --ft_path $i | ||
for i in logs/blender_hotdog_hashXYZ_sphereVIEW_fine1024_log2T19_lr0.01_decay10/*.tar; do | ||
CUDA_VISIBLE_DEVICES=3 python run_nerf.py --config configs/hotdog.txt --finest_res 1024 --lr 0.01 --lr_decay 10 --render_only --ft_path $i | ||
done |