Ejemplo n.º 1
0
def parse_args(args):
    """ Parse the arguments.
    """
    parser = argparse.ArgumentParser(description='Evaluation script for a RetinaNet network.')
    subparsers = parser.add_subparsers(help='Arguments for specific dataset types.', dest='dataset_type')
    subparsers.required = True

    coco_parser = subparsers.add_parser('coco')
    coco_parser.add_argument('coco_path', help='Path to dataset directory (ie. /tmp/COCO).')

    pascal_parser = subparsers.add_parser('pascal')
    pascal_parser.add_argument('pascal_path', help='Path to dataset directory (ie. /tmp/VOCdevkit).')

    data_dir = annotation_path()
    args_annotations = data_dir + '/annotations_test.csv'

    csv_parser = subparsers.add_parser('csv')
    csv_parser.add_argument('--annotations', help='Path to CSV file containing annotations for evaluation.',
                            default=args_annotations)
    csv_parser.add_argument('--classes', help='Path to a CSV file containing class label mapping.',
                            default=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'class_mappings.csv'))
    parser.add_argument('--hard_score_rate', help='', default=1.)

    parser.add_argument('model', help='Path to RetinaNet model.')
    parser.add_argument('--base_dir', help='Path to base dir for CSV file.',
                        default=image_path())
    parser.add_argument('--convert-model',
                        help='Convert the model to an inference model (ie. the input is a training model).', type=int,
                        default=1)


    parser.add_argument('--backbone', help='The backbone of the model.', default='resnet50')
    parser.add_argument('--gpu', help='Id of the GPU to use (as reported by nvidia-smi).')
    parser.add_argument('--score-threshold', help='Threshold on score to filter detections with (defaults to 0.05).',
                        default=0.1, type=float)
    parser.add_argument('--iou-threshold', help='IoU Threshold to count for a positive detection (defaults to 0.5).',
                        default=0.75, type=float)
    parser.add_argument('--save-path', help='Path for saving images with detections (doesn\'t work for COCO).')
    parser.add_argument('--image-min-side', help='Rescale the image so the smallest side is min_side.', type=int,
                        default=800)
    parser.add_argument('--image-max-side', help='Rescale the image if the largest side is larger than max_side.',
                        type=int, default=1333)

    return parser.parse_args(args)
Ejemplo n.º 2
0
def parse_args(args):
    """ Parse the arguments.
    """
    parser = argparse.ArgumentParser(
        description='Simple training script for training a RetinaNet network.')
    subparsers = parser.add_subparsers(
        help='Arguments for specific dataset types.', dest='dataset_type')
    subparsers.required = True

    coco_parser = subparsers.add_parser('coco')
    coco_parser.add_argument('coco_path',
                             help='Path to dataset directory (ie. /tmp/COCO).')

    pascal_parser = subparsers.add_parser('pascal')
    pascal_parser.add_argument(
        'pascal_path', help='Path to dataset directory (ie. /tmp/VOCdevkit).')

    kitti_parser = subparsers.add_parser('kitti')
    kitti_parser.add_argument(
        'kitti_path', help='Path to dataset directory (ie. /tmp/kitti).')

    def csv_list(string):
        return string.split(',')

    oid_parser = subparsers.add_parser('oid')
    oid_parser.add_argument('main_dir', help='Path to dataset directory.')
    oid_parser.add_argument('--version',
                            help='The current dataset version is v4.',
                            default='v4')
    oid_parser.add_argument('--labels-filter',
                            help='A list of labels to filter.',
                            type=csv_list,
                            default=None)
    oid_parser.add_argument('--annotation-cache-dir',
                            help='Path to store annotation cache.',
                            default='.')
    oid_parser.add_argument('--fixed-labels',
                            help='Use the exact specified labels.',
                            default=False)

    data_dir = annotation_path()
    args_annotations = data_dir + '/annotations_train.csv'
    args_classes = data_dir + '/class_mappings_train.csv'
    args_val_annotations = data_dir + '/annotations_val.csv'

    args_snapshot_path = root_dir() + '/snapshot'
    args_tensorboard_dir = root_dir() + '/logs'

    csv_parser = subparsers.add_parser('csv')
    csv_parser.add_argument(
        '--annotations',
        help='Path to CSV file containing annotations for training.',
        default=args_annotations)
    csv_parser.add_argument(
        '--classes',
        help='Path to a CSV file containing class label mapping.',
        default=args_classes)
    csv_parser.add_argument(
        '--val-annotations',
        help=
        'Path to CSV file containing annotations for validation (optional).',
        default=args_val_annotations)
    csv_parser.add_argument('--base_dir',
                            help='Path to base dir for CSV file.',
                            default=image_path())

    group = parser.add_mutually_exclusive_group()
    group.add_argument('--snapshot', help='Resume training from a snapshot.')
    group.add_argument(
        '--imagenet-weights',
        help=
        'Initialize the model with pretrained imagenet weights. This is the default behaviour.',
        action='store_const',
        const=True,
        default=False)
    group.add_argument('--weights',
                       help='Initialize the model with weights from a file.')
    group.add_argument('--no-weights',
                       help='Don\'t initialize the model with any weights.',
                       dest='imagenet_weights',
                       action='store_const',
                       const=False)

    parser.add_argument('--backbone',
                        help='Backbone model used by retinanet.',
                        default='resnet50',
                        type=str)
    parser.add_argument('--batch-size',
                        help='Size of the batches.',
                        default=1,
                        type=int)
    parser.add_argument(
        '--gpu', help='Id of the GPU to use (as reported by nvidia-smi).')
    parser.add_argument('--multi-gpu',
                        help='Number of GPUs to use for parallel processing.',
                        type=int,
                        default=0)
    parser.add_argument(
        '--multi-gpu-force',
        help='Extra flag needed to enable (experimental) multi-gpu support.',
        action='store_true')
    parser.add_argument('--epochs',
                        help='Number of epochs to train.',
                        type=int,
                        default=150)
    parser.add_argument('--steps',
                        help='Number of steps per epoch.',
                        type=int,
                        default=10000)
    parser.add_argument(
        '--snapshot-path',
        help=
        'Path to store snapshots of models during training (defaults to \'./snapshots\')',
        default=args_snapshot_path)
    parser.add_argument('--tensorboard-dir',
                        help='Log directory for Tensorboard output',
                        default=args_tensorboard_dir)
    parser.add_argument('--no-snapshots',
                        help='Disable saving snapshots.',
                        dest='snapshots',
                        action='store_false')
    parser.add_argument('--no-evaluation',
                        help='Disable per epoch evaluation.',
                        dest='evaluation',
                        action='store_false')
    parser.add_argument('--freeze-backbone',
                        help='Freeze training of backbone layers.',
                        action='store_true')
    parser.add_argument('--random-transform',
                        help='Randomly transform image and annotations.',
                        action='store_true')
    parser.add_argument(
        '--image-min-side',
        help='Rescale the image so the smallest side is min_side.',
        type=int,
        default=800)
    parser.add_argument(
        '--image-max-side',
        help='Rescale the image if the largest side is larger than max_side.',
        type=int,
        default=1333)

    return check_args(parser.parse_args(args))