API Reference

This API documentation is not exhaustive, but covers most of the public API that is important to typical Raster Vision usage.

ExperimentConfigBuilder

An ExperimentConfigBuilder is created by calling

rv.ExperimentConfig.builder()
class rastervision.experiment.ExperimentConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

clear_command_uris()

Clears existing command URIs and keys. Useful for re-using experiment configs for new builders.

with_analyze_key(key)

Sets the key associated with the analysis stage.

with_analyze_uri(uri)

Sets the location where the results of the analysis stage will be stored.

with_analyzer(analyzer)

Add an analyzer to be used in the analysis stage.

with_analyzers(analyzers)

Add analyzers to be used in the analysis stage.

with_backend(backend)

Specifies the backend to be used, e.g. rv.TF_DEEPLAB.

with_bundle_key(key)

Sets the key associated with the bundling stage.

with_bundle_uri(uri)

Sets the location where the results of the bundling stage will be stored.

with_chip_key(key)

Sets the key associated with the “chip” stage.

with_chip_uri(uri)

Sets the location where the results of the “chip” stage will be stored.

with_custom_config(config)

Sets custom configuration for this experiment. This can be used by plugins such as custom commands.

with_dataset(dataset)

Specifies the dataset to be used.

with_eval_key(key)

Sets the key associated with the evaluation stage.

with_eval_uri(uri)

Sets the location where the results of the evaluation stage will be stored.

with_evaluator(evaluator)

Sets the evaluator to use for the evaluation stage.

with_evaluators(evaluators)

Sets the evaluators to use for the evaluation stage.

with_id(id)

Sets an id for the experiment.

with_predict_key(key)

Sets the key associated with the prediction stage.

with_predict_uri(uri)

Sets the location where the results of the prediction stage will be stored.

with_root_uri(uri)

Sets the root directory where all output will be stored unless subsequently overridden.

with_stats_analyzer()

Add a stats analyzer to be used in the analysis stage.

with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_train_key(key)

Sets the key associated with the training stage.

with_train_uri(uri)

Sets the location where the results of the training stage will be stored.

DatasetConfigBuilder

A DatasetConfigBuilder is created by calling

rv.DatasetConfig.builder()
class rastervision.data.DatasetConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_augmentor(augmentor)

Sets the data augmentor to be used.

with_augmentors(augmentors)

Sets the data augmentors to be used.

with_test_scene(scene)

Sets the scene to be used for testing.

with_test_scenes(scenes)

Sets the scenes to be used for testing.

with_train_scene(scene)

Sets the scene to be used for training.

with_train_scenes(scenes)

Sets the scenes to be used for training.

with_validation_scene(scene)

Sets the scene to be used for validation.

with_validation_scenes(scenes)

Sets the scenes to be used for validation.

TaskConfigBuilder

TaskConfigBuilders are created by calling

rv.TaskConfig.builder(TASK_TYPE)

Where TASK_TYPE is one of the following:

rv.CHIP_CLASSIFICATION

class rastervision.task.ChipClassificationConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_chip_size(chip_size)

Set the chip_size for this task.

Note that some model implementations have a minimum size of input they can handle. A value of > 200 is usually safe.

Parameters

chip_size – (int) chip size in units of pixels

with_classes(classes: Union[rastervision.core.class_map.ClassMap, List[str], List[rastervision.protos.class_item_pb2.ClassItem], List[rastervision.core.class_map.ClassItem], Dict[str, int], Dict[str, Tuple[int, str]]])

Set the classes for this task.

Parameters

classes – Either a list of class names, a dict which maps class names to class ids, or a dict which maps class names to a tuple of (class_id, color), where color is a PIL color string.

with_debug(debug)

Flag for producing debug products.

with_predict_batch_size(predict_batch_size)

Sets the batch size to use during prediction.

with_predict_debug_uri(predict_debug_uri)

Set the directory to place prediction debug images

with_predict_package_uri(predict_package_uri)

Sets the URI to save a predict package URI to during bundle.

rv.OBJECT_DETECTION

class rastervision.task.ObjectDetectionConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_chip_options(neg_ratio=1, ioa_thresh=0.8, window_method='chip', label_buffer=0.0)

Sets object detection configurations for the Chip command

Parameters
  • neg_ratio – The ratio of negative chips (those containing no bounding boxes) to positive chips. This can be useful if the statistics of the background is different in positive chips. For example, in car detection, the positive chips will always contain roads, but no examples of rooftops since cars tend to not be near rooftops. This option is not used when window_method is sliding.

  • ioa_thresh – When a box is partially outside of a training chip, it is not clear if (a clipped version) of the box should be included in the chip. If the IOA (intersection over area) of the box with the chip is greater than ioa_thresh, it is included in the chip.

  • window_method

    Different models in the Object Detection API have different inputs. Some models allow variable size inputs so several methods of building training data are required

    Valid values are: - chip (default) - label

    • each label’s bounding box is the positive window

    • image
      • each image is the positive window

    • sliding
      • each image is from a sliding window with 50% overlap

  • label_buffer – If method is “label”, the positive window can be buffered. If value is >= 0. and < 1., the value is treated as a percentage If value is >= 1., the value is treated in number of pixels

