Python argparse.ArgumentParser() Examples

The following are 30 code examples for showing how to use argparse.ArgumentParser(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module argparse , or try the search function .

Example 1
def parse_args():
  """
  Parse input arguments
  """
  parser = argparse.ArgumentParser(description='Re-evaluate results')
  parser.add_argument('output_dir', nargs=1, help='results directory',
                      type=str)
  parser.add_argument('--imdb', dest='imdb_name',
                      help='dataset to re-evaluate',
                      default='voc_2007_test', type=str)
  parser.add_argument('--comp', dest='comp_mode', help='competition mode',
                      action='store_true')

  if len(sys.argv) == 1:
    parser.print_help()
    sys.exit(1)

  args = parser.parse_args()
  return args 
Example 2
Project: BERT-Classification-Tutorial   Author: Socialbird-AILab   File: download_glue.py    License: Apache License 2.0 6 votes vote down vote up
def main(arguments):
    parser = argparse.ArgumentParser()
    parser.add_argument('--data_dir', help='directory to save data to', type=str, default='glue_data')
    parser.add_argument('--tasks', help='tasks to download data for as a comma separated string',
                        type=str, default='all')
    parser.add_argument('--path_to_mrpc',
                        help='path to directory containing extracted MRPC data, msr_paraphrase_train.txt and msr_paraphrase_text.txt',
                        type=str, default='')
    args = parser.parse_args(arguments)

    if not os.path.isdir(args.data_dir):
        os.mkdir(args.data_dir)
    tasks = get_tasks(args.tasks)

    for task in tasks:
        if task == 'MRPC':
            format_mrpc(args.data_dir, args.path_to_mrpc)
        elif task == 'diagnostic':
            download_diagnostic(args.data_dir)
        else:
            download_and_extract(task, args.data_dir) 
Example 3
Project: incubator-spot   Author: apache   File: worker.py    License: Apache License 2.0 6 votes vote down vote up
def main():

    # input parameters
    parser = argparse.ArgumentParser(description="Worker Ingest Framework")
    parser.add_argument('-t', '--type', dest='type', required=True,
                        help='Type of data that will be ingested (Pipeline Configuration)',
                        metavar='')
    parser.add_argument('-i', '--id', dest='id', required=True,
                        help='Worker Id, this is needed to sync Kafka and Ingest framework (Partition Number)',
                        metavar='')
    parser.add_argument('-top', '--topic', dest='topic', required=True,
                        help='Topic to read from.', metavar="")
    parser.add_argument('-p', '--processingParallelism', dest='processes',
                        required=False, help='Processing Parallelism', metavar="")
    args = parser.parse_args()

    # start worker based on the type.
    start_worker(args.type, args.topic, args.id, args.processes) 
Example 4
Project: incubator-spot   Author: apache   File: bluecoat.py    License: Apache License 2.0 6 votes vote down vote up
def main():
    """
    Handle commandline arguments and
    start the collector.
    """
    # input Parameters
    parser = argparse.ArgumentParser(description="Bluecoat Parser")
    parser.add_argument('-zk', '--zookeeper', dest='zk', required=True,
                        help='Zookeeper IP and port (i.e. 10.0.0.1:2181)', metavar='')
    parser.add_argument('-t', '--topic', dest='topic', required=True,
                        help='Topic to listen for Spark Streaming', metavar='')
    parser.add_argument('-db', '--database', dest='db', required=True,
                        help='Hive database whete the data will be ingested', metavar='')
    parser.add_argument('-dt', '--db-table', dest='db_table', required=True,
                        help='Hive table whete the data will be ingested', metavar='')
    parser.add_argument('-w', '--num_of_workers', dest='num_of_workers', required=True,
                        help='Num of workers for Parallelism in Data Processing', metavar='')
    parser.add_argument('-bs', '--batch-size', dest='batch_size', required=True,
                        help='Batch Size (Milliseconds)', metavar='')
    args = parser.parse_args()

    # start collector based on data source type.
    bluecoat_parse(args.zk, args.topic, args.db, args.db_table, args.num_of_workers, args.batch_size) 
Example 5
Project: incubator-spot   Author: apache   File: master_collector.py    License: Apache License 2.0 6 votes vote down vote up
def main():

    # input Parameters
    parser = argparse.ArgumentParser(description="Master Collector Ingest Daemon")
    parser.add_argument('-t', '--type', dest='type', required=True,
                        help='Type of data that will be ingested (Pipeline Configuration)',
                        metavar='')
    parser.add_argument('-w', '--workers', dest='workers_num',
                        required=True, help='Number of workers for the ingest process',
                        metavar='')
    parser.add_argument('-id', '--ingestId', dest='ingest_id',
                        required=False, help='Ingest ID', metavar='')
    args = parser.parse_args()

    # start collector based on data source type.
    start_collector(args.type, args.workers_num, args.ingest_id) 
Example 6
Project: godot-mono-builds   Author: godotengine   File: cmd_utils.py    License: MIT License 6 votes vote down vote up
def build_arg_parser(description, env_vars={}):
    from argparse import ArgumentParser, RawDescriptionHelpFormatter
    from textwrap import dedent

    base_env_vars = {
        'MONO_SOURCE_ROOT': 'Overrides default value for --mono-sources',
    }

    env_vars_text = '\n'.join(['    %s: %s' % (var, desc) for var, desc in env_vars.items()])
    base_env_vars_text = '\n'.join(['    %s: %s' % (var, desc) for var, desc in base_env_vars.items()])

    epilog=dedent('''\
environment variables:
%s
%s
''' % (env_vars_text, base_env_vars_text))

    return ArgumentParser(
        description=description,
        formatter_class=RawDescriptionHelpFormatter,
        epilog=epilog
    ) 
Example 7
Project: Mastering-Python-Networking-Second-Edition   Author: PacktPublishing   File: eapi_2_acl.py    License: MIT License 6 votes vote down vote up
def main():
   parser = argparse.ArgumentParser(description="Edit Arista ACLs using your local editor")
   parser.add_argument("acl", metavar="ACL",
                       help="Name of the access list to modify")
   parser.add_argument("switches", metavar="SWITCH", nargs="+",
                       help="Hostname or IP of the switch to query")
   parser.add_argument("--username", help="Name of the user to connect as",
                       default="admin")
   parser.add_argument("--password", help="The user's password")
   parser.add_argument("--https", help="Use HTTPS instead of HTTP",
                       action="store_const", const="https", default="http")
   args = parser.parse_args()

   aclName = args.acl
   tmpfile = "/tmp/AclEditor-%s" % aclName
   apiEndpoints = getEndpoints(args.switches, args.https,
                               args.username, args.password)
   prepopulateAclFile(tmpfile, aclName, apiEndpoints)
   edits = getEdits(tmpfile)
   applyChanges(aclName, apiEndpoints, edits)
   print
   print "Done!" 
Example 8
Project: BASS   Author: Cisco-Talos   File: cmdline.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Bass")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Sample path") 

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO
        }[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG

    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 9
Project: BASS   Author: Cisco-Talos   File: whitelist.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Add samples to BASS whitelist")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
    parser.add_argument("sample", help = "Whitelist sample")

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO}[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG
    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 10
Project: BASS   Author: Cisco-Talos   File: client.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "Find common ngrams in binary files")
    parser.add_argument("-v", "--verbose", action = "count", default = 0, help = "Increase verbosity")
    parser.add_argument("--output", type = str, default = None, help = "Output to file instead of stdout")
    parser.add_argument("--url", type = str, default = "http://localhost:5000", help = "URL of BASS server")
    parser.add_argument("samples", metavar = "sample", nargs = "+", help = "Cluster samples")

    args = parser.parse_args()

    try:
        loglevel = {
            0: logging.ERROR,
            1: logging.WARN,
            2: logging.INFO}[args.verbose]
    except KeyError:
        loglevel = logging.DEBUG
    logging.basicConfig(level = loglevel)
    logging.getLogger().setLevel(loglevel)

    return args 
