Download smkd/utils/parameters.py from SignerX/SignX: direct link, hf CLI and curl.
- Browser
- Download file 7.61 kB
-
https://huggingface.co/datasets/SignerX/SignX/resolve/main/smkd/utils/parameters.py
- Command line
-
hf download hf://datasets/SignerX/SignX/smkd/utils/parameters.py
-
curl -L -o parameters.py https://huggingface.co/datasets/SignerX/SignX/resolve/main/smkd/utils/parameters.py
7.61 kB
| import argparse | |
| def get_parser(): | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # parameter priority: command line > config > default | |
| parser = argparse.ArgumentParser( | |
| description='The pytorch implementation for Visual Alignment Constraint ' | |
| 'for Continuous Sign Language Recognition.') | |
| parser.add_argument( | |
| '--work-dir', | |
| default='./work_dir/temp', | |
| help='the work folder for storing results') | |
| parser.add_argument( | |
| '--config', | |
| default='./configs/baseline.yaml', | |
| help='path to the configuration file') | |
| parser.add_argument( | |
| '--random_fix', | |
| type=str2bool, | |
| default=True, | |
| help='fix random seed or not') | |
| parser.add_argument( | |
| '--device', | |
| type=str, | |
| default=0, | |
| help='the indexes of GPUs for training or testing') | |
| parser.add_argument( | |
| '--num-feature-aug', | |
| type=int, | |
| default=-1, | |
| help='number of feature duplicates, by default -1 no duplication.') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # processor | |
| parser.add_argument( | |
| '--phase', default='train', help='can be train, test and features') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # debug | |
| parser.add_argument( | |
| '--save-interval', | |
| type=int, | |
| default=200, | |
| help='the interval for storing models (#epochs)') | |
| parser.add_argument( | |
| '--random-seed', | |
| type=int, | |
| default=0, | |
| help='the default value for random seed.') | |
| parser.add_argument( | |
| '--eval-interval', | |
| type=int, | |
| default=100, | |
| help='the interval for evaluating models (#epochs)') | |
| parser.add_argument( | |
| '--print-log', | |
| type=str2bool, | |
| default=True, | |
| help='print logging or not') | |
| parser.add_argument( | |
| '--log-interval', | |
| type=int, | |
| default=20, | |
| help='the interval for printing messages (#iteration)') | |
| parser.add_argument( | |
| '--evaluate-tool', default="python", help='sclite or python') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # feeder | |
| parser.add_argument( | |
| '--feeder', default='dataloader_video.BaseFeeder', help='data loader will be used') | |
| parser.add_argument( | |
| '--dataset', | |
| default=None, | |
| help='data loader will be used' | |
| ) | |
| parser.add_argument( | |
| '--dataset-info', | |
| default=dict(), | |
| help='data loader will be used' | |
| ) | |
| parser.add_argument( | |
| '--preprocess-sample-ratio', | |
| type=float, | |
| default=1.0, | |
| help='preprocess-only: fraction of manifest to sample (unused by training)') | |
| parser.add_argument( | |
| '--label-column', | |
| default='TEXT', | |
| help='preprocess-only: manifest label column (unused by training)') | |
| parser.add_argument( | |
| '--scale-update-cycle', | |
| type=str2bool, | |
| default=False, | |
| help='slt-only: scale update_cycle by GPU count (unused by SMKD)') | |
| parser.add_argument( | |
| '--dev-from-train-count', | |
| type=int, | |
| default=0, | |
| help='preprocess-only: override dev split with N samples from train (unused by training)') | |
| parser.add_argument( | |
| '--dev-from-train-keep', | |
| type=str2bool, | |
| default=False, | |
| help='preprocess-only: keep dev samples in train (unused by training)') | |
| parser.add_argument( | |
| '--eval-use-conv', | |
| type=str2bool, | |
| default=False, | |
| help='evaluate using conv head outputs instead of sequence head') | |
| parser.add_argument( | |
| '--debug-seq-topk', | |
| type=int, | |
| default=0, | |
| help='print top-k sequence head average probs on first eval batch (0 disables)') | |
| parser.add_argument( | |
| '--debug-conv-topk', | |
| type=int, | |
| default=0, | |
| help='print top-k conv head average probs on first eval batch (0 disables)') | |
| parser.add_argument( | |
| '--num-worker', | |
| type=int, | |
| default=4, | |
| help='the number of worker for data loader') | |
| parser.add_argument( | |
| '--feeder-args', | |
| default=dict(), | |
| help='the arguments of data loader') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # model | |
| parser.add_argument('--model', default=None, help='the model will be used') | |
| parser.add_argument( | |
| '--model-args', | |
| type=dict, | |
| default=dict(), | |
| help='the arguments of model') | |
| parser.add_argument( | |
| '--load-weights', | |
| default=None, | |
| help='load weights for network initialization') | |
| parser.add_argument( | |
| '--load-checkpoints', | |
| default=None, | |
| help='load checkpoints for continue training') | |
| parser.add_argument( | |
| '--decode-mode', | |
| default="max", | |
| help='search mode for decode, max or beam') | |
| parser.add_argument( | |
| '--ignore-weights', | |
| type=str, | |
| default=[], | |
| nargs='+', | |
| help='the name of weights which will be ignored in the initialization') | |
| parser.add_argument( | |
| '--skip-sample-file', | |
| default=None, | |
| help='path to a newline separated list of sample IDs to ignore') | |
| parser.add_argument( | |
| '--disable-bad-sample-filter', | |
| type=str2bool, | |
| default=False, | |
| help='set true to skip recording/removing samples with non-finite loss') | |
| parser.add_argument( | |
| '--debug-save-batch', | |
| type=str2bool, | |
| default=True, | |
| help='save first batch frames for debugging') | |
| parser.add_argument( | |
| '--debug-stats', | |
| type=str2bool, | |
| default=True, | |
| help='log first batch stats for debugging') | |
| parser.add_argument( | |
| '--debug-save-dir', | |
| default=None, | |
| help='override debug frame output directory') | |
| parser.add_argument( | |
| '--debug-stats-path', | |
| default=None, | |
| help='override debug stats output file path') | |
| parser.add_argument( | |
| '--debug-save-frames', | |
| type=int, | |
| default=8, | |
| help='max frames to save from first batch') | |
| parser.add_argument( | |
| '--debug-save-samples', | |
| type=int, | |
| default=1, | |
| help='max samples to save from first batch') | |
| # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # | |
| # optim | |
| parser.add_argument( | |
| '--batch-size', type=int, default=16, help='training batch size') | |
| parser.add_argument( | |
| '--test-batch-size', type=int, default=8, help='test batch size') | |
| default_optimizer_dict = { | |
| "base_lr": 1e-2, | |
| "optimizer": "SGD", | |
| "nesterov": False, | |
| "step": [5, 10], | |
| "weight_decay": 0.00005, | |
| "start_epoch": 1, | |
| } | |
| default_loss_dict = { | |
| "SeqCTC": 1.0, | |
| } | |
| parser.add_argument( | |
| '--loss-weights', | |
| default=default_loss_dict, | |
| help='loss selection' | |
| ) | |
| parser.add_argument( | |
| '--optimizer-args', | |
| default=default_optimizer_dict, | |
| help='the arguments of optimizer') | |
| parser.add_argument( | |
| '--num-epoch', | |
| type=int, | |
| default=80, | |
| help='stop training in which epoch') | |
| return parser | |
| def str2bool(v): | |
| if v.lower() in ('yes', 'true', 't', 'y', '1'): | |
| return True | |
| elif v.lower() in ('no', 'false', 'f', 'n', '0'): | |
| return False | |
| else: | |
| raise argparse.ArgumentTypeError('Boolean value expected.') | |