with_chip_size(chip_size)

Set the chip_size for this task.

Note that some model implementations have a minimum size of input they can handle. A value of > 200 is usually safe.

Parameters

chip_size – (int) chip size in units of pixels

with_classes(classes: Union[rastervision.core.class_map.ClassMap, List[str], List[rastervision.protos.class_item_pb2.ClassItem], List[rastervision.core.class_map.ClassItem], Dict[str, int], Dict[str, Tuple[int, str]]])

Set the classes for this task.

Parameters

classes – Either a list of class names, a dict which maps class names to class ids, or a dict which maps class names to a tuple of (class_id, color), where color is a PIL color string.

with_debug(debug)

Flag for producing debug products.

with_predict_batch_size(predict_batch_size)

Sets the batch size to use during prediction.

with_predict_debug_uri(predict_debug_uri)

Set the directory to place prediction debug images

with_predict_options(merge_thresh=0.5, score_thresh=0.5)

Prediction options for this task.

Parameters
  • merge_thresh – If predicted boxes have an IOA (intersection over area) greater than merge_thresh, then they are merged into a single box during postprocessing. This is needed since the sliding window approach results in some false duplicates.

  • score_thresh – Predicted boxes are only output if their score is above score_thresh.

with_predict_package_uri(predict_package_uri)

Sets the URI to save a predict package URI to during bundle.

rv.SEMANTIC_SEGMENTATION

class rastervision.task.SemanticSegmentationConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_chip_options(window_method='random_sample', target_classes=None, debug_chip_probability=0.25, negative_survival_probability=1.0, chips_per_scene=1000, target_count_threshold=1000, stride=None)

Sets semantic segmentation configurations for the Chip command.

Parameters
  • window_method – Window method to use for chipping. Options are: random_sample, sliding

  • target_classes – list of class ids to train model on

  • debug_chip_probability – probability of generating a debug chip. Applies to the ‘random_sample’ window method.

  • negative_survival_probability – probability that a sampled negative chip will be utilized if it does not contain more pixels than target_count_threshold. Applies to the ‘random_sample’ window method.

  • chips_per_scene – number of chips to generate per scene. Applies to the ‘random_sample’ window method.

  • target_count_threshold – minimum number of pixels covering target_classes that a chip must have. Applies to the ‘random_sample’ window method.

  • stride – Stride of windows across image. Defaults to half the chip size. Applies to the ‘sliding_window’ method.

Returns

SemanticSegmentationConfigBuilder

with_chip_size(chip_size)

Set the chip_size for this task.

Note that some model implementations have a minimum size of input they can handle. A value of > 200 is usually safe.

Parameters

chip_size – (int) chip size in units of pixels

with_classes(classes: Union[rastervision.core.class_map.ClassMap, List[str], List[rastervision.protos.class_item_pb2.ClassItem], List[rastervision.core.class_map.ClassItem], Dict[str, int], Dict[str, Tuple[int, str]]])

Set the classes for this task.

Parameters

classes – Either a list of class names, a dict which maps class names to class ids, or a dict which maps class names to a tuple of (class_id, color), where color is a PIL color string.

with_debug(debug)

Flag for producing debug products.

with_predict_batch_size(predict_batch_size)

Sets the batch size to use during prediction.

with_predict_chip_size(chip_size)

Set the chip_size to use only at prediction time for this task.

Parameters

chip_size – Integer value chip size

with_predict_debug_uri(predict_debug_uri)

Set the directory to place prediction debug images

with_predict_package_uri(predict_package_uri)

Sets the URI to save a predict package URI to during bundle.

BackendConfig

There are backends based on PyTorch and Tensorflow. Remember to use the appropriate Docker image depending on the backend. Note that the Tensorflow backends are being sunsetted. BackendConfigBuilders are created by calling

rv.BackendConfig.builder(BACKEND_TYPE)

Where BACKEND_TYPE is one of the following:

rv.PYTORCH_SEMANTIC_SEGMENTATION

class rastervision.backend.pytorch_semantic_segmentation_config.PyTorchSemanticSegmentationConfigBuilder(prev_config=None)
build()

Returns the configuration that is built by this builder.

config_class

alias of PyTorchSemanticSegmentationConfig

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)
with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_pretrained_uri(pretrained_uri)

pretrained_uri should be uri of exported model file.

with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_train_options(batch_size=8, lr=0.0001, one_cycle=True, num_epochs=5, model_arch='resnet50', sync_interval=1, debug=False, log_tensorboard=True, run_tensorboard=True)

Set options for training models.

