()
return parsed_args
command line arguments parser
    Returns: args => parsed command line arguments
command line arguments parser
    Returns: args => parsed command line arguments
command line arguments parser Returns : args = > parsed command line arguments
def parse_arguments() -> argparse.Namespace:
    """
    command line arguments parser
    Returns: args => parsed command line arguments
    """
    parser = argparse.ArgumentParser(
        "Train Progressively grown GAN",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )

    # fmt: off
    # Required arguments (input path to the data and the output directory for saving training assets)
    parser.add_argument("train_path", action="store", type=Path,
                        help="Path to the images folder for training the ProGAN")
    parser.add_argument("output_dir", action="store", type=Path,
                        help="Path to the directory for saving the logs and models")

    # Optional arguments
    # dataset related options:
    parser.add_argument("--rec_dir", action="store", type=str2bool, default=False, required=False,
                        help="whether images are stored under one folder or under a recursive dir structure")
    parser.add_argument("--flip_horizontal", action="store", type=str2bool, default=True, required=False,
                        help="whether to apply mirror (horizontal) augmentation")

    # model architecture related options:
    parser.add_argument("--depth", action="store", type=int, default=10, required=False,
                        help="depth of the generator and the discriminator. Starts from 2. "
                             "Example 2 --> (4x4) | 3 --> (8x8) ... | 10 --> (1024x1024)")
    parser.add_argument("--num_channels", action="store", type=int, default=3, required=False,
                        help="number of channels in the image data")
    parser.add_argument("--latent_size", action="store", type=int, default=512, required=False,
                        help="latent size of the generator and the discriminator")

    # training related options:
    parser.add_argument("--use_eql", action="store", type=str2bool, default=True, required=False,
                        help="whether to use the equalized learning rate")
    parser.add_argument("--use_ema", action="store", type=str2bool, default=True, required=False,
                        help="whether to use the exponential moving average of generator weights. "
                             "Keeps two copies of the generator model; an instantaneous one and "
                             "the averaged one.")
    parser.add_argument("--ema_beta", action="store", type=float, default=0.999, required=False,
                        help="value of the ema beta")
    parser.add_argument("--epochs", action="store", type=int, required=False, nargs="+",
                        default=[42 for _ in range(9)],
                        help="number of epochs over the training dataset per stage")
    parser.add_argument("--batch_sizes", action="store", type=int, required=False, nargs="+",
                        default=[32, 32, 32, 32, 16, 16, 8, 4, 2],
                        help="batch size used for training the model per stage")
    parser.add_argument("--batch_repeats", action="store", type=int, required=False, default=4,
                        help="number of G and D steps executed per training iteration")
    parser.add_argument("--fade_in_percentages", action="store", type=int, required=False, nargs="+",
                        default=[50 for _ in range(9)],
                        help="number of iterations for which fading of new layer happens. Measured in percentage")
    parser.add_argument("--loss_fn", action="store", type=str2GANLoss, required=False, default="wgan_gp",
                        help="loss function used for training the GAN. "
                             "Current options: [wgan_gp, standard_gan]")
    parser.add_argument("--g_lrate", action="store", type=float, required=False, default=0.003,
                        help="learning rate used by the generator")
    parser.add_argument("--d_lrate", action="store", type=float, required=False, default=0.003,
                        help="learning rate used by the discriminator")
    parser.add_argument("--num_feedback_samples", action="store", type=int, required=False, default=4,
                        help="number of samples used for fixed seed gan feedback")
    parser.add_argument("--start_depth", action="store", type=int, required=False, default=2,
                        help="resolution to start the training from. "
                             "Example 2 --> (4x4) | 3 --> (8x8) ... | 10 --> (1024x1024). "
                             "Note that this is not a way to restart a partial training. "
                             "Resuming is not supported currently. But will soon be.")
    parser.add_argument("--num_workers", action="store", type=int, required=False, default=4,
                        help="number of dataloader subprocesses. It's a pytorch thing, you can ignore it ;)."
                             " Leave it to the default value unless things are weirdly slow for you.")
    parser.add_argument("--feedback_factor", action="store", type=int, required=False, default=10,
                        help="number of feedback logs written per epoch")
    parser.add_argument("--checkpoint_factor", action="store", type=int, required=False, default=10,
                        help="number of epochs after which a model snapshot is saved per training stage")
    # fmt: on

    parsed_args = parser.parse_args()
    return parsed_args
