Python argparse.ArgumentDefaultsHelpFormatter() Examples

The following are code examples for showing how to use argparse.ArgumentDefaultsHelpFormatter(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: DnD4py   Author: bacook17   File: lookup_5e.py    MIT License 6 votes vote down vote up
def monster_lookup():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=(
            """Searches Roll20.net 5e monster compendium for the term queried."""))
    parser.add_argument('query', nargs='+', help='The words to search')

    args = parser.parse_args()
    text = ' '.join(args.query)

    try:
        item = Roll20Monster(text)
    except IOError as e:
        print(e)
        item = None
    if item is None or len(item) == 0:
        return False
    else:
        try:
            print(item)
        except UnicodeEncodeError:
            print(item.as_unicode)
        return True 
Example 2
Project: DnD4py   Author: bacook17   File: lookup_5e.py    MIT License 6 votes vote down vote up
def item_lookup():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=(
            """Searches Roll20.net 5e Item compendium for the term queried."""))
    parser.add_argument('query', nargs='+', help='The words to search')

    args = parser.parse_args()
    text = ' '.join(args.query)
    
    try:
        item = Roll20Item(text)
    except IOError as e:
        print(e)
        item = None
    if item is None or len(item) == 0:
        return False
    else:
        try:
            print(item)
        except UnicodeEncodeError:
            print(item.as_unicode)
        return True 
Example 3
Project: simple-v-microbiome   Author: geoffrosen   File: trim_to_exact_level.py    MIT License 6 votes vote down vote up
def main():
	parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	parser.add_argument('-i','--input-fp',help='qiimeToMaaslin.py output file', type=str, required=True)
	parser.add_argument('-o','--output-fp',help='Location for file to be written to', type=str, required=True)
	parser.add_argument('-s','--separator',help='Character/string that marks separation of taxa levels', type=str, default="|")
	parser.add_argument('-r','--row',help='Row index (starting at zero) that marks the last metadata row', type=int, required=True)
	parser.add_argument('-t','--taxa-level',help='Number of level that you would like to retain (starting from one)', type=int, required=True)
	parser.add_argument('-l','--leaves-only',help='Output only leaves', action='store_true', default=False)
	args = parser.parse_args()
	with open(args.input_fp, 'rU') as input_file, open(args.output_fp, 'wb') as output_file:
		input_reader = csv.reader(input_file, delimiter='\t')
		output_writer = csv.writer(output_file, delimiter='\t')
		for i in range(args.row):
			output_writer.writerow(input_reader.next())
		if args.leaves_only:
			for remaining_row in input_reader:
				this_tax = remaining_row[0].split(args.separator)
				if len(this_tax) == args.taxa_level:
					this_name = this_tax[args.taxa_level -1]
					output_writer.writerow([this_name] + remaining_row[1:])
		else:
			for remaining_row in input_reader:
				this_tax = remaining_row[0].split(args.separator)
				if len(this_tax) == args.taxa_level:
					output_writer.writerow(remaining_row) 
Example 4
Project: simple-v-microbiome   Author: geoffrosen   File: fix_after_qiimeToMaaslin.py    MIT License 6 votes vote down vote up
def main():
	parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	parser.add_argument('-i','--input-fp',help='qiimeToMaaslin.py output file', type=str, required=True)
	parser.add_argument('-o','--output-fp',help='Location for file to be written to', type=str, required=True)
	args = parser.parse_args()
	with open(args.input_fp, 'rU') as input_file, open(args.output_fp, 'wb') as output_file:
		input_reader = csv.reader(input_file, delimiter='\t')
		output_writer = csv.writer(output_file, delimiter='\t')
		start = False
		while not start:
			row = input_reader.next()
			if row[0].find("sample") != -1:
				start = True
				output_writer.writerow(row)
		for row in input_reader:
			output_writer.writerow(row) 
Example 5
Project: simple-v-microbiome   Author: geoffrosen   File: prepare_for_qiimeToMaaslin.py    MIT License 6 votes vote down vote up
def main():
	parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	parser.add_argument('-i','--input-fp',help='File that will be going to qiimeToMaaslin.py', type=str, required=True)
	parser.add_argument('-o','--output-fp',help='Location for file to be written to', type=str, required=True)
	args = parser.parse_args()
	with open(args.input_fp, 'rU') as input_file, open(args.output_fp, 'wb') as output_file:
		input_reader = csv.reader(input_file, delimiter='\t')
		output_writer = csv.writer(output_file, delimiter='\t')
		output_writer.writerow(input_reader.next())
		base_addition = "Script Added "
		current_zero = 0
		last_addition = "None"
		for row in input_reader:
			if row[0].strip() == "":
				row[0] = base_addition + str(current_zero)
				current_zero += 1
			if row[-1].strip() == "":
				row[-1] = last_addition
			if row[-1].strip().startswith(";"):
				row[-1] = row[-1][row[-1].find(";") + 1:]
			if row[-1].strip().endswith(";"):
				row[-1] = row[-1][:row[-1].rfind(";")]
			row[-1] = row[-1].replace(";","|")
			output_writer.writerow(row) 
Example 6
Project: utilities   Author: czbiohub   File: 10x_mkfastq.py    MIT License 6 votes vote down vote up
def get_parser():
    parser = argparse.ArgumentParser(
        prog="10x_mkfastq.py", formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument("--exp_id", required=True)

    parser.add_argument("--s3_input_dir", default="s3://czbiohub-seqbot/bcl")
    parser.add_argument("--s3_output_dir", default="s3://czb-seqbot/fastqs")
    parser.add_argument("--s3_report_dir", default="s3://czb-seqbot/reports")
    parser.add_argument(
        "--s3_sample_sheet_dir", default="s3://czb-seqbot/sample-sheets"
    )

    parser.add_argument(
        "--sample_sheet_name", default=None, help="Defaults to [exp_id].csv"
    )
    parser.add_argument("--root_dir", default="/mnt")

    return parser 
Example 7
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: diagnose.py    Apache License 2.0 6 votes vote down vote up
def parse_args():
    """Parse arguments."""
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description='Diagnose script for checking the current system.')
    choices = ['python', 'pip', 'mxnet', 'os', 'hardware', 'network']
    for choice in choices:
        parser.add_argument('--' + choice, default=1, type=int,
                            help='Diagnose {}.'.format(choice))
    parser.add_argument('--region', default='', type=str,
                        help="Additional sites in which region(s) to test. \
                        Specify 'cn' for example to test mirror sites in China.")
    parser.add_argument('--timeout', default=10, type=int,
                        help="Connection test timeout threshold, 0 to disable.")
    args = parser.parse_args()
    return args 