Parameters
  • batch_size – (int) the batch size

  • lr – (float) the learning rate if using a fixed LR (ie. one_cycle is False), or the maximum LR to use if one_cycle is True

  • one_cycle – (bool) True if cyclic learning rate scheduler should be used. This cycles the LR once during the course of training and seems to result in a pretty consistent improvement. See lr for more details.

  • num_epochs – (int) number of epochs (sweeps through training set) to train model for

  • model_arch – (str) classification model backbone to use for DeepLabV3 architecture. Currently, only Resnet50 works.

  • sync_interval – (int) sync training directory to cloud every sync_interval epochs.

  • debug – (bool) if True, save debug chips (ie. visualizations of input to model during training) during training and use single-core for creating minibatches.

  • log_tensorboard – (bool) if True, write events to Tensorboard log file

  • run_tensorboard – (bool) if True, run a Tensorboard server at port 6006 that uses the logs generated by the log_tensorboard option

rv.PYTORCH_CHIP_CLASSIFICATION

class rastervision.backend.pytorch_chip_classification_config.PyTorchChipClassificationConfigBuilder(prev_config=None)
build()

Returns the configuration that is built by this builder.

config_class

alias of PyTorchChipClassificationConfig

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)
with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_pretrained_uri(pretrained_uri)

pretrained_uri should be uri of exported model file.

with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_train_options(batch_size=8, lr=0.0001, one_cycle=True, num_epochs=1, model_arch='resnet18', sync_interval=1, debug=False, log_tensorboard=True, run_tensorboard=True)

Set options for training models.

Parameters
  • batch_size – (int) the batch size

  • weight_decay – (float) the weight decay

  • lr – (float) the learning rate if using a fixed LR (ie. one_cycle is False), or the maximum LR to use if one_cycle is True

  • one_cycle – (bool) True if cyclic learning rate scheduler should be used. This cycles the LR once during the course of training and seems to result in a pretty consistent improvement. See lr for more details.

  • num_epochs – (int) number of epochs (sweeps through training set) to train model for

  • model_arch – (str) Any classification model option in torchvision.models is valid, for example, resnet18.

  • sync_interval – (int) sync training directory to cloud every sync_interval epochs.

  • debug – (bool) if True, save debug chips (ie. visualizations of input to model during training) during training and use single-core for creating minibatches.

  • log_tensorboard – (bool) if True, write events to Tensorboard log file

  • run_tensorboard – (bool) if True, run a Tensorboard server at port 6006 that uses the logs generated by the log_tensorboard option

rv.PYTORCH_OBJECT_DETECTION

class rastervision.backend.pytorch_object_detection_config.PyTorchObjectDetectionConfigBuilder(prev_config=None)

Object detection using PyTorch and Faster-RCNN/Resnet50 from torchvision.

build()

Returns the configuration that is built by this builder.

config_class

alias of PyTorchObjectDetectionConfig

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)
with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_pretrained_uri(pretrained_uri)

pretrained_uri should be uri of exported model file.

with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_train_options(batch_size=8, lr=0.0001, one_cycle=True, num_epochs=5, model_arch='resnet18', sync_interval=1, log_tensorboard=True, run_tensorboard=True, debug=False)

Set options for training models.

Parameters
  • batch_size – (int) the batch size

  • lr – (float) the learning rate if using a fixed LR (ie. one_cycle is False), or the maximum LR to use if one_cycle is True

  • one_cycle – (bool) True if cyclic learning rate scheduler should be used. This cycles the LR once during the course of training and seems to result in a pretty consistent improvement. See lr for more details.

  • num_epochs – (int) number of epochs (sweeps through training set) to train model for

  • model_arch – (str) classification model backbone to use. Any Resnet option in torchvision.models is valid, for example, resnet18.

  • sync_interval – (int) sync training directory to cloud every sync_interval epochs.

  • log_tensorboard – (bool) if True, write events to Tensorboard log file

  • run_tensorboard – (bool) if True, run a Tensorboard server at port 6006 that uses the logs generated by the log_tensorboard option

  • debug – (bool) if True, save debug chips (ie. visualizations of input to model during training) during training and use single-core for creating minibatches.

rv.KERAS_CLASSIFICATION

class rastervision.backend.keras_classification_config.KerasClassificationConfigBuilder(prev=None)
build()

Build this configuration.

with_batch_size(batch_size)

Sets the training batch size.

with_config(config_mod, ignore_missing_keys=False, set_missing_keys=False)

Modify the backend configuration.

Given a dict, modify the tensorflow pipeline configuration such that keys that are found recursively in the configuration are replaced with those values. TODO: better explanation.

with_debug(debug)

Sets the debug flag for this backend.

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)

Sets the filename of the trained model.

with_num_epochs(num_epochs)

Sets the number of training epochs.

with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_template(template)

Use a template as the base for configuring Keras Classification.

Parameters

template – dict, string or uri

with_train_options(sync_interval=600, do_monitoring=True, replace_model=False)

Sets the train options for this backend.

Parameters
  • sync_interval – How often to sync output of training to the cloud (in seconds).

  • do_monitoring – Run process to monitor training (eg. Tensorboard)

  • replace_model – Replace the model checkpoint if exists. If false, this will continue training from the checkpoint if it exists, if the backend allows for this.

