SemanticSegmentationConfig#

Note

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

pydantic model SemanticSegmentationConfig[source]#

Configure a SemanticSegmentation pipeline.

Show JSON schema
{
   "title": "SemanticSegmentationConfig",
   "description": "Configure a :class:`.SemanticSegmentation` 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": "semantic_segmentation",
         "enum": [
            "semantic_segmentation"
         ],
         "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": {
            "window_method": "SemanticSegmentationWindowMethod.sliding",
            "target_class_ids": null,
            "negative_survival_prob": 1.0,
            "chips_per_scene": 1000,
            "target_count_threshold": 1000,
            "stride": null,
            "type_hint": "semantic_segmentation_chip_options"
         },
         "allOf": [
            {
               "$ref": "#/definitions/SemanticSegmentationChipOptions"
            }
         ]
      },
      "predict_options": {
         "title": "Predict Options",
         "default": {
            "type_hint": "semantic_segmentation_predict_options",
            "stride": null,
            "crop_sz": null
         },
         "allOf": [
            {
               "$ref": "#/definitions/SemanticSegmentationPredictOptions"
            }
         ]
      }
   },
   "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
      },
      "SemanticSegmentationWindowMethod": {
         "title": "SemanticSegmentationWindowMethod",
         "description": "Enum for window methods\n\n    Attributes:\n        sliding: use a sliding window\n        random_sample: randomly sample windows\n    ",
         "enum": [
            "sliding",
            "random_sample"
         ]
      },
      "SemanticSegmentationChipOptions": {
         "title": "SemanticSegmentationChipOptions",
         "description": "Chipping options for semantic segmentation.",
         "type": "object",
         "properties": {
            "window_method": {
               "description": "Window method to use for chipping.",
               "default": "sliding",
               "allOf": [
                  {
                     "$ref": "#/definitions/SemanticSegmentationWindowMethod"
                  }
               ]
            },
            "target_class_ids": {
               "title": "Target Class Ids",
               "description": "List of class ids considered as targets (ie. those to prioritize when creating chips) which is only used in conjunction with the target_count_threshold and negative_survival_probability options. Applies to the random_sample window method.",
               "type": "array",
               "items": {
                  "type": "integer"
               }
            },
            "negative_survival_prob": {
               "title": "Negative Survival Prob",
               "description": "List of class ids considered as targets (ie. those to prioritize when creating chips) which is only used in conjunction with the target_count_threshold and negative_survival_probability options. Applies to the random_sample window method.",
               "default": 1.0,
               "type": "number"
            },
            "chips_per_scene": {
               "title": "Chips Per Scene",
               "description": "Number of chips to generate per scene. Applies to the random_sample window method.",
               "default": 1000,
               "type": "integer"
            },
            "target_count_threshold": {
               "title": "Target Count Threshold",
               "description": "Minimum number of pixels covering target_classes that a chip must have. Applies to the random_sample window method.",
               "default": 1000,
               "type": "integer"
            },
            "stride": {
               "title": "Stride",
               "description": "Stride of windows across image. Defaults to half the chip size. Applies to the sliding_window method.",
               "type": "integer"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "semantic_segmentation_chip_options",
               "enum": [
                  "semantic_segmentation_chip_options"
               ],
               "type": "string"
            }
         },
         "additionalProperties": false
      },
      "SemanticSegmentationPredictOptions": {
         "title": "SemanticSegmentationPredictOptions",
         "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": "semantic_segmentation_predict_options",
               "enum": [
                  "semantic_segmentation_predict_options"
               ],
               "type": "string"
            },
            "stride": {
               "title": "Stride",
               "description": "Stride of windows across image. Allows aggregating multiple predictions for each pixel if less than the chip size. Defaults to predict_chip_sz.",
               "type": "integer"
            },
            "crop_sz": {
               "title": "Crop Sz",
               "description": "Number of rows/columns of pixels from the edge of prediction windows to discard. This is useful because predictions near edges tend to be lower quality and can result in very visible artifacts near the edges of chips. If \"auto\", will be set to half the stride if stride is less than chip_sz. Defaults to None.",
               "anyOf": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "enum": [
                        "auto"
                     ],
                     "type": "string"
                  }
               ]
            }
         },
         "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: SemanticSegmentationChipOptions = SemanticSegmentationChipOptions(window_method=<SemanticSegmentationWindowMethod.sliding: 'sliding'>, target_class_ids=None, negative_survival_prob=1.0, chips_per_scene=1000, target_count_threshold=1000, stride=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: SemanticSegmentationPredictOptions = SemanticSegmentationPredictOptions(stride=None, crop_sz=None)#
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['semantic_segmentation'] = 'semantic_segmentation'#
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()[source]#

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()[source]#

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