ObjectDetectionConfig#

Note

All Configs are derived from rastervision.pipeline.config.Config, which itself is a pydantic Model.

pydantic model ObjectDetectionConfig[source]#

Configure an ObjectDetection pipeline.

Show JSON schema
{
   "title": "ObjectDetectionConfig",
   "description": "Configure an :class:`.ObjectDetection` pipeline.",
   "type": "object",
   "properties": {
      "root_uri": {
         "title": "Root Uri",
         "description": "The root URI for output generated by the pipeline",
         "type": "string"
      },
      "rv_config": {
         "title": "Rv Config",
         "description": "Used to store serialized RVConfig so pipeline can run in remote environment with the local RVConfig. This should not be set explicitly by users -- it is only used by the runner when running a remote pipeline.",
         "type": "object"
      },
      "plugin_versions": {
         "title": "Plugin Versions",
         "description": "Used to store a mapping of plugin module paths to the latest version number. This should not be set explicitly by users -- it is set automatically when serializing and saving the config to disk.",
         "type": "object",
         "additionalProperties": {
            "type": "integer"
         }
      },
      "type_hint": {
         "title": "Type Hint",
         "default": "object_detection",
         "enum": [
            "object_detection"
         ],
         "type": "string"
      },
      "dataset": {
         "title": "Dataset",
         "description": "Dataset containing train, validation, and optional test scenes.",
         "allOf": [
            {
               "$ref": "#/definitions/DatasetConfig"
            }
         ]
      },
      "backend": {
         "title": "Backend",
         "description": "Backend to use for interfacing with ML library.",
         "allOf": [
            {
               "$ref": "#/definitions/BackendConfig"
            }
         ]
      },
      "evaluators": {
         "title": "Evaluators",
         "description": "Evaluators to run during analyzer command. If list is empty the default evaluator is added.",
         "default": [],
         "type": "array",
         "items": {
            "$ref": "#/definitions/EvaluatorConfig"
         }
      },
      "analyzers": {
         "title": "Analyzers",
         "description": "Analyzers to run during analyzer command. A StatsAnalyzer will be added automatically if any scenes have a RasterTransformer.",
         "default": [],
         "type": "array",
         "items": {
            "$ref": "#/definitions/AnalyzerConfig"
         }
      },
      "train_chip_sz": {
         "title": "Train Chip Sz",
         "description": "Size of training chips in pixels.",
         "default": 300,
         "type": "integer"
      },
      "predict_chip_sz": {
         "title": "Predict Chip Sz",
         "description": "Size of predictions chips in pixels.",
         "default": 300,
         "type": "integer"
      },
      "predict_batch_sz": {
         "title": "Predict Batch Sz",
         "description": "Batch size to use during prediction.",
         "default": 8,
         "type": "integer"
      },
      "chip_nodata_threshold": {
         "title": "Chip Nodata Threshold",
         "description": "Discard chips where the proportion of NODATA values is greater than or equal to this value. Might result in false positives if there are many legitimate black pixels in the chip. Use with caution.",
         "default": 1,
         "minimum": 0,
         "maximum": 1,
         "type": "number"
      },
      "analyze_uri": {
         "title": "Analyze Uri",
         "description": "URI for output of analyze. If None, will be auto-generated.",
         "type": "string"
      },
      "chip_uri": {
         "title": "Chip Uri",
         "description": "URI for output of chip. If None, will be auto-generated.",
         "type": "string"
      },
      "train_uri": {
         "title": "Train Uri",
         "description": "URI for output of train. If None, will be auto-generated.",
         "type": "string"
      },
      "predict_uri": {
         "title": "Predict Uri",
         "description": "URI for output of predict. If None, will be auto-generated.",
         "type": "string"
      },
      "eval_uri": {
         "title": "Eval Uri",
         "description": "URI for output of eval. If None, will be auto-generated.",
         "type": "string"
      },
      "bundle_uri": {
         "title": "Bundle Uri",
         "description": "URI for output of bundle. If None, will be auto-generated.",
         "type": "string"
      },
      "source_bundle_uri": {
         "title": "Source Bundle Uri",
         "description": "If provided, the model will be loaded from this bundle for the train stage. Useful for fine-tuning.",
         "type": "string"
      },
      "chip_options": {
         "title": "Chip Options",
         "default": {
            "neg_ratio": 1.0,
            "ioa_thresh": 0.8,
            "window_method": "ObjectDetectionWindowMethod.chip",
            "label_buffer": null,
            "type_hint": "object_detection_chip_options"
         },
         "allOf": [
            {
               "$ref": "#/definitions/ObjectDetectionChipOptions"
            }
         ]
      },
      "predict_options": {
         "title": "Predict Options",
         "default": {
            "type_hint": "object_detection_predict_options",
            "merge_thresh": 0.5,
            "score_thresh": 0.5
         },
         "allOf": [
            {
               "$ref": "#/definitions/ObjectDetectionPredictOptions"
            }
         ]
      }
   },
   "required": [
      "dataset",
      "backend"
   ],
   "additionalProperties": false,
   "definitions": {
      "ClassConfig": {
         "title": "ClassConfig",
         "description": "Configure class information for a machine learning task.",
         "type": "object",
         "properties": {
            "names": {
               "title": "Names",
               "description": "Names of classes. The i-th class in this list will have class ID = i.",
               "type": "array",
               "items": {
                  "type": "string"
               }
            },
            "colors": {
               "title": "Colors",
               "description": "Colors used to visualize classes. Can be color strings accepted by matplotlib or RGB tuples. If None, a random color will be auto-generated for each class.",
               "type": "array",
               "items": {
                  "anyOf": [
                     {
                        "type": "string"
                     },
                     {
                        "type": "array",
                        "items": {}
                     }
                  ]
               }
            },
            "null_class": {
               "title": "Null Class",
               "description": "Optional name of class in `names` to use as the null class. This is used in semantic segmentation to represent the label for imagery pixels that are NODATA or that are missing a label. If None and the class names include \"null\", it will automatically be used as the null class. If None, and this Config is part of a SemanticSegmentationConfig, a null class will be added automatically.",
               "type": "string"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "class_config",
               "enum": [
                  "class_config"
               ],
               "type": "string"
            }
         },
         "required": [
            "names"
         ],
         "additionalProperties": false
      },
      "RasterTransformerConfig": {
         "title": "RasterTransformerConfig",
         "description": "Configure a :class:`.RasterTransformer`.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "raster_transformer",
               "enum": [
                  "raster_transformer"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "RasterSourceConfig": {
         "title": "RasterSourceConfig",
         "description": "Configure a :class:`.RasterSource`.",
         "type": "object",
         "properties": {
            "channel_order": {
               "title": "Channel Order",
               "description": "The sequence of channel indices to use when reading imagery.",
               "type": "array",
               "items": {
                  "type": "integer"
               }
            },
            "transformers": {
               "title": "Transformers",
               "default": [],
               "type": "array",
               "items": {
                  "$ref": "#/definitions/RasterTransformerConfig"
               }
            },
            "extent": {
               "title": "Extent",
               "description": "Use-specified extent in pixel coords in the form (ymin, xmin, ymax, xmax). Useful for cropping the raster source so that only part of the raster is read from.",
               "type": "array",
               "minItems": 4,
               "maxItems": 4,
               "items": [
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  },
                  {
                     "type": "integer"
                  }
               ]
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "raster_source",
               "enum": [
                  "raster_source"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "LabelSourceConfig": {
         "title": "LabelSourceConfig",
         "description": "Configure a :class:`.LabelSource`.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "label_source",
               "enum": [
                  "label_source"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "LabelStoreConfig": {
         "title": "LabelStoreConfig",
         "description": "Configure a :class:`.LabelStore`.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "label_store",
               "enum": [
                  "label_store"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "SceneConfig": {
         "title": "SceneConfig",
         "description": "Configure a :class:`.Scene` comprising raster data & labels for an AOI.\n    ",
         "type": "object",
         "properties": {
            "id": {
               "title": "Id",
               "type": "string"
            },
            "raster_source": {
               "$ref": "#/definitions/RasterSourceConfig"
            },
            "label_source": {
               "$ref": "#/definitions/LabelSourceConfig"
            },
            "label_store": {
               "$ref": "#/definitions/LabelStoreConfig"
            },
            "aoi_uris": {
               "title": "Aoi Uris",
               "description": "List of URIs of GeoJSON files that define the AOIs for the scene. Each polygon defines an AOI which is a piece of the scene that is assumed to be fully labeled and usable for training or validation. The AOIs are assumed to be in EPSG:4326 coordinates.",
               "type": "array",
               "items": {
                  "type": "string"
               }
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "scene",
               "enum": [
                  "scene"
               ],
               "type": "string"
            }
         },
         "required": [
            "id",
            "raster_source"
         ],
         "additionalProperties": false
      },
      "DatasetConfig": {
         "title": "DatasetConfig",
         "description": "Configure train, validation, and test splits for a dataset.",
         "type": "object",
         "properties": {
            "class_config": {
               "$ref": "#/definitions/ClassConfig"
            },
            "train_scenes": {
               "title": "Train Scenes",
               "type": "array",
               "items": {
                  "$ref": "#/definitions/SceneConfig"
               }
            },
            "validation_scenes": {
               "title": "Validation Scenes",
               "type": "array",
               "items": {
                  "$ref": "#/definitions/SceneConfig"
               }
            },
            "test_scenes": {
               "title": "Test Scenes",
               "default": [],
               "type": "array",
               "items": {
                  "$ref": "#/definitions/SceneConfig"
               }
            },
            "scene_groups": {
               "title": "Scene Groups",
               "description": "Groupings of scenes. Should be a dict of the form: {<group-name>: Set(scene_id_1, scene_id_2, ...)}. Three groups are added by default: \"train_scenes\", \"validation_scenes\", and \"test_scenes\"",
               "default": {},
               "type": "object",
               "additionalProperties": {
                  "type": "array",
                  "items": {
                     "type": "string"
                  },
                  "uniqueItems": true
               }
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "dataset",
               "enum": [
                  "dataset"
               ],
               "type": "string"
            }
         },
         "required": [
            "class_config",
            "train_scenes",
            "validation_scenes"
         ],
         "additionalProperties": false
      },
      "BackendConfig": {
         "title": "BackendConfig",
         "description": "Configure a :class:`.Backend`.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "backend",
               "enum": [
                  "backend"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "EvaluatorConfig": {
         "title": "EvaluatorConfig",
         "description": "Configure an :class:`.Evaluator`.",
         "type": "object",
         "properties": {
            "output_uri": {
               "title": "Output Uri",
               "description": "URI of directory where evaluator output will be saved. Evaluations for each scene-group will be save in a JSON file at <output_uri>/<scene-group-name>/eval.json. If None, and this Config is part of an RVPipeline, this field will be auto-generated.",
               "type": "string"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "evaluator",
               "enum": [
                  "evaluator"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "AnalyzerConfig": {
         "title": "AnalyzerConfig",
         "description": "Configure an :class:`.Analyzer`.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "analyzer",
               "enum": [
                  "analyzer"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "ObjectDetectionWindowMethod": {
         "title": "ObjectDetectionWindowMethod",
         "description": "Enum for window methods\n\n    Attributes:\n        chip: the default method\n    ",
         "enum": [
            "chip",
            "label",
            "image",
            "sliding"
         ]
      },
      "ObjectDetectionChipOptions": {
         "title": "ObjectDetectionChipOptions",
         "description": "Base class that can be extended to provide custom configurations.\n\nThis adds some extra methods to Pydantic BaseModel.\nSee https://pydantic-docs.helpmanual.io/\n\nThe general idea is that configuration schemas can be defined by\nsubclassing this and adding class attributes with types and\ndefault values for each field. Configs can be defined hierarchically,\nie. a Config can have fields which are of type Config.\nValidation, serialization, deserialization, and IDE support is\nprovided automatically based on this schema.",
         "type": "object",
         "properties": {
            "neg_ratio": {
               "title": "Neg Ratio",
               "description": "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.",
               "default": 1.0,
               "type": "number"
            },
            "ioa_thresh": {
               "title": "Ioa Thresh",
               "description": "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.",
               "default": 0.8,
               "type": "number"
            },
            "window_method": {
               "default": "chip",
               "allOf": [
                  {
                     "$ref": "#/definitions/ObjectDetectionWindowMethod"
                  }
               ]
            },
            "label_buffer": {
               "title": "Label Buffer",
               "type": "integer"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "object_detection_chip_options",
               "enum": [
                  "object_detection_chip_options"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "ObjectDetectionPredictOptions": {
         "title": "ObjectDetectionPredictOptions",
         "description": "Base class that can be extended to provide custom configurations.\n\nThis adds some extra methods to Pydantic BaseModel.\nSee https://pydantic-docs.helpmanual.io/\n\nThe general idea is that configuration schemas can be defined by\nsubclassing this and adding class attributes with types and\ndefault values for each field. Configs can be defined hierarchically,\nie. a Config can have fields which are of type Config.\nValidation, serialization, deserialization, and IDE support is\nprovided automatically based on this schema.",
         "type": "object",
         "properties": {
            "type_hint": {
               "title": "Type Hint",
               "default": "object_detection_predict_options",
               "enum": [
                  "object_detection_predict_options"
               ],
               "type": "string"
            },
            "merge_thresh": {
               "title": "Merge Thresh",
               "description": "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.",
               "default": 0.5,
               "type": "number"
            },
            "score_thresh": {
               "title": "Score Thresh",
               "description": "Predicted boxes are only output if their score is above score_thresh.",
               "default": 0.5,
               "type": "number"
            }
         },
         "additionalProperties": false
      }
   }
}

Config
  • extra: str = forbid

  • validate_assignment: bool = True

Fields
field analyze_uri: Optional[str] = None#

URI for output of analyze. If None, will be auto-generated.

field analyzers: List[AnalyzerConfig] = []#

Analyzers to run during analyzer command. A StatsAnalyzer will be added automatically if any scenes have a RasterTransformer.

field backend: BackendConfig [Required]#

Backend to use for interfacing with ML library.

field bundle_uri: Optional[str] = None#

URI for output of bundle. If None, will be auto-generated.

field chip_nodata_threshold: Proportion = 1#

Discard chips where the proportion of NODATA values is greater than or equal to this value. Might result in false positives if there are many legitimate black pixels in the chip. Use with caution.

Constraints
  • minimum = 0

  • maximum = 1

field chip_options: ObjectDetectionChipOptions = ObjectDetectionChipOptions(neg_ratio=1.0, ioa_thresh=0.8, window_method=<ObjectDetectionWindowMethod.chip: 'chip'>, label_buffer=None)#
field chip_uri: Optional[str] = None#

URI for output of chip. If None, will be auto-generated.

field dataset: DatasetConfig [Required]#

Dataset containing train, validation, and optional test scenes.

field eval_uri: Optional[str] = None#

URI for output of eval. If None, will be auto-generated.

field evaluators: List[EvaluatorConfig] = []#

Evaluators to run during analyzer command. If list is empty the default evaluator is added.

field plugin_versions: Optional[Dict[str, int]] = None#

Used to store a mapping of plugin module paths to the latest version number. This should not be set explicitly by users – it is set automatically when serializing and saving the config to disk.

field predict_batch_sz: int = 8#

Batch size to use during prediction.

field predict_chip_sz: int = 300#

Size of predictions chips in pixels.

field predict_options: ObjectDetectionPredictOptions = ObjectDetectionPredictOptions(merge_thresh=0.5, score_thresh=0.5)#
field predict_uri: Optional[str] = None#

URI for output of predict. If None, will be auto-generated.

field root_uri: str = None#

The root URI for output generated by the pipeline

field rv_config: dict = None#

Used to store serialized RVConfig so pipeline can run in remote environment with the local RVConfig. This should not be set explicitly by users – it is only used by the runner when running a remote pipeline.

field source_bundle_uri: Optional[str] = None#

If provided, the model will be loaded from this bundle for the train stage. Useful for fine-tuning.

field train_chip_sz: int = 300#

Size of training chips in pixels.

field train_uri: Optional[str] = None#

URI for output of train. If None, will be auto-generated.

field type_hint: Literal['object_detection'] = 'object_detection'#
build(tmp_dir)[source]#

Return a pipeline based on this configuration.

Subclasses should override this to return an instance of the corresponding subclass of Pipeline.

Parameters

tmp_dir – root of any temporary directory to pass to pipeline

get_config_uri() str#

Get URI of serialized version of this PipelineConfig.

Return type

str

get_default_evaluator()[source]#

Returns a default EvaluatorConfig to use if one isn’t set.

get_default_label_store(scene)[source]#

Returns a default LabelStoreConfig to fill in any missing ones.

get_model_bundle_uri()#
recursive_validate_config()#

Recursively validate hierarchies of Configs.

This uses reflection to call validate_config on a hierarchy of Configs using a depth-first pre-order traversal.

revalidate()#

Re-validate an instantiated Config.

Runs all Pydantic validators plus self.validate_config().

Adapted from: https://github.com/samuelcolvin/pydantic/issues/1864#issuecomment-679044432

update()#

Update any fields before validation.

Subclasses should override this to provide complex default behavior, for example, setting default values as a function of the values of other fields. The arguments to this method will vary depending on the type of Config.

validate_config()#

Validate fields that should be checked after update is called.

This is to complement the builtin validation that Pydantic performs at the time of object construction.

validate_list(field: str, valid_options: List[str])#

Validate a list field.

Parameters
  • field (str) – name of field to validate

  • valid_options (List[str]) – values that field is allowed to take

Raises

ConfigError – if field is invalid