Currently I am using a similar code to the following to create arguments that are used in my code. The problem with that is different functions only demand specific arguments not all of them. For example, when data is handled only --dataname
and --datapath
are used. Unfortunately, I have to pass all arguments as args
to every function and use only few of them. This makes the maintenance very difficult.
Questions:
- Is there any way for me to separate them out as
Architecture
,Dataset
,Initialization
, andOptimization
's arguments. - If so, how can I retrieve the ones that are asscociated with a different group.
- If so, is there still a way to use all of them at once?
import argparse
parser = argparse.ArgumentParser(
description='Comprehensive image classification')
# ===== Architecture ===== #
parser.add_argument('--arch', '-a', metavar='ARCH', default='resnet50')
parser.add_argument('--pretrained', dest='pretrained', action='store_true',
help='use pre-trained model')
# ===== Dataset ===== #
parser.add_argument('--dataname', default='imagenet', type=str,
help='mnist | cifar10 | cifar100| fashionmnist | imagenet')
parser.add_argument('--datapath', default = '/datasets/imagenet/',
metavar='DIR', help='path to dataset')
# ===== Initialization ===== #
parser.add_argument('--init-policy', default='kaimingn',
type=str, help='kaimingn | kaimingu | xaviern | xavieru')
parser.add_argument('--init-kaiming-mode', default='fan_in', type=str, help='fan_in | fan_out')
# ===== Optimization ======== #
parser.add_argument('--optimizer', '-o', default='SGD+M', type=str, help='SGD | SGD+M | Adam')
parser.add_argument('--epochs', default=90, type=int, metavar='N',
help='number of total epochs to run')
args = parser.parse_args()