with_training_data_uri(training_data_uri)

Whence comes the training data?

Parameters

training_data_uri – The location of the training data.

with_training_output_uri(training_output_uri)

Whither goes the training output?

Parameters

training_output_uri – The location where the training output will be stored.

rv.TF_OBJECT_DETECTION

class rastervision.backend.tf_object_detection_config.TFObjectDetectionConfigBuilder(prev=None)
build()

Build this configuration.

Set any values into the TF object detection pipeline config as necessary.

with_batch_size(batch_size)

Sets the training batch size.

with_config(config_mod, ignore_missing_keys=False, set_missing_keys=False)

Given a dict, modify the tensorflow pipeline configuration.

Modify it such that keys that are found recursively in the configuration are replaced with those values. TODO: better explanation.

with_debug(debug)

Sets the debug flag for this backend.

with_fine_tune_checkpoint_name(fine_tune_checkpoint_name)

Defines the name of the fine tune checkpoint for this model.

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)

Defines the name of the model file that will be created for this model after training.

with_num_steps(num_steps)

Sets the number of training steps.

with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_script_locations(model_main_uri='/opt/tf-models/object_detection/model_main.py', export_uri='/opt/tf-models/object_detection/export_inference_graph.py')
with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_template(template)

Use a template for TF Object Detection pipeline config.

Parameters

template – A dict, string or uri as the base for the TF Object Detection API model training pipeline, for example those found here: https://github.com/tensorflow/models/tree/eef6bb5bd3b3cd5fcf54306bf29750b7f9f9a5ea/research/object_detection/samples/configs # noqa

with_train_options(sync_interval=600, do_monitoring=True, replace_model=False)

Sets the train options for this backend.

Parameters
  • sync_interval – How often to sync output of training to the cloud (in seconds).

  • do_monitoring – Run process to monitor training (eg. Tensorboard)

  • replace_model – Replace the model checkpoint if exists. If false, this will continue training from checkpoing if exists, if the backend allows for this.

with_training_data_uri(training_data_uri)

Whence comes the training data?

Parameters

training_data_uri – The location of the training data.

with_training_output_uri(training_output_uri)

Whither goes the training output?

Parameters

training_output_uri – The location where the training output will be stored.

rv.TF_DEEPLAB

class rastervision.backend.tf_deeplab_config.TFDeeplabConfigBuilder(prev=None)
build()

Build this configuration.

with_batch_size(batch_size)

Sets the training batch size.

with_config(config_mod, ignore_missing_keys=False, set_missing_keys=False)

Given a dict, modify the tensorflow pipeline configuration.

Modify it such that keys that are found recursively in the configuration are replaced with those values.

with_debug(debug)

Sets the debug flag for this backend.

with_fine_tune_checkpoint_name(fine_tune_checkpoint_name)

Sets the name of the fine tune checkpoint for the model.

with_model_defaults(model_defaults_key)

Sets the backend configuration and pretrained model defaults according to the model defaults configuration.

with_model_uri(model_uri)

Sets the filename for the model that will be trained.

with_num_clones(num_clones)

Sets the number of clones (useful for multi-GPU training).

with_num_steps(num_steps)

Sets the number of training steps.

with_pretrained_model(uri)

Set a pretrained model URI. The filetype and meaning for this model will be different based on the backend implementation.

with_script_locations(train_py='/opt/tf-models/deeplab/train.py', export_py='/opt/tf-models/deeplab/export_model.py', eval_py='/opt/tf-models/deeplab/eval.py')
with_task(task)

Sets a specific task type.

Parameters

task – A TaskConfig object.

with_template(template)

Use a TFDL config template from dict, string or uri.

with_train_options(train_restart_dir=None, sync_interval=600, do_monitoring=True, replace_model=False, do_eval=False)

Sets the train options for this backend.

Parameters
  • sync_interval – How often to sync output of training to the cloud (in seconds).

  • do_monitoring – Run process to monitor training (eg. Tensorboard)

  • replace_model – Replace the model checkpoint if exists. If false, this will continue training from checkpoint if exists, if the backend allows for this.

  • do_eval – Boolean determining whether to run the eval script.

with_training_data_uri(training_data_uri)

Whence comes the training data?

Parameters

training_data_uri – The location of the training data.

with_training_output_uri(training_output_uri)

Whither goes the training output?

Parameters

training_output_uri – The location where the training output will be stored.

SceneConfig

SceneConfigBuilders are created by calling

rv.SceneConfig.builder()
class rastervision.data.SceneConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

clear_aois()

Clears the AOIs for this scene

clear_label_source()

Clears the label source for this scene

clear_label_store()

Clears the label store for this scene

with_aoi_uri(uri)

Sets the Area of Interest for the scene.

Parameters

uri – a URI of a GeoJSON file with polygons.

with_aoi_uris(uris)

Sets the areas of interest for the scene.

Parameters

uris – List of URIs each to a GeoJSON file with polygons.

with_id(id)

Sets an id for the scene.