Example 8
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: imagenet.py    Apache License 2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Setup the ImageNet dataset.',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', required=True,
                        help="The directory that contains downloaded tar files")
    parser.add_argument('--target-dir', default=_TARGET_DIR,
                        help="The directory to store extracted images")
    parser.add_argument('--checksum', action='store_true',
                        help="If check integrity before extracting.")
    parser.add_argument('--with-rec', action='store_true',
                        help="If build image record files.")
    parser.add_argument('--num-thread', type=int, default=1,
                        help="Number of threads to use when building image record file.")
    args = parser.parse_args()
    return args 
Example 9
Project: Manga-colorization---cycle-gan   Author: OValery16   File: base_options.py    Mozilla Public License 2.0 6 votes vote down vote up
def gather_options(self):
        # initialize parser with basic options
        if not self.initialized:
            parser = argparse.ArgumentParser(
                formatter_class=argparse.ArgumentDefaultsHelpFormatter)
            parser = self.initialize(parser)

        # get the basic options
        opt, _ = parser.parse_known_args()

        # modify model-related parser options
        model_name = opt.model
        model_option_setter = models.get_option_setter(model_name)
        parser = model_option_setter(parser, self.isTrain)
        opt, _ = parser.parse_known_args()  # parse again with the new defaults

        # modify dataset-related parser options
        dataset_name = opt.dataset_mode
        dataset_option_setter = data.get_option_setter(dataset_name)
        parser = dataset_option_setter(parser, self.isTrain)

        self.parser = parser

        return parser.parse_args() 
Example 10
Project: pcfg-sampling   Author: wilkeraziz   File: binarizable.py    Apache License 2.0 6 votes vote down vote up
def argparser():
    """parse command line arguments"""

    parser = argparse.ArgumentParser(prog='parse')

    parser.description = 'Binarizable permutations'
    parser.formatter_class = argparse.ArgumentDefaultsHelpFormatter

    parser.add_argument('input', nargs='?', 
            type=argparse.FileType('r'), default=sys.stdin,
            help='input corpus (one sentence per line)')
    #parser.add_argument('output', nargs='?', 
    #        type=argparse.FileType('w'), default=sys.stdout,
    #        help='parse trees')
    parser.add_argument('--show-permutations', 
            action='store_true',
            help='enumerate permutations (use with care)')
    parser.add_argument('--verbose', '-v',
            action='store_true',
            help='increase the verbosity level')

    return parser 
Example 11
Project: pcfg-sampling   Author: wilkeraziz   File: itg-parse.py    Apache License 2.0 6 votes vote down vote up
def argparser():
    """parse command line arguments"""

    parser = argparse.ArgumentParser(prog='parse')

    parser.description = 'Earley parser'
    parser.formatter_class = argparse.ArgumentDefaultsHelpFormatter

    parser.add_argument('grammar',  
            type=argparse.FileType('r'), 
            help='CFG rules')
    parser.add_argument('input', nargs='?', 
            type=argparse.FileType('r'), default=sys.stdin,
            help='input corpus (one sentence per line)')
    parser.add_argument('--show-permutations',
            action='store_true',
            help='dumps all permutations (use with caution)')
    parser.add_argument('--verbose', '-v',
            action='store_true',
            help='increase the verbosity level')

    return parser 
Example 12
Project: docker-pyftpdlib   Author: andriykohut   File: ftpd.py    MIT License 6 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument(
        '--user', default='user',
        help="Username for FTP acess (user will be created)")
    parser.add_argument('--password', default='password',
                        help="Password for FTP user.")
    parser.add_argument('--host', default='0.0.0.0')
    parser.add_argument('--port', type=int, default=21)
    parser.add_argument('--passive', default='3000-3010',
                        help="Range of passive ports")
    parser.add_argument('--anon', action='store_true',
                        help="Allow anonymous access")
    args = parser.parse_args()
    run_ftpd(**vars(args)) 
Example 13
Project: GCE-Model   Author: elnaaz   File: train.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_args():
    parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
    parser.add_argument('--dexp', help='root experiment folder', default='exp')
    parser.add_argument('--data', help='dataset', default='woz', choices=['woz', 'multi_woz'])
    parser.add_argument('--model', help='which model to use', default='gce', choices=get_models())
    # parser.add_argument('--use_elmo', help='use elmo embeddings', action='store_true')
    # parser.add_argument('--encoder', help='which encoder to use', default='GLADEncoder', choices=GLAD_ENCODERS)
    parser.add_argument('--epoch', help='max epoch to run for', default=50, type=int)
    parser.add_argument('--demb', help='word embedding size', default=400, type=int)
    parser.add_argument('--dhid', help='hidden state size', default=200, type=int)
    parser.add_argument('--batch_size', help='batch size', default=50, type=int)
    parser.add_argument('--lr', help='learning rate', default=1e-3, type=float)
    parser.add_argument('--stop', help='slot to early stop on', default='joint_goal')
    parser.add_argument('--resume', help='save directory to resume from')
    parser.add_argument('-n', '--nick', help='nickname for model', default='default')
    parser.add_argument('--seed', default=42, help='random seed', type=int)
    parser.add_argument('--test', action='store_true', help='run in evaluation only mode')
    parser.add_argument('--gpu', type=int, help='which GPU to use')
    parser.add_argument('--dropout', nargs='*', help='dropout rates', default=['emb=0.2', 'local=0.2', 'global=0.2'])
    args = parser.parse_args()
    args.dout = os.path.join(args.dexp, args.data, args.model, args.nick)
    args.dropout = {d.split('=')[0]: float(d.split('=')[1]) for d in args.dropout}
    if not os.path.isdir(args.dout):
        os.makedirs(args.dout)
    return args 