def parse_arguments ( ) -> argparse . Namespace : parser = argparse . ArgumentParser ( "Train Progressively grown GAN" , formatter_class = argparse . ArgumentDefaultsHelpFormatter , ) # fmt: off # Required arguments (input path to the data and the output directory for saving training assets) parser . add_argument ( "train_path" , action = "store" , type = Path , help = "Path to the images folder for training the ProGAN" ) parser . add_argument ( "output_dir" , action = "store" , type = Path , help = "Path to the directory for saving the logs and models" ) # Optional arguments # dataset related options: parser . add_argument ( "--rec_dir" , action = "store" , type = str2bool , default = False , required = False , help = "whether images are stored under one folder or under a recursive dir structure" ) parser . add_argument ( "--flip_horizontal" , action = "store" , type = str2bool , default = True , required = False , help = "whether to apply mirror (horizontal) augmentation" ) # model architecture related options: parser . add_argument ( "--depth" , action = "store" , type = int , default = 10 , required = False , help = "depth of the generator and the discriminator. Starts from 2. " "Example 2 --> (4x4) | 3 --> (8x8) ... | 10 --> (1024x1024)" ) parser . add_argument ( "--num_channels" , action = "store" , type = int , default = 3 , required = False , help = "number of channels in the image data" ) parser . add_argument ( "--latent_size" , action = "store" , type = int , default = 512 , required = False , help = "latent size of the generator and the discriminator" ) # training related options: parser . add_argument ( "--use_eql" , action = "store" , type = str2bool , default = True , required = False , help = "whether to use the equalized learning rate" ) parser . add_argument ( "--use_ema" , action = "store" , type = str2bool , default = True , required = False , help = "whether to use the exponential moving average of generator weights. " "Keeps two copies of the generator model; an instantaneous one and " "the averaged one." ) parser . add_argument ( "--ema_beta" , action = "store" , type = float , default = 0.999 , required = False , help = "value of the ema beta" ) parser . add_argument ( "--epochs" , action = "store" , type = int , required = False , nargs = "+" , default = [ 42 for _ in range ( 9 ) ] , help = "number of epochs over the training dataset per stage" ) parser . add_argument ( "--batch_sizes" , action = "store" , type = int , required = False , nargs = "+" , default = [ 32 , 32 , 32 , 32 , 16 , 16 , 8 , 4 , 2 ] , help = "batch size used for training the model per stage" ) parser . add_argument ( "--batch_repeats" , action = "store" , type = int , required = False , default = 4 , help = "number of G and D steps executed per training iteration" ) parser . add_argument ( "--fade_in_percentages" , action = "store" , type = int , required = False , nargs = "+" , default = [ 50 for _ in range ( 9 ) ] , help = "number of iterations for which fading of new layer happens. Measured in percentage" ) parser . add_argument ( "--loss_fn" , action = "store" , type = str2GANLoss , required = False , default = "wgan_gp" , help = "loss function used for training the GAN. " "Current options: [wgan_gp, standard_gan]" ) parser . add_argument ( "--g_lrate" , action = "store" , type = float , required = False , default = 0.003 , help = "learning rate used by the generator" ) parser . add_argument ( "--d_lrate" , action = "store" , type = float , required = False , default = 0.003 , help = "learning rate used by the discriminator" ) parser . add_argument ( "--num_feedback_samples" , action = "store" , type = int , required = False , default = 4 , help = "number of samples used for fixed seed gan feedback" ) parser . add_argument ( "--start_depth" , action = "store" , type = int , required = False , default = 2 , help = "resolution to start the training from. " "Example 2 --> (4x4) | 3 --> (8x8) ... | 10 --> (1024x1024). " "Note that this is not a way to restart a partial training. " "Resuming is not supported currently. But will soon be." ) parser . add_argument ( "--num_workers" , action = "store" , type = int , required = False , default = 4 , help = "number of dataloader subprocesses. It's a pytorch thing, you can ignore it ;)." " Leave it to the default value unless things are weirdly slow for you." ) parser . add_argument ( "--feedback_factor" , action = "store" , type = int , required = False , default = 10 , help = "number of feedback logs written per epoch" ) parser . add_argument ( "--checkpoint_factor" , action = "store" , type = int , required = False , default = 10 , help = "number of epochs after which a model snapshot is saved per training stage" ) # fmt: on parsed_args = parser . parse_args ( ) return parsed_args