Ejemplo n.º 1
0
import xml.etree.ElementTree
import cv2
import numpy as np
from constants import get_config
import pickle
import os
import sys
import random as rn
import imgaug as iaa

config = get_config()
IMAGE_H, IMAGE_W, CHANNEL = config['IMAGE_H'], config['IMAGE_W'], config[
    'CHANNEL']
CLASS = config['CLASS']
BOX = config['BOX']
LABELS = config['LABELS']
GRID_H, GRID_W = config['GRID_H'], config['GRID_W']
IMAGE_NUM = 1000


def get_center(xmin, ymin, w, h):
    center_w = int(w / 2)
    center_h = int(h / 2)
    return xmin + center_w, ymin + center_h


def parsing_xml(xml_path):
    root = xml.etree.ElementTree.parse(xml_path).getroot()
    data = []
    for object in root.iter('object'):
        try:
def main(argv=None):  # IGNORE:C0111
    '''Command line options.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version,
                                                     program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Created by user_name on %s.
  Copyright 2016 organization_name. All rights reserved.

  Licensed under the Apache License 2.0
  http://www.apache.org/licenses/LICENSE-2.0

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % (program_shortdesc, str(__date__))

    try:
        setup_log()
        # Setup argument parser
        parser = ArgumentParser(description=program_license,
                                formatter_class=RawDescriptionHelpFormatter)
        parser.add_argument("-v", "--verbose", dest="verbose",
                            action="count",
                            help="set verbosity level [default: %(default)s]")
        parser.add_argument("-i", "--include", dest="include",
                            help="only include paths matching this regex "
                            "pattern. "
                            "Note: exclude is given preference over include. "
                            "[default: %(default)s]", metavar="RE")
        parser.add_argument('-V', '--version', action='version',
                            version=program_version_message)
        parser.add_argument("-g", "--generate", help="This program generates "
                            "the docker compose file")
        # Process arguments
        args = parser.parse_args()
        logger.info("The config section is {}".format(CONFIG_SECTION))

        config = get_config()
        if args.generate:
            template_dir = config.get(CONFIG_SECTION, "template_dir")
            template_file = config.get(CONFIG_SECTION, "template_file")
            output_template = config.get(CONFIG_SECTION, "output_template")
            logger.debug("Template dir: {}\nTemplate file:{}\nOutput name:{}"
                         .format(template_dir, template_file, output_template))
            env = Environment(loader=FileSystemLoader(template_dir))
            configuration = env.get_template(template_file)
            config_variables = {}

            configured = configuration.render(config_variables)
            configuration_template = codecs.open(output_template,
                                                 "w", "utf8")
            configuration_template.write(configured)
            configuration_template.close()

        return 0
    except KeyboardInterrupt:
        # ## handle keyboard interrupt ###
        logger.exception("User interrupted the execution")
        return 0
    except Exception:
        logger.exception("Error while running the application")
        return 2