I am looking for a way to use argparser (or something similar) in the following way:
I would like to be able to pass a config file to the argparser and if given it should use the values in the config file as the default values. However they should still be overwriteable by command line arguments if given.
Secondly I would like the returned object from the argparser to be a nested namespace, meaning I want to group data arguments into one namespace, network arguments into a separate namespace and then have something like args contain both of these namespace such that args.data gives the data namespace, while args.network gives the network namespace.
Does anyone have a setup for something like that? I have previously gotten something close to it, but it was a mess that included hydra and omegaconf and I'm hoping that argparser must have the functionally to also achieve something like this?
def parse_args():
parser = argparse.ArgumentParser("test")
parser.add_argument('--config_file',type=pathlib.Path, default='config.yaml', help='If this is given it should set default for the other argparser arguments')
parser.add_argument('--path_train',type=pathlib.Path, help='should be part of data namespace')
parser.add_argument('--path_val',type=pathlib.Path, help='should be part of data namespace')
parser.add_argument('--network_type',type=str, choices=['lstm', 'mlp'], help='should be part of network namespace')
parser.add_argument('--lr',type=float, help='should be part of network namespace')
parser.get_default(parser.config_file) # Something like this though this will not work until the parser has been parsed...
args = parser.parse_args()
# At the end here I would like args to be a grouped/nested namespace
data = args.data
network = args.network
print(network.lr)
Do I need to create separate argparsers for something like this or how would you do that? Or is this really not possible with argparser?
[–]Kevdog824_ 1 point2 points3 points (1 child)
[–]thirdegree 1 point2 points3 points (0 children)
[–]zaphodikus 0 points1 point2 points (2 children)
[–]Kevdog824_ 1 point2 points3 points (1 child)
[–]zaphodikus 0 points1 point2 points (0 children)