I am on my way to study many of the Github repos of object detection. However, wherever I see, the train/eval code section in those repos are always presented in a command-line interface using Argument Parser. This is an example from a repo that Im studying:
parser.add_argument("--dataset_type", default="voc", type=str,
help='Specify dataset type. Currently support voc and open_images.')
parser.add_argument('--datasets', nargs='+', help='Dataset directory path')
parser.add_argument('--validation_dataset', help='Dataset directory path')
parser.add_argument('--balance_data', action='store_true',
help="Balance training data by down-sampling more frequent labels.")
parser.add_argument('--net', default="vgg16-ssd",
help="The network architecture, it can be mb1-ssd, mb1-lite-ssd, mb2-ssd-lite or vgg16-ssd.")
parser.add_argument('--freeze_base_net', action='store_true',
help="Freeze base net layers.")
parser.add_argument('--freeze_net', action='store_true',
help="Freeze all the layers except the prediction head.")
parser.add_argument('--mb2_width_mult', default=1.0, type=float,
help='Width Multiplifier for MobilenetV2')
I mean, why? the Argument Parser makes it really really hard to read the code and see where the variables go. In the code above, there are almost a hundred lines of those argument parsers code, and it really strains my eyes to see what argument is what. And isn’t Python syntax is convenient enough, just dump all the training params in to a config file? Why type out like 3 lines of terminal command every time you train something, and furthermore, why turn a convenient Python program into something that looks like command-line ffmpeg? Please anyone explain it to me.
3
However, wherever I see, the train/eval code section in those repos are always presented in a command-line interface using Argument Parser.
At least it is not a graphical user interface, obfuscated DLL, or something you have to run a web server to use. Command line interfaces are part of the legacy of the Unix philosophy of small, modular programs, in contrast to large monolithic programs.
Why type out like 3 lines of terminal command every time you train something, and furthermore, why turn a convenient Python program into something that looks like command-line ffmpeg?
It is common pattern for python code to have multiple interfaces, for example the argument parsing may be behind an if __name__=='__main__':
path for running from the command line, but the author may also expect others to import the module into their program and call the functions directly.
And isn’t Python syntax is convenient enough, just dump all the training params in to a config file?
Python is very dynamic so you can generally just pass your arguments to the optional parameter of argparse parse_args function from your own python code. https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args
the Argument Parser makes it really really hard to read the code and see where the variables go. In the code above, there are almost a hundred lines of those argument parsers code, and it really strains my eyes to see what argument is what.
Most of the parameters have defaults, the author is probably not expecting you to fill in every parameter. It is also possible that this interface is intended for their own testing purposes and they just expect you to call functions.