with_label_source(label_source: Union[str, rastervision.data.label_source.label_source_config.LabelSourceConfig])

Sets the raster source for this scene.

Parameters

label_source – Can either be a label source configuration, or a string. If a string, the registry will be queried to grab the default LabelSourceConfig for the string.

Note

A task must be set with with_task before calling this, if calling with a string.

with_label_store(label_store: Union[str, rastervision.data.label_store.label_store_config.LabelStoreConfig, None] = None)

Sets the raster store for this scene.

Parameters

label_store – Can either be a label store configuration, or a string, or None. If a string, the registry will be queried to grab the default LabelStoreConfig for the string. If None, then the default for the task from the regsitry will be used.

Note

A task must be set with with_task before calling this, if calling with a string.

with_raster_source(raster_source: Union[str, rastervision.data.raster_source.raster_source_config.RasterSourceConfig], channel_order=None)

Sets the raster source for this scene.

Parameters
  • raster_source – Can either be a raster source configuration, or a string. If a string, the registry will be queried to grab the default RasterSourceConfig for the string.

  • channel_order – Optional channel order for this raster source.

with_task(task)

Sets a specific task type, e.g. rv.OBJECT_DETECTION.

RasterSourceConfig

RasterSourceConfigBuilders are created by calling

rv.RasterSourceConfig.builder(SOURCE_TYPE)

Where SOURCE_TYPE is one of the following:

rv.RASTERIO_SOURCE

class rastervision.data.RasterioSourceConfigBuilder(prev=None)

This RasterSource can read any file that can be opened by Rasterio/GDAL.

This includes georeferenced formats such as GeoTIFF and non-georeferenced formats such as JPG. See https://www.gdal.org/formats_list.html for more details.

build()

Returns the configuration that is built by this builder.

with_channel_order(channel_order)

Defines the channel order for this raster source.

This defines the subset of channel indices and their order to use when extracting chips from raw imagery.

Parameters

channel_order – list of channel indices

with_shifts(x, y)

Set the x- and y-shifts in meters.

This will only have an effect on georeferenced imagery.

Parameters
  • x – A number of meters to shift along the x-axis. A positive shift moves the “camera” to the right.

  • y – A number of meters to shift along the y-axis. A positive shift moves the “camera” down.

with_stats_transformer()

Add a stats transformer to the raster source.

with_transformer(transformer)

A transformer to be applied to the raster data.

Parameters

transformer – A transformer to apply to the raster data.

with_transformers(transformers)

Transformers to be applied to the raster data.

Parameters

transformers – A list of transformers to apply to the raster data.

with_uri(uri)

Set URI for raster files that can be read by Rasterio.

with_uris(uris)

Set URIs for raster files that can be read by Rasterio.

rv.RASTERIZED_SOURCE

class rastervision.data.RasterizedSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_channel_order(channel_order)

Defines the channel order for this raster source.

This defines the subset of channel indices and their order to use when extracting chips from raw imagery.

Parameters

channel_order – list of channel indices

with_rasterizer_options(background_class_id, all_touched=False)

Specify options for converting GeoJSON to raster.

Parameters
  • background_class_id – The class_id to use for background pixels that don’t overlap with any shapes in the GeoJSON file.

  • all_touched – If True, all pixels touched by geometries will be burned in. If false, only pixels whose center is within the polygon or that are selected by Bresenham’s line algorithm will be burned in. (See rasterio.features.rasterize).

with_stats_transformer()

Add a stats transformer to the raster source.

with_transformer(transformer)

A transformer to be applied to the raster data.

Parameters

transformer – A transformer to apply to the raster data.

with_transformers(transformers)

Transformers to be applied to the raster data.

Parameters

transformers – A list of transformers to apply to the raster data.

with_uri(uri)
with_vector_source(vector_source)

Set the vector_source.

Parameters

vector_source (str or VectorSource) – a URI and use the default provider to construct a VectorSource.

LabelSourceConfig

LabelSourceConfigBuilders are created by calling

rv.LabelSourceConfig.builder(SOURCE_TYPE)

Where SOURCE_TYPE is one of the following:

rv.CHIP_CLASSIFICATION

class rastervision.data.ChipClassificationLabelSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_background_class_id(background_class_id)

Sets the background class ID.

Optional class_id to use as the background class; ie. the one that is used when a window contains no boxes. If not set, empty windows have None set as their class_id.

with_cell_size(cell_size)

Sets the cell size of the chips.

If not explicitly set, the chip size will be used if this object is created as part of an experiment.

Parameters

cell_size – (int) the size of the cells in units of pixels

with_infer_cells(infer_cells)

Set if this label source should infer cells.

If true, the label source will infer the cell polygon and label from the polygons in the vector_source. If the labels are already cells and properly labeled, this can be False.

with_ioa_thresh(ioa_thresh)

The minimum IOA of a polygon and cell.

with_pick_min_class_id(pick_min_class_id)

Set this label source to pick min class ID

If true, the class_id for a cell is the minimum class_id of the boxes in that cell. Otherwise, pick the class_id of the box covering the greatest area.

