Last active
June 30, 2021 18:22
-
-
Save eldar/9847e5ec85b1a6eebd7bddf32aca32ae to your computer and use it in GitHub Desktop.
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
class ConfConverter: | |
def __init__(self, filename): | |
self.filename = filename | |
self.f = open(filename, "w") | |
def __del__(self): | |
self.f.close() | |
def add_argument(self, name, type=None, default=None, required=None, choices=[], help="", nargs=None, action=None): | |
f = self.f | |
key = name.lstrip("--") | |
f.write(f"{key}: ") | |
if default is not None: | |
if nargs == "+": | |
vals = [str(v) for v in default] | |
if type == str: | |
vals = ['"' + v + '"' for v in default] | |
f.write("[" + ", ".join(vals) + "]") | |
elif type == int or type == float: | |
f.write(str(default)) | |
elif type == str: | |
f.write(f"\"" + default + "\"") | |
elif type == None: | |
if default == True: | |
f.write("true") | |
elif default == False: | |
f.write("false") | |
else: | |
assert False | |
if help: | |
help = help.replace("\n", " ") | |
help = " ".join(help.split()) | |
f.write(f" # {help}") | |
f.write("\n") | |
def parse_args(self): | |
pass |
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
root_dir: # root directory of dataset | |
dataset_name: "blender" # which dataset to train/val | |
data_perturb: [] # what perturbation to add to data. Available choices: [], ["color"], ["occ"] or ["color", "occ"] | |
img_wh: [800, 800] # resolution (img_w, img_h) of the image | |
img_downscale: 1 # how much to downscale the images for phototourism dataset | |
use_cache: false # whether to use ray cache (make sure img_downscale is the same) | |
N_emb_xyz: 10 # number of xyz embedding frequencies | |
N_emb_dir: 4 # number of direction embedding frequencies | |
N_samples: 64 # number of coarse samples | |
N_importance: 128 # number of additional fine samples | |
use_disp: false # use disparity depth sampling | |
perturb: 1.0 # factor to perturb depth sampling points | |
noise_std: 1.0 # std dev of noise added to regularize sigma | |
N_vocab: 100 # number of vocabulary (number of images) in the dataset for nn.Embedding | |
encode_a: false # whether to encode appearance (NeRF-A) | |
N_a: 48 # number of embeddings for appearance | |
encode_t: false # whether to encode transient object (NeRF-U) | |
N_tau: 16 # number of embeddings for transient objects | |
beta_min: 0.1 # minimum color variance for each ray | |
optimise_cameras: false # optimise camera poses | |
cameras_lr: 0.001 # learning rate | |
cameras_lr_exp_gamma: 0.794 # learning rate | |
barf: false # BARF-style annealing | |
barf_start_epoch: 4 # epoch to end annealing | |
barf_end_epoch: 8 # epoch to end annealing | |
batch_size: 1024 # batch size | |
chunk: 32768 # chunk size to split the input to avoid OOM | |
num_epochs: 16 # number of training epochs | |
num_gpus: 1 # number of gpus | |
ckpt_path: # pretrained checkpoint path to load | |
prefixes_to_ignore: ["loss"] # the prefixes to ignore in the checkpoint state dict | |
optimizer: "adam" # optimizer type | |
lr: 0.0005 # learning rate | |
lr_end: 0.0005 # learning rate | |
momentum: 0.9 # learning rate momentum | |
weight_decay: 0 # weight decay | |
lr_scheduler: "steplr" # scheduler type | |
warmup_multiplier: 1.0 # lr is multiplied by this factor after --warmup_epochs | |
warmup_epochs: 0 # Gradually warm-up(increasing) learning rate in optimizer | |
decay_step: [20] # scheduler decay step | |
decay_gamma: 0.1 # learning rate decay amount | |
poly_exp: 0.9 # exponent for polynomial learning rate decay | |
exp_name: "exp" # experiment name | |
refresh_every: 1 # print the progress bar every X steps |
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
# import argparse | |
from conf_converter import ConfConverter | |
def get_opts(): | |
# parser = argparse.ArgumentParser() | |
parser = ConvConverter("config.yaml") | |
parser.add_argument('--root_dir', type=str, required=True, | |
help='root directory of dataset') | |
parser.add_argument('--dataset_name', type=str, default='blender', | |
choices=['blender', 'phototourism', 'car'], | |
help='which dataset to train/val') | |
# for blender | |
parser.add_argument('--data_perturb', nargs="+", type=str, default=[], | |
help='''what perturbation to add to data. | |
Available choices: [], ["color"], ["occ"] or ["color", "occ"] | |
''') | |
parser.add_argument('--img_wh', nargs="+", type=int, default=[800, 800], | |
help='resolution (img_w, img_h) of the image') | |
# for phototourism | |
parser.add_argument('--img_downscale', type=int, default=1, | |
help='how much to downscale the images for phototourism dataset') | |
parser.add_argument('--use_cache', default=False, action="store_true", | |
help='whether to use ray cache (make sure img_downscale is the same)') | |
# original NeRF parameters | |
parser.add_argument('--N_emb_xyz', type=int, default=10, | |
help='number of xyz embedding frequencies') | |
parser.add_argument('--N_emb_dir', type=int, default=4, | |
help='number of direction embedding frequencies') | |
parser.add_argument('--N_samples', type=int, default=64, | |
help='number of coarse samples') | |
parser.add_argument('--N_importance', type=int, default=128, | |
help='number of additional fine samples') | |
parser.add_argument('--use_disp', default=False, action="store_true", | |
help='use disparity depth sampling') | |
parser.add_argument('--perturb', type=float, default=1.0, | |
help='factor to perturb depth sampling points') | |
parser.add_argument('--noise_std', type=float, default=1.0, | |
help='std dev of noise added to regularize sigma') | |
# NeRF-W parameters | |
parser.add_argument('--N_vocab', type=int, default=100, | |
help='''number of vocabulary (number of images) | |
in the dataset for nn.Embedding''') | |
parser.add_argument('--encode_a', default=False, action="store_true", | |
help='whether to encode appearance (NeRF-A)') | |
parser.add_argument('--N_a', type=int, default=48, | |
help='number of embeddings for appearance') | |
parser.add_argument('--encode_t', default=False, action="store_true", | |
help='whether to encode transient object (NeRF-U)') | |
parser.add_argument('--N_tau', type=int, default=16, | |
help='number of embeddings for transient objects') | |
parser.add_argument('--beta_min', type=float, default=0.1, | |
help='minimum color variance for each ray') | |
# BARF parameters | |
parser.add_argument('--optimise_cameras', default=False, action="store_true", | |
help='optimise camera poses') | |
parser.add_argument('--cameras_lr', type=float, default=1e-3, | |
help='learning rate') | |
parser.add_argument('--cameras_lr_exp_gamma', type=float, default=0.794, | |
help='learning rate') | |
parser.add_argument('--barf', default=False, action="store_true", | |
help='BARF-style annealing') | |
parser.add_argument('--barf_start_epoch', type=int, default=4, | |
help='epoch to end annealing') | |
parser.add_argument('--barf_end_epoch', type=int, default=8, | |
help='epoch to end annealing') | |
parser.add_argument('--batch_size', type=int, default=1024, | |
help='batch size') | |
parser.add_argument('--chunk', type=int, default=32*1024, | |
help='chunk size to split the input to avoid OOM') | |
parser.add_argument('--num_epochs', type=int, default=16, | |
help='number of training epochs') | |
parser.add_argument('--num_gpus', type=int, default=1, | |
help='number of gpus') | |
parser.add_argument('--ckpt_path', type=str, default=None, | |
help='pretrained checkpoint path to load') | |
parser.add_argument('--prefixes_to_ignore', nargs='+', type=str, default=['loss'], | |
help='the prefixes to ignore in the checkpoint state dict') | |
parser.add_argument('--optimizer', type=str, default='adam', | |
help='optimizer type', | |
choices=['sgd', 'adam', 'radam', 'ranger']) | |
parser.add_argument('--lr', type=float, default=5e-4, | |
help='learning rate') | |
parser.add_argument('--lr_end', type=float, default=5e-4, | |
help='learning rate') | |
parser.add_argument('--momentum', type=float, default=0.9, | |
help='learning rate momentum') | |
parser.add_argument('--weight_decay', type=float, default=0, | |
help='weight decay') | |
parser.add_argument('--lr_scheduler', type=str, default='steplr', | |
help='scheduler type', | |
choices=['steplr', 'cosine', 'poly', 'exp_interval']) | |
#### params for warmup, only applied when optimizer == 'sgd' or 'adam' | |
parser.add_argument('--warmup_multiplier', type=float, default=1.0, | |
help='lr is multiplied by this factor after --warmup_epochs') | |
parser.add_argument('--warmup_epochs', type=int, default=0, | |
help='Gradually warm-up(increasing) learning rate in optimizer') | |
########################### | |
#### params for steplr #### | |
parser.add_argument('--decay_step', nargs='+', type=int, default=[20], | |
help='scheduler decay step') | |
parser.add_argument('--decay_gamma', type=float, default=0.1, | |
help='learning rate decay amount') | |
########################### | |
#### params for poly #### | |
parser.add_argument('--poly_exp', type=float, default=0.9, | |
help='exponent for polynomial learning rate decay') | |
########################### | |
parser.add_argument('--exp_name', type=str, default='exp', | |
help='experiment name') | |
parser.add_argument('--refresh_every', type=int, default=1, | |
help='print the progress bar every X steps') | |
return parser.parse_args() | |
get_opts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment