Last active
December 21, 2020 18:33
-
-
Save sengstacken/5b44d7da3d716f23e9244ec4af758f0f to your computer and use it in GitHub Desktop.
How to parse arguments in python
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 | |
| def parse_args(): | |
| parser = argparse.ArgumentParser() | |
| # hyperparameters sent by the client are passed as command-line arguments to the script | |
| parser.add_argument('--epochs', type=int, default=1) | |
| parser.add_argument('--batch_size', type=int, default=64) | |
| # data directories | |
| parser.add_argument('--train', type=str, default=os.environ.get('SM_CHANNEL_TRAINING')) | |
| parser.add_argument('--test', type=str, default=os.environ.get('SM_CHANNEL_VALIDATION')) | |
| # model directory: we will use the default set by SageMaker, /opt/ml/model | |
| parser.add_argument('--model_dir', type=str, default=os.environ.get('SM_MODEL_DIR')) | |
| return parser.parse_known_args() | |
| args, _ = parse_args() | |
| print(args.__dict__) | |
| print(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment