示例#1
0
def predict(predict_package, image_uri, output_uri, update_stats,
            channel_order, export_config):
    """Make predictions on the image at IMAGE_URI
    using PREDICT_PACKAGE and store the
    prediciton output at OUTPUT_URI.
    """
    if channel_order is not None:
        channel_order = [
            int(channel_ind) for channel_ind in channel_order.split(' ')
        ]

    with RVConfig.get_tmp_dir() as tmp_dir:
        predictor = rv.Predictor(predict_package, tmp_dir, update_stats,
                                 channel_order)
        predictor.predict(image_uri, output_uri, export_config)
示例#2
0
def test_prediction_package_validation(experiment, test, temp_dir, image_uri):
    console_info('Checking predict command validation...')
    errors = []
    pp = experiment.task.predict_package_uri
    predict = rv.Predictor(pp, temp_dir, channel_order=[0, 1, 7]).predict
    try:
        predict(image_uri, 'x.txt')
        e = TestError(test,
                      ('Predictor should have raised exception due to invalid '
                       'channel_order, but did not.'),
                      'in experiment {}'.format(experiment.id))
        errors.append(e)
    except ValueError:
        pass

    return errors
示例#3
0
def test_prediction_package_results(experiment, test, temp_dir, scenes,
                                    scenes_to_uris):
    console_info('Checking predict package produces same results...')
    errors = []
    pp = experiment.task.predict_package_uri
    predict = rv.Predictor(pp, temp_dir).predict

    for scene_config in scenes:
        # Need to write out labels and read them back,
        # otherwise the floating point precision direct box
        # coordinates will not match those from the PREDICT
        # command, which are rounded to pixel coordinates
        # via pyproj logic (in the case of rasterio crs transformer.
        predictor_label_store_uri = os.path.join(
            temp_dir, test.lower(), 'predictor/{}'.format(scene_config.id))
        uri = scenes_to_uris[scene_config.id]

        predict(uri, predictor_label_store_uri)

        scene = scene_config.create_scene(experiment.task, temp_dir)

        scene_labels = scene.prediction_label_store.get_labels()

        extent = scene.raster_source.get_extent()
        crs_transformer = scene.raster_source.get_crs_transformer()
        predictor_label_store = scene_config.label_store \
                                       .for_prediction(
                                           predictor_label_store_uri) \
                                       .create_store(
                                           experiment.task,
                                           extent,
                                           crs_transformer,
                                           temp_dir)

        from rastervision.data import ActivateMixin
        with ActivateMixin.compose(scene, predictor_label_store):
            if not predictor_label_store.get_labels() == scene_labels:
                e = TestError(
                    test, ('Predictor did not produce the same labels '
                           'as the Predict command'),
                    'for scene {} in experiment {}'.format(
                        scene_config.id, experiment.id))
                errors.append(e)

    return errors