Example 14
Project: nlp-notebooks   Author: eric-haibin-lin   File: predict_ner.py    Apache License 2.0 6 votes vote down vote up
def parse_args():
    """Parse command line arguments."""
    arg_parser = argparse.ArgumentParser(
        description='Predict on CoNLL format data using BERT-based named entity recognition model',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    # data file paths
    arg_parser.add_argument('--test-path', type=str, required=True,
                            help='Path to the test data file')
    arg_parser.add_argument('--seq-len', type=int, default=200,
                            help='The length of the sequence input to BERT.'
                                 ' An exception will raised if this is not large enough.')
    arg_parser.add_argument('--load-checkpoint-prefix', type=str, required=False, default=None,
                            help='Prefix of model checkpoint file')

    arg_parser.add_argument('--gpu', type=int,
                            help='Number (index) of GPU to run on, e.g. 0. '
                                 'If not specified, CPU context is used.')
    arg_parser.add_argument('--batch-size', type=int, default=32, help='Batch size for training')
    args = arg_parser.parse_args()
    return args 
Example 15
Project: meta-transfer-learning   Author: erfaneshrati   File: args.py    MIT License 5 votes vote down vote up
def argument_parser():
    """
    Get an argument parser for a training script.
    """
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--pretrained', help='evaluate a pre-trained model',
                        action='store_true', default=False)
    parser.add_argument('--seed', help='random seed', default=0, type=int)
    parser.add_argument('--checkpoint', help='checkpoint directory', default='model_checkpoint')
    parser.add_argument('--classes', help='number of classes per inner task', default=5, type=int)
    parser.add_argument('--shots', help='number of examples per class', default=5, type=int)
    parser.add_argument('--train-shots', help='shots in a training batch', default=0, type=int)
    parser.add_argument('--inner-batch', help='inner batch size', default=5, type=int)
    parser.add_argument('--inner-iters', help='inner iterations', default=20, type=int)
    parser.add_argument('--replacement', help='sample with replacement', action='store_true')
    parser.add_argument('--learning-rate', help='Adam step size', default=1e-3, type=float)
    parser.add_argument('--meta-step', help='meta-training step size', default=0.1, type=float)
    parser.add_argument('--meta-step-final', help='meta-training step size by the end',
                        default=0.1, type=float)
    parser.add_argument('--meta-batch', help='meta-training batch size', default=1, type=int)
    parser.add_argument('--meta-iters', help='meta-training iterations', default=400000, type=int)
    parser.add_argument('--eval-batch', help='eval inner batch size', default=5, type=int)
    parser.add_argument('--eval-iters', help='eval inner iterations', default=50, type=int)
    parser.add_argument('--eval-samples', help='evaluation samples', default=100, type=int)
    parser.add_argument('--eval-interval', help='train steps per eval', default=1000, type=int)
    parser.add_argument('--weight-decay', help='weight decay rate', default=1, type=float)
    parser.add_argument('--transductive', help='evaluate all samples at once', action='store_true')
    parser.add_argument('--foml', help='use FOML instead of Reptile', action='store_true')
    parser.add_argument('--foml-tail', help='number of shots for the final mini-batch in FOML',
                        default=None, type=int)
    parser.add_argument('--sgd', help='use vanilla SGD instead of Adam', action='store_true')
    parser.add_argument('--metatransfer', help='use meta transfer learning approach', action='store_true')
    parser.add_argument('--gpu', help='gpu id', default=0, type=int)
    return parser 
Example 16
Project: DnD4py   Author: bacook17   File: lookup_5e.py    MIT License 5 votes vote down vote up
def spell_lookup():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=(
            """Searches Roll20.net 5e Spell compendium for the term queried."""))
    parser.add_argument('--ds',
                        help='Parse as dungeonsheets class', action='store_true')
    parser.add_argument('query', nargs='+', help='The words to search')

    args = parser.parse_args()
    text = ' '.join(args.query)
    
    try:
        item = DnDSpell(text)
#         item = Roll20Spell(text)
    except IOError as e:
        print(e)
        item = None
    if item is None or len(item) == 0:
        return False
    else:
        try:
            if args.ds:
                print(item.as_dungeonsheets_class())
            else:
                print(item)
        except UnicodeEncodeError:
            print(item.as_unicode)
        return True 
Example 17
Project: DnD4py   Author: bacook17   File: lookup_5e.py    MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description=(
            """Searches Roll20.net 5e compendium for the term queried."""))

    parser.add_argument('--monster',
                        help='Search only monster lists', action='store_true')
    parser.add_argument('--spell',
                        help='Search only spell lists', action='store_true')
    parser.add_argument('--item',
                        help='Search only item lists', action='store_true')
    parser.add_argument('query', nargs='+', help='The words to search')

    args = parser.parse_args()
    text = ' '.join(args.query)

    item = None
    if args.monster:
        item = Roll20Monster(text)
    elif args.spell:
        item = Roll20Spell(text)
    elif args.item:
        item = Roll20Item(text)
    else:
        for r in [Roll20Monster, Roll20Spell,
                  Roll20Item, Roll20]:
            try:
                item = r(text)
            except IOError as e:
                continue
            else:
                break
    if item is None or len(item) == 0:
        print('Not Found')
    else:
        try:
            print(item)
        except UnicodeEncodeError:
            print(item.as_unicode) 