Example 11
Project: BASS   Author: Cisco-Talos   File: export_binexport_pickle.py    License: GNU General Public License v2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description = "IDA Pro script: Dump bindiff database file")
    subparsers = parser.add_subparsers(help = "subcommand")
    
    parser_pickle = subparsers.add_parser("pickle", help = "Dump pickled database")
    parser_pickle.add_argument("pickle_output", type = str, help = "Output pickle database file")
    parser_pickle.set_defaults(handler = handle_pickle)

    parser_bindiff = subparsers.add_parser("binexport", help = "Dump bindiff database")
    parser_bindiff.add_argument("bindiff_output", type = str, help = "Output BinExport database file")
    parser_bindiff.set_defaults(handler = handle_binexport)

    parser_bindiff_pickle = subparsers.add_parser("binexport_pickle", help = "Dump bindiff database and pickled database")
    parser_bindiff_pickle.add_argument("bindiff_output", type = str, help = "Output BinDiff database file")
    parser_bindiff_pickle.add_argument("pickle_output", type = str, help = "Output pickle database file")
    parser_bindiff_pickle.set_defaults(handler = handle_binexport_pickle)

    args = parser.parse_args(idc.ARGV[1:])

    return args 
Example 12
def parse_args():
  """
  Parse input arguments
  """
  parser = argparse.ArgumentParser(description='Re-evaluate results')
  parser.add_argument('output_dir', nargs=1, help='results directory',
                      type=str)
  parser.add_argument('--imdb', dest='imdb_name',
                      help='dataset to re-evaluate',
                      default='voc_2007_test', type=str)
  parser.add_argument('--matlab', dest='matlab_eval',
                      help='use matlab for evaluation',
                      action='store_true')
  parser.add_argument('--comp', dest='comp_mode', help='competition mode',
                      action='store_true')
  parser.add_argument('--nms', dest='apply_nms', help='apply nms',
                      action='store_true')

  if len(sys.argv) == 1:
    parser.print_help()
    sys.exit(1)

  args = parser.parse_args()
  return args 
