Пример #1
0
def create_models_local(p):
    test_image_data_generator = keras.preprocessing.image.ImageDataGenerator()
    test_generator = CSVGenerator(p['test_csv'], p['classes_csv'],
                                  test_image_data_generator, 1)
    model, training_model, prediction_model = create_models(
        num_classes=test_generator.num_classes(), p=p)

    return model, training_model, prediction_model, test_generator
Пример #2
0
if snapshot is not None:
    print('Loading model, this may take a second...')
    model = models.load_model(snapshot, backbone_name=backbone)
    training_model = model
    prediction_model = retinanet_bbox(model=model)
else:
    weights = weights
    # default to imagenet if nothing else is specified
    if weights is None and imagenet_weights:
        weights = backbone_model.download_imagenet()

    print('Creating model, this may take a second...')
    modifier = freeze_model if freeze_backbone else None

    model = backbone_model.retinanet(train_generator.num_classes(),
                                     modifier=modifier)
    if weights is not None:
        model.load_weights(weights, by_name=True, skip_mismatch=True)
    training_model = model

    # make prediction model
    prediction_model = retinanet_bbox(model=model)

    # compile model
    training_model.compile(loss={
        'regression': losses.smooth_l1(),
        'classification': losses.focal()
    },
                           optimizer=keras.optimizers.adam(lr=1e-5,
                                                           clipnorm=0.001))
Пример #3
0
        batch_size=args.batch_size)

    if args.val_path:
        test_image_data_generator = keras.preprocessing.image.ImageDataGenerator(
        )

        # create a generator for testing data
        test_generator = CSVGenerator(
            csv_data_file=args.val_path,
            csv_class_file=args.classes,
            image_data_generator=test_image_data_generator,
            batch_size=args.batch_size)
    else:
        test_generator = None

    num_classes = train_generator.num_classes()

    # create the model
    print('Creating model, this may take a second...')
    model = create_model(num_classes=num_classes, weights=args.weights)

    # compile model (note: set loss to None since loss is added inside layer)
    model.compile(loss={
        'regression': keras_retinanet.losses.smooth_l1(),
        'classification': keras_retinanet.losses.focal()
    },
                  optimizer=keras.optimizers.adam(lr=1e-5, clipnorm=0.001))

    # print model summary
    print(model.summary())