Example 18
Project: utilities   Author: czbiohub   File: template.py    MIT License 5 votes vote down vote up
def get_parser():
    """
    Required: Define the arguments your script takes in this function,
    so that evros can test them before launching a job
    """
    parser = argparse.ArgumentParser(
        prog="template.py", formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument("--message", default="Hello world!")

    return parser 
Example 19
Project: utilities   Author: czbiohub   File: 10x_count.py    MIT License 5 votes vote down vote up
def get_parser():
    parser = argparse.ArgumentParser(
        prog="10x_count.py", formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    parser.add_argument("--s3_input_dir", required=True)
    parser.add_argument("--s3_output_dir", required=True)
    parser.add_argument(
        "--taxon", required=True, choices=list(reference_genomes.keys())
    )
    parser.add_argument("--cell_count", type=int, default=3000)

    parser.add_argument("--dobby", action="store_true",
                        help="Use if 10x run was demuxed locally (post November 2019)")

    parser.add_argument(
        "--region",
        default="west",
        choices=("east", "west"),
        help=(
            "Region you're running jobs in."
            " Should match the location of"
            " the fastq.gz files"
        ),
    )

    parser.add_argument("--glacier", action="store_true")
    parser.add_argument("--root_dir", default="/mnt")

    return parser 
Example 20
Project: utilities   Author: czbiohub   File: gene_cell_table.py    MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(
        description=(
            "Construct the gene-cell table for an experiment\n"
            "e.g. gene_cell_table"
            " s3://bucket-name/path/to/results path/to/output.csv"
        ),
        epilog="See https://github.com/czbiohub/utilities for more examples",
        add_help=False,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )

    # basic usage
    basic_group = parser.add_argument_group("basic arguments")
    basic_group.add_argument("s3_input_path", help="Location of data on S3")
    basic_group.add_argument(
        "output_file", help="File to save the output, e.g. my_gc_table[.csv,.h5ad]"
    )

    # other arguments
    other_group = parser.add_argument_group("other options")
    other_group.add_argument(
        "--no_log", action="store_true", help="Don't try to download log files"
    )
    other_group.add_argument(
        "--dryrun", action="store_true", help="Don't actually download any files"
    )
    other_group.add_argument(
        "--debug", action="store_true", help="Set logging to debug level"
    )
    other_group.add_argument(
        "-h", "--help", action="help", help="Show this help message and exit"
    )

    args = parser.parse_args()

    main_logger, _lf, _fh = get_logger(__name__, args.debug, args.dryrun)

    gene_cell_table(args, main_logger, args.dryrun) 
Example 21
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: train_cifar10.py    Apache License 2.0 5 votes vote down vote up
def prepare_args():
    # parse args
    parser = argparse.ArgumentParser(description="train cifar10",
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    fit.add_fit_args(parser)
    data.add_data_args(parser)
    data.add_data_aug_args(parser)
    # uncomment to set standard cifar augmentations
    # set_cifar_aug(parser)
    parser.set_defaults(
        # network
        network        = 'resnet',
        num_layers     = 110,
        # data
        data_train     = train_fname,
        data_val       = val_fname,
        num_classes    = 10,
        num_examples  = 50000,
        image_shape    = '3,28,28',
        pad_size       = 4,
        # train
        batch_size     = 128,
        num_epochs     = 300,
        lr             = .05,
        lr_step_epochs = '200,250',
    )
    return parser.parse_args(), fit, data 
Example 22
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: lstm_sort.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description="Parse args for lstm_sort example",
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--start-range', type=int, default=100,
                        help='starting number of the range')
    parser.add_argument('--end-range', type=int, default=1000,
                        help='Ending number of the range')
    parser.add_argument('--cpu', action='store_true',
                        help='To use CPU for training')
    return parser.parse_args() 
Example 23
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: demo.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description='Demonstrate a Faster R-CNN network',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--network', type=str, default='vgg16', help='base network')
    parser.add_argument('--params', type=str, default='', help='path to trained model')
    parser.add_argument('--dataset', type=str, default='voc', help='training dataset')
    parser.add_argument('--image', type=str, default='', help='path to test image')
    parser.add_argument('--gpu', type=str, default='', help='gpu device eg. 0')
    parser.add_argument('--vis', action='store_true', help='display results')
    parser.add_argument('--vis-thresh', type=float, default=0.7, help='threshold display boxes')
    # faster rcnn params
    parser.add_argument('--img-short-side', type=int, default=600)
    parser.add_argument('--img-long-side', type=int, default=1000)
    parser.add_argument('--img-pixel-means', type=str, default='(0.0, 0.0, 0.0)')
    parser.add_argument('--img-pixel-stds', type=str, default='(1.0, 1.0, 1.0)')
    parser.add_argument('--rpn-feat-stride', type=int, default=16)
    parser.add_argument('--rpn-anchor-scales', type=str, default='(8, 16, 32)')
    parser.add_argument('--rpn-anchor-ratios', type=str, default='(0.5, 1, 2)')
    parser.add_argument('--rpn-pre-nms-topk', type=int, default=6000)
    parser.add_argument('--rpn-post-nms-topk', type=int, default=300)
    parser.add_argument('--rpn-nms-thresh', type=float, default=0.7)
    parser.add_argument('--rpn-min-size', type=int, default=16)
    parser.add_argument('--rcnn-num-classes', type=int, default=21)
    parser.add_argument('--rcnn-feat-stride', type=int, default=16)
    parser.add_argument('--rcnn-pooled-size', type=str, default='(14, 14)')
    parser.add_argument('--rcnn-batch-size', type=int, default=1)
    parser.add_argument('--rcnn-bbox-stds', type=str, default='(0.1, 0.1, 0.2, 0.2)')
    parser.add_argument('--rcnn-nms-thresh', type=float, default=0.3)
    parser.add_argument('--rcnn-conf-thresh', type=float, default=1e-3)
    args = parser.parse_args()
    args.img_pixel_means = ast.literal_eval(args.img_pixel_means)
    args.img_pixel_stds = ast.literal_eval(args.img_pixel_stds)
    args.rpn_anchor_scales = ast.literal_eval(args.rpn_anchor_scales)
    args.rpn_anchor_ratios = ast.literal_eval(args.rpn_anchor_ratios)
    args.rcnn_pooled_size = ast.literal_eval(args.rcnn_pooled_size)
    args.rcnn_bbox_stds = ast.literal_eval(args.rcnn_bbox_stds)
    return args 
Example 24
Project: dynamic-training-with-apache-mxnet-on-aws   Author: awslabs   File: test.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description='Test a Faster R-CNN network',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--network', type=str, default='vgg16', help='base network')
    parser.add_argument('--params', type=str, default='', help='path to trained model')
    parser.add_argument('--dataset', type=str, default='voc', help='training dataset')
    parser.add_argument('--imageset', type=str, default='', help='imageset splits')
    parser.add_argument('--gpu', type=int, default=0, help='gpu device eg. 0')
    # faster rcnn params
    parser.add_argument('--img-short-side', type=int, default=600)
    parser.add_argument('--img-long-side', type=int, default=1000)
    parser.add_argument('--img-pixel-means', type=str, default='(0.0, 0.0, 0.0)')
    parser.add_argument('--img-pixel-stds', type=str, default='(1.0, 1.0, 1.0)')
    parser.add_argument('--rpn-feat-stride', type=int, default=16)
    parser.add_argument('--rpn-anchor-scales', type=str, default='(8, 16, 32)')
    parser.add_argument('--rpn-anchor-ratios', type=str, default='(0.5, 1, 2)')
    parser.add_argument('--rpn-pre-nms-topk', type=int, default=6000)
    parser.add_argument('--rpn-post-nms-topk', type=int, default=300)
    parser.add_argument('--rpn-nms-thresh', type=float, default=0.7)
    parser.add_argument('--rpn-min-size', type=int, default=16)
    parser.add_argument('--rcnn-num-classes', type=int, default=21)
    parser.add_argument('--rcnn-feat-stride', type=int, default=16)
    parser.add_argument('--rcnn-pooled-size', type=str, default='(14, 14)')
    parser.add_argument('--rcnn-batch-size', type=int, default=1)
    parser.add_argument('--rcnn-bbox-stds', type=str, default='(0.1, 0.1, 0.2, 0.2)')
    parser.add_argument('--rcnn-nms-thresh', type=float, default=0.3)
    parser.add_argument('--rcnn-conf-thresh', type=float, default=1e-3)
    args = parser.parse_args()
    args.img_pixel_means = ast.literal_eval(args.img_pixel_means)
    args.img_pixel_stds = ast.literal_eval(args.img_pixel_stds)
    args.rpn_anchor_scales = ast.literal_eval(args.rpn_anchor_scales)
    args.rpn_anchor_ratios = ast.literal_eval(args.rpn_anchor_ratios)
    args.rcnn_pooled_size = ast.literal_eval(args.rcnn_pooled_size)
    args.rcnn_bbox_stds = ast.literal_eval(args.rcnn_bbox_stds)
    return args 
Example 25
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: finetune_minc.py    Apache License 2.0 5 votes vote down vote up
def parse_opts():
    parser = argparse.ArgumentParser(description='Transfer learning on MINC-2500 dataset',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--data', type=str, default='',
                        help='directory for the prepared data folder')
    parser.add_argument('--model', required=True, type=str,
                        help='name of the pretrained model from model zoo.')
    parser.add_argument('-j', '--workers', dest='num_workers', default=4, type=int,
                        help='number of preprocessing workers')
    parser.add_argument('--num-gpus', default=0, type=int,
                        help='number of gpus to use, 0 indicates cpu only')
    parser.add_argument('--epochs', default=40, type=int,
                        help='number of training epochs')
    parser.add_argument('-b', '--batch-size', default=64, type=int,
                        help='mini-batch size')
    parser.add_argument('--lr', '--learning-rate', default=0.001, type=float,
                        help='initial learning rate')
    parser.add_argument('--momentum', default=0.9, type=float,
                        help='momentum')
    parser.add_argument('--weight-decay', '--wd', dest='wd', default=1e-4, type=float,
                        help='weight decay (default: 1e-4)')
    parser.add_argument('--lr-factor', default=0.75, type=float,
                        help='learning rate decay ratio')
    parser.add_argument('--lr-steps', default='10,20,30', type=str,
                        help='list of learning rate decay epochs as in str')
    opts = parser.parse_args()
    return opts

# Preparation 
Example 26
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: prepare_minc.py    Apache License 2.0 5 votes vote down vote up
def parse_opts():
    parser = argparse.ArgumentParser(description='Preparing MINC 2500 Dataset',
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--data', type=str, required=True,
                        help='directory for the original data folder')
    parser.add_argument('--split', type=int, default=1,
                        help='an integer in [1, 5] to specify the train/val/test split file')
    opts = parser.parse_args()
    return opts

# Preparation 
Example 27
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: ade20k.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Initialize ADE20K dataset.',
        epilog='Example: python setup_ade20k.py',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', default=None, help='dataset directory on disk')
    args = parser.parse_args()
    return args 
Example 28
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: cityscapes.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Initialize ADE20K dataset.',
        epilog='Example: python prepare_cityscapes.py',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', default=None, help='dataset directory on disk')
    args = parser.parse_args()
    return args 
Example 29
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: mscoco.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Initialize MS COCO dataset.',
        epilog='Example: python mscoco.py --download-dir ~/mscoco',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', type=str, default='~/mscoco/', help='dataset directory on disk')
    parser.add_argument('--no-download', action='store_true', help='disable automatic download if set')
    parser.add_argument('--overwrite', action='store_true', help='overwrite downloaded files if set, in case they are corrupted')
    args = parser.parse_args()
    return args 
Example 30
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: download_dataset.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Initialize DIV2K - bicubic downscaling x4 competition dataset.',
        epilog='Example: python download_dataset.py --download-dir ./',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', type=str, default='./', help='dataset directory on disk')
    parser.add_argument('--overwrite', action='store_true', help='overwrite downloaded files if set, in case they are corrputed')
    parser.add_argument('--file',type=str,default='DIV2K_train_HR',choices=['DIV2K_train_HR','DIV2K_test_LR_bicubic_X4','DIV2K_valid_HR','DIV2K_valid_LR_bicubic_X4'])
    args = parser.parse_args()
    return args

#####################################################################################
# Download and extract datasets into ``path`` 
Example 31
Project: FCOS_GluonCV   Author: DetectionTeamUCAS   File: download_dataset.py    Apache License 2.0 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='Initialize Cycle Gan dataset.',
        epilog='Example: python download_dataset.py --download-dir ./',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--download-dir', type=str, default='./', help='dataset directory on disk')
    parser.add_argument('--overwrite', action='store_true', help='overwrite downloaded files if set, in case they are corrupted')
    parser.add_argument('--file',type=str,default='horse2zebra',choices=['apple2orange','summer2winter_yosemite','horse2zebra','monet2photo','cezanne2photo','ukiyoe2photo','vangogh2photo','maps','cityscapes','facades','iphone2dslr_flower','ae_photos'],
                        help='Available datasets are: apple2orange, summer2winter_yosemite, horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos')
    args = parser.parse_args()
    return args

#####################################################################################
# Download and extract VOC datasets into ``path`` 
Example 32
Project: soccer-matlab   Author: utra-robosoccer   File: minitaur_gym_env_example.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
  parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
  parser.add_argument('--env', help='environment ID (0==sine, 1==stand, 2=reset, 3=overheat)',type=int,  default=0)
  args = parser.parse_args()
  print("--env=" + str(args.env))
    
  if (args.env == 0):
    SinePolicyExample()
  if (args.env == 1):
    SineStandExample()
  if (args.env == 2):
    ResetPoseExample()
  if (args.env == 3):
    MotorOverheatExample() 
Example 33
Project: soccer-matlab   Author: utra-robosoccer   File: testEnv.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
    import argparse
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID', default='AntBulletEnv-v0')
    parser.add_argument('--seed', help='RNG seed', type=int, default=0)
    parser.add_argument('--render', help='OpenGL Visualizer', type=int, default=0)
    parser.add_argument('--rgb',help='rgb_array gym rendering',type=int, default=0)
    parser.add_argument('--resetbenchmark',help='Repeat reset to show reset performance',type=int, default=0)
    parser.add_argument('--steps', help='Number of steps', type=int, default=1)
    
    args = parser.parse_args()
    test(args) 
Example 34
Project: soccer-matlab   Author: utra-robosoccer   File: minitaur_gym_env_example.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID (0==sine, 1==stand, 2=reset, 3=overheat)',type=int,  default=0)
    args = parser.parse_args()
    print("--env=" + str(args.env))
      
    if (args.env == 0):
      SinePolicyExample()
    if (args.env == 1):
      SineStandExample()
    if (args.env == 2):
      ResetPoseExample()
    if (args.env == 3):
      MotorOverheatExample() 
Example 35
Project: soccer-matlab   Author: utra-robosoccer   File: test_pybullet_sim_gym_env.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID (0==reset)',type=int,  default=0)
    args = parser.parse_args()
    print("--env=" + str(args.env))
      
    if (args.env == 0):
      ResetPoseExample(steps = 1000) 
Example 36
Project: zippy   Author: Illumina   File: make_params.py    Apache License 2.0 5 votes vote down vote up
def get_argparser():
    parser = argparse.ArgumentParser(usage='make_params is used to compile a proto-workflow into a form useable by ZIPPY', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('proto', help='The proto-workflow to compile.')
    parser.add_argument('out', help='The name of the compiled workflow to create.  If none, prepends compiled to the filetype as output (e.g., foo.compiled.json)', nargs='?')
    parser.add_argument('--defaults', default='defaults.json', help='File with default parameter values (in json format)')
    parser.add_argument('--default_behavior', default='warn', choices=['include', 'warn', 'ignore'], help='How to treat optional parameters.  <Include> them all in your file, <warn> you if they are not in the specified defaults file, or <ignore> them.')
    return parser 
Example 37
Project: zippy   Author: Illumina   File: downsampling_bloom.py    Apache License 2.0 5 votes vote down vote up
def buildParser():
    parser = argparse.ArgumentParser(
        description = __doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument("--bam", type=str, required=True,
                        help="Bam file to downsample")
    parser.add_argument("--downsampled_pairs", type=int, required=True,
                        help="Number of unique pairs to downsample to")
    parser.add_argument("--output", type=str, required=True,
                        help="Path to output bam file")
    parser.add_argument("--threads", type=int, default=4,
                        help="Number of threads to use")
    parser.add_argument("--unmapped", action='store_true', help="If set, include unmapped reads")
    return parser 
Example 38
Project: sic   Author: Yanixos   File: chardetect.py    GNU General Public License v3.0 5 votes vote down vote up
def main(argv=None):
    '''
    Handles command line arguments and gets things started.

    :param argv: List of arguments, as if specified on the command-line.
                 If None, ``sys.argv[1:]`` is used instead.
    :type argv: list of str
    '''
    # Get command line arguments
    parser = argparse.ArgumentParser(
        description="Takes one or more file paths and reports their detected \
                     encodings",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        conflict_handler='resolve')
    parser.add_argument('input',
                        help='File whose encoding we would like to determine.',
                        type=argparse.FileType('rb'), nargs='*',
                        default=[sys.stdin])
    parser.add_argument('--version', action='version',
                        version='%(prog)s {0}'.format(__version__))
    args = parser.parse_args(argv)

    for f in args.input:
        if f.isatty():
            print("You are running chardetect interactively. Press " +
                  "CTRL-D twice at the start of a blank line to signal the " +
                  "end of your input. If you want help, run chardetect " +
                  "--help\n", file=sys.stderr)
        print(description_of(f, f.name)) 
Example 39
Project: BDCN   Author: wandoucao   File: augment_edge_sample.py    MIT License 5 votes vote down vote up
def make_parser():
	parser = argparse.ArgumentParser(description='Process Images.',
									 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	add_arg = parser.add_argument
	add_arg('--src_color',			default=False, type=str,			help='File pattern to load for training.')
	add_arg('--src_mask',			default=False, type=str,			help='File pattern to load for training mask.')
	add_arg('--src_label',			default=False, type=str,			help='File pattern to load for training label.')
	add_arg('--dst_color',			default=False, type=str,			help='Path  to save color images.')
	add_arg('--dst_mask',			default=False, type=str,			help='Path  to save mask images.')
	add_arg('--dst_label',			default=False, type=str,			help='Path  to save label images.')
	add_arg('--resize',				default=0, type=int,				help='images size.')
	add_arg('--augment',			default=0, type=int,				help='images size.')
	return parser 
Example 40
Project: BDCN   Author: wandoucao   File: augment_edge_img.py    MIT License 5 votes vote down vote up
def make_parser():
	parser = argparse.ArgumentParser(description='Process Images.',
									 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
	add_arg = parser.add_argument
	add_arg('--src_color',			default=False, type=str,			help='File pattern to load for training.')
	add_arg('--src_mask',			default=False, type=str,			help='File pattern to load for training mask.')
	add_arg('--src_label',			default=False, type=str,			help='File pattern to load for training label.')
	add_arg('--dst_color',			default=False, type=str,			help='Path  to save color images.')
	add_arg('--dst_mask',			default=False, type=str,			help='Path  to save mask images.')
	add_arg('--dst_label',			default=False, type=str,			help='Path  to save label images.')
	add_arg('--resize',				default=0, type=int,				help='images size.')
	add_arg('--augment',			default=0, type=int,				help='images size.')
	return parser 
Example 41
Project: AshsSDK   Author: thehappydinoa   File: chardetect.py    MIT License 5 votes vote down vote up
def main(argv=None):
    '''
    Handles command line arguments and gets things started.

    :param argv: List of arguments, as if specified on the command-line.
                 If None, ``sys.argv[1:]`` is used instead.
    :type argv: list of str
    '''
    # Get command line arguments
    parser = argparse.ArgumentParser(
        description="Takes one or more file paths and reports their detected \
                     encodings",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        conflict_handler='resolve')
    parser.add_argument('input',
                        help='File whose encoding we would like to determine.',
                        type=argparse.FileType('rb'), nargs='*',
                        default=[sys.stdin])
    parser.add_argument('--version', action='version',
                        version='%(prog)s {0}'.format(__version__))
    args = parser.parse_args(argv)

    for f in args.input:
        if f.isatty():
            print("You are running chardetect interactively. Press " +
                  "CTRL-D twice at the start of a blank line to signal the " +
                  "end of your input. If you want help, run chardetect " +
                  "--help\n", file=sys.stderr)
        print(description_of(f, f.name)) 
Example 42
Project: AshsSDK   Author: thehappydinoa   File: chardetect.py    MIT License 5 votes vote down vote up
def main(argv=None):
    '''
    Handles command line arguments and gets things started.

    :param argv: List of arguments, as if specified on the command-line.
                 If None, ``sys.argv[1:]`` is used instead.
    :type argv: list of str
    '''
    # Get command line arguments
    parser = argparse.ArgumentParser(
        description="Takes one or more file paths and reports their detected \
                     encodings",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        conflict_handler='resolve')
    parser.add_argument('input',
                        help='File whose encoding we would like to determine.',
                        type=argparse.FileType('rb'), nargs='*',
                        default=[sys.stdin])
    parser.add_argument('--version', action='version',
                        version='%(prog)s {0}'.format(__version__))
    args = parser.parse_args(argv)

    for f in args.input:
        if f.isatty():
            print("You are running chardetect interactively. Press " +
                  "CTRL-D twice at the start of a blank line to signal the " +
                  "end of your input. If you want help, run chardetect " +
                  "--help\n", file=sys.stderr)
        print(description_of(f, f.name)) 
Example 43
Project: pcfg-sampling   Author: wilkeraziz   File: get_stats.py    Apache License 2.0 5 votes vote down vote up
def argparser():
    """parse command line arguments"""
    parser = argparse.ArgumentParser(prog='get_stats')

    parser.description = 'Get cProfile stats'
    parser.formatter_class = argparse.ArgumentDefaultsHelpFormatter

    parser.add_argument('--pstats',
            type=str,
            help='path to cProfile stats')
    parser.add_argument('--parser_type',
            type=str, default='mc', choices=['mc', 'mcmc'],
            help='Tyope of the parser')

    return parser 
Example 44
Project: lirpg   Author: Hwhitetooth   File: run_atari.py    MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID', default='BreakoutNoFrameskip-v4')
    parser.add_argument('--seed', help='RNG seed', type=int, default=0)
    parser.add_argument('--prioritized', type=int, default=1)
    parser.add_argument('--dueling', type=int, default=1)
    parser.add_argument('--num-timesteps', type=int, default=int(10e6))
    args = parser.parse_args()
    logger.configure()
    set_global_seeds(args.seed)
    env = make_atari(args.env)
    env = bench.Monitor(env, logger.get_dir())
    env = deepq.wrap_atari_dqn(env)
    model = deepq.models.cnn_to_mlp(
        convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
        hiddens=[256],
        dueling=bool(args.dueling),
    )
    act = deepq.learn(
        env,
        q_func=model,
        lr=1e-4,
        max_timesteps=args.num_timesteps,
        buffer_size=10000,
        exploration_fraction=0.1,
        exploration_final_eps=0.01,
        train_freq=4,
        learning_starts=10000,
        target_network_update_freq=1000,
        gamma=0.99,
        prioritized_replay=bool(args.prioritized)
    )
    # act.save("pong_model.pkl") XXX
    env.close() 
Example 45
Project: lirpg   Author: Hwhitetooth   File: cmd_util.py    MIT License 5 votes vote down vote up
def arg_parser():
    """
    Create an empty argparse.ArgumentParser.
    """
    import argparse
    return argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) 
Example 46
Project: lirpg   Author: Hwhitetooth   File: results_plotter.py    MIT License 5 votes vote down vote up
def main():
    import argparse
    import os
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--dirs', help='List of log directories', nargs = '*', default=['./log'])
    parser.add_argument('--num_timesteps', type=int, default=int(10e6))
    parser.add_argument('--xaxis', help = 'Varible on X-axis', default = X_TIMESTEPS)
    parser.add_argument('--task_name', help = 'Title of plot', default = 'Breakout')
    args = parser.parse_args()
    args.dirs = [os.path.abspath(dir) for dir in args.dirs]
    plot_results(args.dirs, args.num_timesteps, args.xaxis, args.task_name)
    plt.show() 
Example 47
Project: lirpg   Author: Hwhitetooth   File: main.py    MIT License 5 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('--env-id', type=str, default='HalfCheetah-v1')
    boolean_flag(parser, 'render-eval', default=False)
    boolean_flag(parser, 'layer-norm', default=True)
    boolean_flag(parser, 'render', default=False)
    boolean_flag(parser, 'normalize-returns', default=False)
    boolean_flag(parser, 'normalize-observations', default=True)
    parser.add_argument('--seed', help='RNG seed', type=int, default=0)
    parser.add_argument('--critic-l2-reg', type=float, default=1e-2)
    parser.add_argument('--batch-size', type=int, default=64)  # per MPI worker
    parser.add_argument('--actor-lr', type=float, default=1e-4)
    parser.add_argument('--critic-lr', type=float, default=1e-3)
    boolean_flag(parser, 'popart', default=False)
    parser.add_argument('--gamma', type=float, default=0.99)
    parser.add_argument('--reward-scale', type=float, default=1.)
    parser.add_argument('--clip-norm', type=float, default=None)
    parser.add_argument('--nb-epochs', type=int, default=500)  # with default settings, perform 1M steps total
    parser.add_argument('--nb-epoch-cycles', type=int, default=20)
    parser.add_argument('--nb-train-steps', type=int, default=50)  # per epoch cycle and MPI worker
    parser.add_argument('--nb-eval-steps', type=int, default=100)  # per epoch cycle and MPI worker
    parser.add_argument('--nb-rollout-steps', type=int, default=100)  # per epoch cycle and MPI worker
    parser.add_argument('--noise-type', type=str, default='adaptive-param_0.2')  # choices are adaptive-param_xx, ou_xx, normal_xx, none
    parser.add_argument('--num-timesteps', type=int, default=None)
    boolean_flag(parser, 'evaluation', default=False)
    args = parser.parse_args()
    # we don't directly specify timesteps for this script, so make sure that if we do specify them
    # they agree with the other parameters
    if args.num_timesteps is not None:
        assert(args.num_timesteps == args.nb_epochs * args.nb_epoch_cycles * args.nb_rollout_steps)
    dict_args = vars(args)
    del dict_args['num_timesteps']
    return dict_args 
Example 48
Project: HardRLWithYoutube   Author: MaxSobolMark   File: run_atari.py    MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID', default='BreakoutNoFrameskip-v4')
    parser.add_argument('--seed', help='RNG seed', type=int, default=0)
    parser.add_argument('--prioritized', type=int, default=1)
    parser.add_argument('--prioritized-replay-alpha', type=float, default=0.6)
    parser.add_argument('--dueling', type=int, default=1)
    parser.add_argument('--num-timesteps', type=int, default=int(10e6))
    parser.add_argument('--checkpoint-freq', type=int, default=10000)
    parser.add_argument('--checkpoint-path', type=str, default=None)

    args = parser.parse_args()
    logger.configure()
    set_global_seeds(args.seed)
    env = make_atari(args.env)
    env = bench.Monitor(env, logger.get_dir())
    env = deepq.wrap_atari_dqn(env)

    deepq.learn(
        env,
        "conv_only",
        convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
        hiddens=[256],
        dueling=bool(args.dueling),
        lr=1e-4,
        total_timesteps=args.num_timesteps,
        buffer_size=10000,
        exploration_fraction=0.1,
        exploration_final_eps=0.01,
        train_freq=4,
        learning_starts=10000,
        target_network_update_freq=1000,
        gamma=0.99,
        prioritized_replay=bool(args.prioritized),
        prioritized_replay_alpha=args.prioritized_replay_alpha,
        checkpoint_freq=args.checkpoint_freq,
        checkpoint_path=args.checkpoint_path,
    )

    env.close() 
Example 49
Project: HardRLWithYoutube   Author: MaxSobolMark   File: run_retro.py    MIT License 5 votes vote down vote up
def main():
    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--env', help='environment ID', default='SuperMarioBros-Nes')
    parser.add_argument('--gamestate', help='game state to load', default='Level1-1')
    parser.add_argument('--seed', help='seed', type=int, default=0)
    parser.add_argument('--num-timesteps', type=int, default=int(10e6))
    args = parser.parse_args()
    logger.configure()
    set_global_seeds(args.seed)
    env = retro_wrappers.make_retro(game=args.env, state=args.gamestate, max_episode_steps=10000, use_restricted_actions=retro.Actions.DISCRETE)
    env.seed(args.seed)
    env = bench.Monitor(env, logger.get_dir())
    env = retro_wrappers.wrap_deepmind_retro(env)

    model = deepq.models.cnn_to_mlp(
        convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
        hiddens=[256],
        dueling=True
    )
    act = deepq.learn(
        env,
        q_func=model,
        lr=1e-4,
        max_timesteps=args.num_timesteps,
        buffer_size=10000,
        exploration_fraction=0.1,
        exploration_final_eps=0.01,
        train_freq=4,
        learning_starts=10000,
        target_network_update_freq=1000,
        gamma=0.99,
        prioritized_replay=True
    )
    act.save()
    env.close() 
Example 50
Project: HardRLWithYoutube   Author: MaxSobolMark   File: cmd_util.py    MIT License 5 votes vote down vote up
def arg_parser():
    """
    Create an empty argparse.ArgumentParser.
    """
    import argparse
    return argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)