Example 13
Project: twitter-export-image-fill   Author: mwichary   File: twitter-export-image-fill.py    License: The Unlicense 6 votes vote down vote up
def parse_arguments():
  parser = argparse.ArgumentParser(description = 'Downloads all the images to your Twitter archive .')
  parser.add_argument('--include-videos', dest='PATH_TO_YOUTUBE_DL',
      help = 'use youtube_dl to download videos (and animated GIFs) in addition to images')
  parser.add_argument('--continue-after-failure', action='store_true',
      help = 'continue the process when one of the downloads fail (creates incomplete archive)')
  parser.add_argument('--backfill-from', dest='EARLIER_ARCHIVE_PATH',
      help = 'copy images downloaded into an earlier archive instead of downloading them again (useful for incremental backups)')
  parser.add_argument('--skip-retweets', action='store_true',
      help = 'do not download images or videos from retweets')
  parser.add_argument('--skip-images', action='store_true',
      help = 'do not download images in general')
  parser.add_argument('--skip-videos', action='store_true',
      help = 'do not download videos (and animated GIFs) in general')
  parser.add_argument('--skip-avatars', action='store_true',
      help = 'do not download avatar images')
  parser.add_argument('--verbose', action='store_true',
      help = 'show additional debugging info')
  parser.add_argument('--force-redownload', action='store_true',
      help = 'force to re-download images and videos that were already downloaded')
  return parser.parse_args() 
Example 14
Project: iSDX   Author: sdn-ixp   File: arproxy.py    License: Apache License 2.0 6 votes vote down vote up
def main():
    global arpListener, config

    parser = argparse.ArgumentParser()
    parser.add_argument('dir', help='the directory of the example')
    args = parser.parse_args()

    # locate config file
    config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","examples",args.dir,"config","sdx_global.cfg")

    logger.info("Reading config file %s", config_file)
    config = parse_config(config_file)

    logger.info("Starting ARP Listener")
    arpListener = ArpListener()
    ap_thread = Thread(target=arpListener.start)
    ap_thread.start()

    # start pctrl listener in foreground
    logger.info("Starting PCTRL Listener")
    pctrlListener = PctrlListener()
    pctrlListener.start() 
Example 15
Project: flappybird-qlearning-bot   Author: chncyhn   File: learn.py    License: MIT License 6 votes vote down vote up
def main():
    global HITMASKS, ITERATIONS, VERBOSE, bot

    parser = argparse.ArgumentParser("learn.py")
    parser.add_argument("--iter", type=int, default=1000, help="number of iterations to run")
    parser.add_argument(
        "--verbose", action="store_true", help="output [iteration | score] to stdout"
    )
    args = parser.parse_args()
    ITERATIONS = args.iter
    VERBOSE = args.verbose

    # load dumped HITMASKS
    with open("data/hitmasks_data.pkl", "rb") as input:
        HITMASKS = pickle.load(input)

    while True:
        movementInfo = showWelcomeAnimation()
        crashInfo = mainGame(movementInfo)
        showGameOverScreen(crashInfo) 
