Python argparse 模块,MetavarTypeHelpFormatter() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用argparse.MetavarTypeHelpFormatter()

项目:dynamicpricing    作者:marcelja    | 项目源码 | 文件源码
def parse_arguments(description: str):
    logging.getLogger().setLevel(logging.DEBUG)
    logging.getLogger("urllib3").setLevel(logging.WARNING)
    logging.getLogger("requests").setLevel(logging.WARNING)
    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=argparse.MetavarTypeHelpFormatter)
    parser.add_argument('--port',
                        type=int,
                        default=5103,
                        help='Port to bind flask App to, default is 5103')
    parser.add_argument('--train',
                        type=str,
                        help='Path to csv file for training')
    parser.add_argument('--buy',
                        type=str,
                        help='Path to buyOffer.csv')
    parser.add_argument('--merchant',
                        type=str,
                        help='Merchant ID for initial csv parsing')
    parser.add_argument('--test',
                        type=str,
                        help='Path to csv file for cross validation')
    parser.add_argument('--output',
                        type=str,
                        help='Output will be written into the spedified file')
    return parser.parse_args()
项目:yolov2    作者:datlife    | 项目源码 | 文件源码
def _main_():
    parser = argparse.ArgumentParser(description="Detect object in an image",
                                     formatter_class=argparse.MetavarTypeHelpFormatter)

    parser.add_argument('--path', type=str, default='./assets/example.jpg',
                        help="Path to image file")

    parser.add_argument('--weights', type=str, default='./assets/coco_yolov2.weights',
                        help="Path to pre-trained weight file")

    parser.add_argument('--output_dir', type=str, default=None,
                        help="Output Directory")

    parser.add_argument('--iou', type=float, default=0.5,
                        help="Intersection over Union (IoU) value")

    parser.add_argument('--threshold', type=float, default=0.6,
                        help="Score Threshold value (minimum accuracy)")

    # ############
    # Parse Config
    # ############
    args = parser.parse_args()
    anchors, label_dict = parse_config(cfg)

    # ###################
    # Define Keras Model
    # ###################
    model = yolov2_darknet(is_training      = False,
                           img_size         = cfg.IMG_INPUT_SIZE,
                           anchors          = anchors,
                           num_classes      = cfg.N_CLASSES,
                           iou              = args.iou,
                           scores_threshold = args.threshold)

    model.load_weights(args.weights)
    model.summary()

    # #####################
    # Make one prediction #
    # #####################
    image = np.expand_dims(cv2.imread(args.path), axis=0)

    pred_bboxes, pred_classes, pred_scores = model.predict_on_batch(image)
    pred_classes = [label_dict[idx] for idx in pred_classes]

    # #################
    # Display Result  #
    # #################
    h, w, _ = image.shape
    if args.output_dir is not None:
        result = draw(image, pred_bboxes, pred_classes, pred_scores)
        cv2.imwrite(os.path.join(args.output_dir, args.path.split('/')[-1].split('.')[0] + '_result.jpg'), result)