with_uri(uri)
with_use_intersection_over_cell(use_intersection_over_cell)

Set this label source to use intersection over cell or not.

If use_intersection_over_cell is true, then use the area of the cell as the denominator in the IOA. Otherwise, use the area of the polygon.

with_vector_source(vector_source)

Set the vector_source.

Parameters

vector_source (str or VectorSource) – a URI and use the default provider to construct a VectorSource.

rv.OBJECT_DETECTION

class rastervision.data.ObjectDetectionLabelSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_uri(uri)
with_vector_source(vector_source)

Set the vector_source.

Parameters

vector_source (str or VectorSource) – a URI and use the default provider to construct a VectorSource.

rv.SEMANTIC_SEGMENTATION

class rastervision.data.SemanticSegmentationLabelSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_raster_source(source, channel_order=None)

Set raster_source.

Parameters

source – (RasterSourceConfig) A RasterSource assumed to have RGB values that are mapped to class_ids using the rgb_class_map.

Returns

SemanticSegmentationLabelSourceConfigBuilder

with_rgb_class_map(rgb_class_map)

Set rgb_class_map.

Parameters

rgb_class_map – (something accepted by ClassMap.construct_from) a class map with color values used to map RGB values to class ids

Returns

SemanticSegmentationLabelSourceConfigBuilder

VectorSourceConfig

VectorSourceConfigBuilders are created by calling

rv.VectorSourceConfig.builder(SOURCE_TYPE)

Where SOURCE_TYPE is one of the following:

rv.GEOJSON_SOURCE

class rastervision.data.GeoJSONVectorSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_buffers(line_bufs=None, point_bufs=None)

Set options for buffering lines and points into polygons.

For example, this is useful for buffering lines representing roads so that their width roughly matches the width of roads in the imagery.

Parameters
  • line_bufs – (dict or None) If none, uses default buffer value of 1. Otherwise, a map from class_id to number of pixels to buffer by. If the buffer value is None, then no buffering will be performed and the LineString or Point won’t get converted to a Polygon. Not converting to Polygon is incompatible with the currently available LabelSources, but may be useful in the future.

  • point_bufs – (dict or None) same as above, but used for buffering Points into Polygons.

with_class_inference(class_id_to_filter=None, default_class_id=1)

Set options for inferring the class of each feature.

For more info on how class inference works, see ClassInference.infer_class()

Parameters
with_uri(uri)

rv.VECTOR_TILE_SOURCE

class rastervision.data.VectorTileVectorSourceConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_buffers(line_bufs=None, point_bufs=None)

Set options for buffering lines and points into polygons.

For example, this is useful for buffering lines representing roads so that their width roughly matches the width of roads in the imagery.

Parameters
  • line_bufs – (dict or None) If none, uses default buffer value of 1. Otherwise, a map from class_id to number of pixels to buffer by. If the buffer value is None, then no buffering will be performed and the LineString or Point won’t get converted to a Polygon. Not converting to Polygon is incompatible with the currently available LabelSources, but may be useful in the future.

  • point_bufs – (dict or None) same as above, but used for buffering Points into Polygons.

with_class_inference(class_id_to_filter=None, default_class_id=1)

Set options for inferring the class of each feature.

For more info on how class inference works, see ClassInference.infer_class()

Parameters
with_id_field(id_field='@id')

Set the name of the id field.

Parameters

id_field – (str) name of field in feature[‘properties’] that contains the feature’s unique id. Used for merging features that are split across tile boundaries.

with_uri(uri)

Set the URI of the vector tiles.

Parameters

uri – (str) URI of vector tile endpoint. Should either contain {z}/{x}/{y} or point to .mbtiles file.

with_zoom(zoom)

Set the zoom level to use when accessing vector tiles.

Note: the vector tiles need to support the zoom level. Typically only a subset of zoom levels are supported.

LabelStoreConfig

LabelStoreConfigBuilders are created by calling

rv.LabelStoreConfig.builder(STORE_TYPE)

Where STORE_TYPE is one of the following:

rv.CHIP_CLASSIFICATION_GEOJSON

class rastervision.data.ChipClassificationGeoJSONStoreConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_uri(uri)

Set URI for a GeoJSON used to read/write predictions.

For rv.OBJECT_DETECTION:

rv.OBJECT_DETECTION_GEOJSON

class rastervision.data.ObjectDetectionGeoJSONStoreConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_uri(uri)

Set URI for a GeoJSON used to read/write predictions.

rv.SEMANTIC_SEGMENTATION_RASTER

class rastervision.data.SemanticSegmentationRasterStoreConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_rgb(rgb)

Set flag for writing RGB data using the class map.

Otherwise this method will write the class ID into a single band.

with_uri(uri)

Set URI for a GeoTIFF used to read/write predictions.

with_vector_output(vector_output)

Configure vector output for predictions.

Parameters