Example 16
Project: python-panavatar   Author: ondergetekende   File: __init__.py    License: MIT License 6 votes vote down vote up
def cmdline():
    import argparse

    parser = argparse.ArgumentParser(description='Generate an svg wallpaper')
    parser.add_argument('--width', type=int, default=1024,
                        help='The width of the wallpaper')
    parser.add_argument('--height', type=int, default=786,
                        help='The height of the wallpaper')
    parser.add_argument('--seed',
                        help='Seed for the randomizer')
    parser.add_argument('--log-choices',
                        help='Log the choices made', action='store_true')

    parser.add_argument('--output', type=argparse.FileType('w'),
                        default='-')

    args = parser.parse_args()

    for element in get_svg_iter(args.width, args.height,
                                {"seed": args.seed},
                                log_choices=args.log_choices):
        args.output.write(element) 
Example 17
Project: mmdetection   Author: open-mmlab   File: image_demo.py    License: Apache License 2.0 6 votes vote down vote up
def main():
    parser = ArgumentParser()
    parser.add_argument('img', help='Image file')
    parser.add_argument('config', help='Config file')
    parser.add_argument('checkpoint', help='Checkpoint file')
    parser.add_argument(
        '--device', default='cuda:0', help='Device used for inference')
    parser.add_argument(
        '--score-thr', type=float, default=0.3, help='bbox score threshold')
    args = parser.parse_args()

    # build the model from a config file and a checkpoint file
    model = init_detector(args.config, args.checkpoint, device=args.device)
    # test a single image
    result = inference_detector(model, args.img)
    # show the results
    show_result_pyplot(model, args.img, result, score_thr=args.score_thr) 
Example 18
Project: mmdetection   Author: open-mmlab   File: benchmark_filter.py    License: Apache License 2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description='Filter configs to train')
    parser.add_argument(
        '--basic-arch',
        action='store_true',
        help='to train models in basic arch')
    parser.add_argument(
        '--datasets', action='store_true', help='to train models in dataset')
    parser.add_argument(
        '--data-pipeline',
        action='store_true',
        help='to train models related to data pipeline, e.g. augmentations')
    parser.add_argument(
        '--nn-module',
        action='store_true',
        help='to train models related to neural network modules')

    args = parser.parse_args()
    return args 
Example 19
Project: mmdetection   Author: open-mmlab   File: pytorch2onnx.py    License: Apache License 2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(
        description='MMDet pytorch model conversion to ONNX')
    parser.add_argument('config', help='test config file path')
    parser.add_argument('checkpoint', help='checkpoint file')
    parser.add_argument(
        '--out', type=str, required=True, help='output ONNX filename')
    parser.add_argument(
        '--shape',
        type=int,
        nargs='+',
        default=[1280, 800],
        help='input image size')
    parser.add_argument(
        '--passes', type=str, nargs='+', help='ONNX optimization passes')
    args = parser.parse_args()
    return args 
Example 20
Project: mmdetection   Author: open-mmlab   File: browse_dataset.py    License: Apache License 2.0 6 votes vote down vote up
def parse_args():
    parser = argparse.ArgumentParser(description='Browse a dataset')
    parser.add_argument('config', help='train config file path')
    parser.add_argument(
        '--skip-type',
        type=str,
        nargs='+',
        default=['DefaultFormatBundle', 'Normalize', 'Collect'],
        help='skip some useless pipeline')
    parser.add_argument(
        '--output-dir',
        default=None,
        type=str,
        help='If there is no display interface, you can save it')
    parser.add_argument('--not-show', default=False, action='store_true')
    parser.add_argument(
        '--show-interval',
        type=int,
        default=999,
        help='the interval of show (ms)')
    args = parser.parse_args()
    return args 
Example 21
Project: twstock   Author: mlouielu   File: __init__.py    License: MIT License 6 votes vote down vote up
def run():
    parser = argparse.ArgumentParser()

    parser.add_argument('-b', '--bfp', nargs='+')
    parser.add_argument('-s', '--stock', nargs='+')
    parser.add_argument('-r', '--realtime', nargs='+')
    parser.add_argument('-U', '--upgrade-codes', action='store_true', help='Update entites codes')
    args = parser.parse_args()

    if args.bfp:
        best_four_point.run(args.bfp)
    elif args.stock:
        stock.run(args.stock)
    elif args.realtime:
        realtime.run(args.realtime)
    elif args.upgrade_codes:
        print('Start to update codes')
        __update_codes()
        print('Done!')
    else:
        parser.print_help() 
Example 22
Project: fireprox   Author: ustayready   File: fire.py    License: GNU General Public License v3.0 6 votes vote down vote up
def parse_arguments() -> Tuple[argparse.Namespace, str]:
    """Parse command line arguments and return namespace

    :return: Namespace for arguments and help text as a tuple
    """
    parser = argparse.ArgumentParser(description='FireProx API Gateway Manager')
    parser.add_argument('--profile_name',
                        help='AWS Profile Name to store/retrieve credentials', type=str, default=None)
    parser.add_argument('--access_key',
                        help='AWS Access Key', type=str, default=None)
    parser.add_argument('--secret_access_key',
                        help='AWS Secret Access Key', type=str, default=None)
    parser.add_argument('--session_token',
                        help='AWS Session Token', type=str, default=None)
    parser.add_argument('--region',
                        help='AWS Region', type=str, default=None)
    parser.add_argument('--command',
                        help='Commands: list, create, delete, update', type=str, default=None)
    parser.add_argument('--api_id',
                        help='API ID', type=str, required=False)
    parser.add_argument('--url',
                        help='URL end-point', type=str, required=False)
    return parser.parse_args(), parser.format_help() 
Example 23
Project: CAMISIM   Author: CAMI-challenge   File: create_metadata.py    License: Apache License 2.0 6 votes vote down vote up
def parse_options():
    """
    parse command line options
    """
    parser = argparse.ArgumentParser()

    helptext="Root path of input run for which metadata should be created, should contain metadata.tsv and genome_to_id.tsv"
    parser.add_argument("-i", "--input-run", type=str, help=helptext)

    helptext="output file to write metadata to"
    parser.add_argument("-o", "--output", type=str, help=helptext)
    
    helptext="Name of the data set"
    parser.add_argument("-n", "--name", type=str, help=helptext)

    if not len(sys.argv) > 1:
        parser.print_help()
        return None
    args = parser.parse_args()

    return args 
Example 24
Project: indras_net   Author: gcallah   File: json_generator.py    License: GNU General Public License v3.0 5 votes vote down vote up
def main():
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("filename")

    args = arg_parser.parse_args()

    model_file = args.filename

    validate_config()

    generate_json(parse_docstring(model_file))

    if(saw_error is True):
        exit(1) 
Example 25
Project: svviz   Author: svviz   File: runTests.py    License: MIT License 5 votes vote down vote up
def main():
    # don't ask me why I rolled my own regression testing code instead of using one of the 
    # gazillion existing frameworks...

    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("-r", "--reference", help="path for hg19 reference fasta; must be defined here or "
        "using the environmental variable SVVIZ_HG19_FASTA")

    parser.add_argument("mode", help="run|reset")
    parser.add_argument("which", nargs="*", help="which analyses to run (default all)")

    args = parser.parse_args()

    print(args.which)

    # if len(sys.argv) < 2:
    #     print USAGE
    #     return 

    if args.mode == "run":
        if getHG19Ref(args.reference) is None:
            parser.print_help()
            print("ERROR: Must provide path for hg19 reference fasta")
            sys.exit(1)
        run(args.which)
    elif args.mode == "reset":
        reset()
    else:
        parser.print_help() 
Example 26
Project: mutatest   Author: EvanKepner   File: cli.py    License: MIT License 5 votes vote down vote up
def cli_args(args: Sequence[str], search_config_files: bool = True) -> argparse.Namespace:
    """Command line arguments as parsed args.

    If a INI configuration file is set it is used to set additional default arguments, but
    the CLI arguments override any INI file settings.

    Args:
        args: the argument sequence from the command line
        search_config_files: flag for looking through ``SETTINGS_FILES`` for settings

    Returns:
        Parsed args from ArgumentParser
    """
    parser = cli_parser()

    if search_config_files:
        for ini_config_file in SETTINGS_FILES:

            if ini_config_file.path.exists():
                try:
                    ini_config = read_ini_config(ini_config_file.path, ini_config_file.sections)
                    ini_cli_args = parse_ini_config_with_cli(parser, ini_config, args)
                    return parser.parse_args(ini_cli_args)

                except KeyError:
                    # read_ini_config will raise KeyError if the section is not valid
                    continue

    return parser.parse_args(args) 