vector_output – Either a list of dictionaries or a protobuf object. The dictionary or the object contain (respectively) keys (attributes) called ‘denoise’, ‘uri’, ‘class_id’, and ‘mode’. The value associated with the ‘denoise’ key specifies the radius of the structural element used to perform a low-pass filtering process on the mask (see https://en.wikipedia.org/wiki/Mathematical_morphology#Opening). The value associated with the ‘uri’ key is either a file where the GeoJSON prediction will be written, or “” indicating that the filename should be auto-generated. ‘class_id’ is the integer prediction class that is of interest. The ‘mode’ key must be set to ‘buildings’ or ‘polygons’.

RasterTransformerConfig

RasterTransformerConfigBuilders are created by calling

rv.RasterTransformerConfig.builder(TRANSFORMER_TYPE)

Where TRANSFORMER_TYPE is one of the following:

rv.STATS_TRANSFORMER

class rastervision.data.StatsTransformerConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_stats_uri(stats_uri)

Set the stats_uri.

Parameters

stats_uri – URI to the stats json to use

AugmentorConfig

AugmentorConfigBuilders are created by calling

rv.AugmentorConfig.builder(AUGMENTOR_TYPE)

Where AUGMENTOR_TYPE is one of the following:

rv.NODATA_AUGMENTOR

class rastervision.augmentor.NodataAugmentorConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_probability(aug_prob)

Sets the probability for this augmentation.

Determines how probable this augmentation will happen to negative chips.

Parameters

aug_prob – Float value between 0.0 and 1.0

AnalyzerConfig

AnalyzerConfigBuilders are created by calling

rv.AnalyzerConfig.builder(ANALYZER_TYPE)

Where ANALYZER_TYPE is one of the following:

rv.STATS_ANALYZER

class rastervision.analyzer.StatsAnalyzerConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_sample_prob(sample_prob)

Set the sample_prob used to sample a subset of each scene.

If sample_prob is set, then a subset of each scene is used to compute stats which speeds up the computation. Roughly speaking, if sample_prob=0.5, then half the pixels in the scene will be used. More precisely, the number of chips is equal to sample_prob * (width * height / 300^2), or 1, whichever is greater. Each chip is uniformly sampled from the scene with replacement. Otherwise, it uses a sliding window over the entire scene to compute stats.

Parameters

sample_prob – (float or None) between 0 and 1

with_stats_uri(stats_uri)

Set the stats_uri.

Parameters

stats_uri – URI to the stats json to use

EvaluatorConfig

EvaluatorConfigBuilders are created by calling

rv.EvaluatorConfig.builder(Evaluator_TYPE)

Where Evaluator_TYPE is one of the following:

rv.CHIP_CLASSIFICATION_EVALUATOR

class rastervision.evaluation.ChipClassificationEvaluatorConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_class_map(class_map)

Set the class map to be used for evaluation.

Parameters

class_map – The class map to be used

with_output_uri(output_uri)

Set the output_uri.

Parameters

output_uri – URI to the stats json to use

with_task(task)

Sets a specific task type, e.g. rv.OBJECT_DETECTION.

with_vector_output_uri(vector_output_uri)

Set the vector_output_uri.

Parameters

vector_output_uri – URI to the vector stats json to use

rv.OBJECT_DETECTION_EVALUATOR

class rastervision.evaluation.ObjectDetectionEvaluatorConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_class_map(class_map)

Set the class map to be used for evaluation.

Parameters

class_map – The class map to be used

with_output_uri(output_uri)

Set the output_uri.

Parameters

output_uri – URI to the stats json to use

with_task(task)

Sets a specific task type, e.g. rv.OBJECT_DETECTION.

with_vector_output_uri(vector_output_uri)

Set the vector_output_uri.

Parameters

vector_output_uri – URI to the vector stats json to use

rv.SEMANTIC_SEGMENTATION_EVALUATOR

class rastervision.evaluation.SemanticSegmentationEvaluatorConfigBuilder(prev=None)
build()

Returns the configuration that is built by this builder.

with_class_map(class_map)

Set the class map to be used for evaluation.

Parameters

class_map – The class map to be used

with_output_uri(output_uri)

Set the output_uri.

Parameters

output_uri – URI to the stats json to use

with_task(task)

Sets a specific task type, e.g. rv.OBJECT_DETECTION.

with_vector_output_uri(vector_output_uri)

Set the vector_output_uri.

Parameters

vector_output_uri – URI to the vector stats json to use

Aux Commands

class rastervision.command.aux.CogifyCommand(command_config)

Turns a GDAL-readable raster into a Cloud Optimized GeoTiff.

Configuration:

uris: A list of tuples of (src_path, dest_path) where dest_path is

the COG URI.

block_size: The tile size for the COG. Defaults to 512.

resample_method: The resample method to use for overviews. Defaults to ‘near’.

compression: The compression method to use. Defaults to ‘deflate’. Use ‘none’ for no compression.

overviews: The overview levels to create. Defaults to [2, 4, 8, 16, 32]

Aux Command Options

class rastervision.command.aux_command.AuxCommandOptions(split_on=None, inputs=<function AuxCommandOptions.<lambda>>, outputs=<function AuxCommandOptions.<lambda>>, include_by_default=False, required_fields=None)
__init__(split_on=None, inputs=<function AuxCommandOptions.<lambda>>, outputs=<function AuxCommandOptions.<lambda>>, include_by_default=False, required_fields=None)

Instantiate an AuxCommandOptions object.

Parameters
  • split_on (str) – The property of the configuration to use when splitting.

  • configuration at this property must be a list. (The) –

  • inputs – A function that, given the configuration, returns a list of

  • that are inputs into the command. Along with outputs, this allows (URIs) –

  • Vision to correctly determine if there are any missing inputs, or (Raster) –

  • the command has already been run. It will also allow the command to (if) –

  • run in the right sequence if run with other commands that will produce (be) –

  • command's inputs as their outputs. (this) –

  • outputs – A function that, given the configuration, returns a list of

  • that are outputs of the command. See the details on inputs. (URIs) –

  • include_by_default – Set this to True if you want this command to run

  • default, meaning it will run every time no specific commands are issued (by) –

  • the command line (on) –

  • required_fields – Set this to properties of the configuration that are

  • If the user of the command does not set values into those (required.) –

  • properties, an error will be thrown at configuration building (configuration) –

  • time.

Predictor

class rastervision.Predictor(prediction_package_uri, tmp_dir, update_stats=False, channel_order=None)

Class for making predictions based off of a prediction package.

__init__(prediction_package_uri, tmp_dir, update_stats=False, channel_order=None)

Creates a new Predictor.

Parameters
  • prediction_package_uri – The URI of the prediction package to use. Can be any type of URI that Raster Vision can read.

  • tmp_dir – Temporary directory in which to store files that are used by the Predictor. This directory is not cleaned up by this class.

  • update_stats – Option indicating if any Analyzers should be run on the image to be predicted on. Otherwise, the Predictor will use the output of Analyzers that are bundled with the predict package. This is useful, for instance, if you are predicting against imagery that needs to be normalized with a StatsAnalyzer, and the color profile of the new imagery is significantly different then the imagery the model was trained on.

  • channel_order – Option for a new channel order to use for the imagery being predicted against. If not present, the channel_order from the original configuration in the predict package will be used.

load_model()

Load the model for this Predictor.

This is useful if you are going to make multiple predictions with the model, and want it to be fast on the first prediction.

Note: This is called implicitly on the first call of ‘predict’ if it hasn’t been called already.

predict(image_uri, label_uri=None, config_uri=None)

Generate predictions for the given image.

Parameters
  • image_uri – URI of the image to make predictions against. This can be any type of URI readable by Raster Vision FileSystems.

  • label_uri – Optional URI to save labels off into.

  • config_uri – Optional URI in which to save the bundle_config, which can be useful to client applications for understanding how to interpret the labels.

  • Returns – rastervision.data.labels.Labels containing the predicted labels.

Plugin Registry

class rastervision.plugin.PluginRegistry(plugin_config, rv_home)
register_aux_command(command_type, command_class)

Registers a custom AuxCommand as a plugin.

Parameters
  • - The key used for this plugin. This will be used to (command_type) – construct the builder in a “.builder(key)” call.

  • - The subclass of AuxCommand subclass to register. (command_class) –

register_command_config_builder(command_type, builder_class)

Registers a ConfigBuilder as a plugin.

Parameters
  • - The key used for this plugin. This will be used to (command_type) – construct the builder in a “.builder(key)” call.

  • - The subclass of CommandConfigBuilder that builds (builder_class) – the CommandConfig for this plugin.

register_config_builder(group, key, builder_class)

Registers a ConfigBuilder as a plugin.

Parameters
  • - The Config group, e.g. rv.BACKEND, rv.TASK. (group) –

  • - The key used for this plugin. This will be used to (key) – construct the builder in a “.builder(key)” call.

  • - The subclass of ConfigBuilder that builds (builder_class) – the Config for this plugin.

register_default_evaluator(provider_class)

Registers an EvaluatorDefaultProvider for use as a plugin.

register_default_label_source(provider_class)

Registers a LabelSourceDefaultProvider for use as a plugin.

register_default_label_store(provider_class)

Registers a LabelStoreDefaultProvider for use as a plugin.

register_default_raster_source(provider_class)

Registers a RasterSourceDefaultProvider for use as a plugin.

register_default_vector_source(provider_class)

Registers a VectorSourceDefaultProvider for use as a plugin.

register_experiment_runner(runner_key, runner_class)

Registers an ExperimentRunner as a plugin.

Parameters
  • - The key used to reference this plugin runner. (runner_key) – This is a string that will match the command line argument used to reference this runner; e.g. if the key is “FOO_RUNNER”, then users can use the runner by issuing a “rastervision run foo_runner …” command.

  • - The class of the ExperimentRunner plugin. (runner_class) –

register_filesystem(filesystem_class)

Registers a FileSystem as a plugin.