Example 27
Project: mutatest   Author: EvanKepner   File: test_cli.py    License: MIT License 5 votes vote down vote up
def mock_parser():
    """Mock parser."""
    parser = argparse.ArgumentParser(prog="mock_parser", description=("Mock parser"))
    parser.add_argument("-e", "--exclude", action="append", default=[], help="Append")
    parser.add_argument("-b", "--blacklist", nargs="*", default=[], help="Nargs")
    parser.add_argument("--debug", action="store_true", help="Store True.")

    return parser 
Example 28
Project: incubator-spot   Author: apache   File: collector.py    License: Apache License 2.0 5 votes vote down vote up
def _parse_args():
    '''
        Parse command-line options found in 'args' (default: sys.argv[1:]).

    :returns: On success, a namedtuple of Values instances.
    '''
    parser   = ArgumentParser('Distributed Collector Daemon of Apache Spot', epilog='END')
    required = parser.add_argument_group('mandatory arguments')

    # .................................state optional arguments
    parser.add_argument('-c', '--config-file',
        default='ingest_conf.json',
        type=file,
        help='path of configuration file',
        metavar='')

    parser.add_argument('-l', '--log-level',
        default='INFO',
        help='determine the level of the logger',
        metavar='')

    parser.add_argument('--skip-conversion',
        action='store_true',
        default=False,
        help='no transformation will be applied to the data; useful for importing CSV files')

    # .................................state mandatory arguments
    required.add_argument('--topic',
        required=True,
        help='name of topic where the messages will be published')

    required.add_argument('-t', '--type',
        choices=pipelines.__all__,
        required=True,
        help='type of data that will be collected')

    return parser.parse_args() 
Example 29
Project: incubator-spot   Author: apache   File: start_oa.py    License: Apache License 2.0 5 votes vote down vote up
def main():

    # input parameters.
    parser = argparse.ArgumentParser(description="Master OA Script")
    parser.add_argument('-d','--date',required=True,dest='date',help='Date data that will be processed by OA  (i.e 20161102)',metavar='')
    parser.add_argument('-t','--type',required=True,dest='type',help='Data type that will be processed by OA (i.e dns, proxy, flow)',metavar='')
    parser.add_argument('-l','--limit',required=True,dest='limit',help='Num of suspicious connections that will be processed by OA.',metavar='')
    args= parser.parse_args()

    start_oa(args) 
Example 30
Project: cat-bbs   Author: aleju   File: create_dataset.py    License: MIT License 5 votes vote down vote up
def main():
    """Generate datasets."""

    parser = argparse.ArgumentParser(description="Process some integers.")
    parser.add_argument("--dataset_dir", help="")
    parser.add_argument("--out_dir", default="", help="")
    parser.add_argument("--img_size", default=224, type=int, help="")
    args = parser.parse_args()

    assert args.dataset_dir is not None, "Expected 10k cats dataset directory via --dataset_dir"

    # load images and their facial keypoints
    print("Loading filepaths...")
    fps = find_image_filepaths(args.dataset_dir)

    print("Loading images...")
    examples = []
    for i, fp in enumerate(fps):
        if (i+1) % 100 == 0:
            print("Image %d of %d..." % (i+1, len(fps)))
        img = ndimage.imread(fp, mode="RGB")
        kps = load_keypoints(fp, image_height=img.shape[0], image_width=img.shape[1])
        img_square, (added_top, added_right, added_bottom, added_left) = to_aspect_ratio_add(img, 1.0, return_paddings=True)
        kps = [(x+added_left, y+added_top) for (x, y) in kps]
        #rs_factor = args.img_size / img_square.shape[0]
        img_square_rs = misc.imresize(img_square, (args.img_size, args.img_size))
        kps_rs = [(int((x/img_square.shape[1])*args.img_size), int((y/img_square.shape[0])*args.img_size)) for (x, y) in kps]
        examples.append(Example(fp, img_square_rs, kps_rs))

    # save datasets
    print("Saving pickle file...")
    with open(os.path.join(args.out_dir, "cats-dataset.pkl"), "w") as f:
        pickle.dump(examples, f)