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"
         }
      },
      "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": {
         "$ref": "#/definitions/SemanticSegmentationChipOptions"
      },
      "predict_options": {
         "$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"
               }
            },
            "bbox": {
               "title": "Bbox",
               "description": "User-specified bbox 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
      },
      "WindowSamplingMethod": {
         "title": "WindowSamplingMethod",
         "description": "Enum for window sampling methods.\n\nAttributes:\n    sliding: Sliding windows.\n    random: Randomly sampled windows.",
         "enum": [
            "sliding",
            "random"
         ]
      },
      "WindowSamplingConfig": {
         "title": "WindowSamplingConfig",
         "description": "Configure the sampling of chip windows.",
         "type": "object",
         "properties": {
            "method": {
               "default": "sliding",
               "allOf": [
                  {
                     "$ref": "#/definitions/WindowSamplingMethod"
                  }
               ]
            },
            "size": {
               "title": "Size",
               "description": "If method = sliding, this is the size of sliding window. If method = random, this is the size that all the windows are resized to before they are returned. If method = random and neither size_lims nor h_lims and w_lims have been specified, then size_lims is set to (size, size + 1).",
               "anyOf": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "type": "array",
                     "minItems": 2,
                     "maxItems": 2,
                     "items": [
                        {
                           "type": "integer",
                           "exclusiveMinimum": 0
                        },
                        {
                           "type": "integer",
                           "exclusiveMinimum": 0
                        }
                     ]
                  }
               ]
            },
            "stride": {
               "title": "Stride",
               "description": "Stride of sliding window. Only used if method = sliding.",
               "anyOf": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "type": "array",
                     "minItems": 2,
                     "maxItems": 2,
                     "items": [
                        {
                           "type": "integer",
                           "exclusiveMinimum": 0
                        },
                        {
                           "type": "integer",
                           "exclusiveMinimum": 0
                        }
                     ]
                  }
               ]
            },
            "padding": {
               "title": "Padding",
               "description": "How many pixels are windows allowed to overflow the edges of the raster source.",
               "anyOf": [
                  {
                     "type": "integer",
                     "minimum": 0
                  },
                  {
                     "type": "array",
                     "minItems": 2,
                     "maxItems": 2,
                     "items": [
                        {
                           "type": "integer",
                           "minimum": 0
                        },
                        {
                           "type": "integer",
                           "minimum": 0
                        }
                     ]
                  }
               ]
            },
            "pad_direction": {
               "title": "Pad Direction",
               "description": "If \"end\", only pad ymax and xmax (bottom and right). If \"start\", only pad ymin and xmin (top and left). If \"both\", pad all sides. Has no effect if paddiong is zero. Defaults to \"end\".",
               "default": "end",
               "enum": [
                  "both",
                  "start",
                  "end"
               ],
               "type": "string"
            },
            "size_lims": {
               "title": "Size Lims",
               "description": "[min, max) interval from which window sizes will be uniformly randomly sampled. The upper limit is exclusive. To fix the size to a constant value, use size_lims = (sz, sz + 1). Only used if method = random. Specify either size_lims or h_lims and w_lims, but not both. If neither size_lims nor h_lims and w_lims have been specified, then this will be set to (size, size + 1).",
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  }
               ]
            },
            "h_lims": {
               "title": "H Lims",
               "description": "[min, max] interval from which window heights will be uniformly randomly sampled. Only used if method = random.",
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  }
               ]
            },
            "w_lims": {
               "title": "W Lims",
               "description": "[min, max] interval from which window widths will be uniformly randomly sampled. Only used if method = random.",
               "type": "array",
               "minItems": 2,
               "maxItems": 2,
               "items": [
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  },
                  {
                     "type": "integer",
                     "exclusiveMinimum": 0
                  }
               ]
            },
            "max_windows": {
               "title": "Max Windows",
               "description": "Max number of windows to sample. Only used if method = random.",
               "default": 10000,
               "minimum": 0,
               "type": "integer"
            },
            "max_sample_attempts": {
               "title": "Max Sample Attempts",
               "description": "Max attempts when trying to find a window within the AOI of a scene. Only used if method = random and the scene has aoi_polygons specified.",
               "default": 100,
               "exclusiveMinimum": 0,
               "type": "integer"
            },
            "efficient_aoi_sampling": {
               "title": "Efficient Aoi Sampling",
               "description": "If the scene has AOIs, sampling windows at random anywhere in the extent and then checking if they fall within any of the AOIs can be very inefficient. This flag enables the use of an alternate algorithm that only samples window locations inside the AOIs. Only used if method = random and the scene has aoi_polygons specified. Defaults to True",
               "default": true,
               "type": "boolean"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "window_sampling",
               "enum": [
                  "window_sampling"
               ],
               "type": "string"
            }
         },
         "required": [
            "size"
         ],
         "additionalProperties": false
      },
      "SemanticSegmentationChipOptions": {
         "title": "SemanticSegmentationChipOptions",
         "description": "Chipping options for semantic segmentation.",
         "type": "object",
         "properties": {
            "sampling": {
               "title": "Sampling",
               "description": "Window sampling config.",
               "anyOf": [
                  {
                     "$ref": "#/definitions/WindowSamplingConfig"
                  },
                  {
                     "type": "object",
                     "additionalProperties": {
                        "$ref": "#/definitions/WindowSamplingConfig"
                     }
                  }
               ]
            },
            "nodata_threshold": {
               "title": "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. If 1.0, only chips that are fully NODATA will be discarded. Defaults to 1.0.",
               "default": 1.0,
               "minimum": 0,
               "maximum": 1,
               "type": "number"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "semantic_segmentation_chip_options",
               "enum": [
                  "semantic_segmentation_chip_options"
               ],
               "type": "string"
            },
            "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": "Probability of keeping a negative chip.",
               "default": 1.0,
               "type": "number"
            },
            "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"
            }
         },
         "required": [
            "sampling"
         ],
         "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": {
            "chip_sz": {
               "title": "Chip Sz",
               "description": "Size of predictions chips in pixels.",
               "default": 300,
               "type": "integer"
            },
            "stride": {
               "title": "Stride",
               "description": "Stride of the sliding window for generating chips. Allows aggregating multiple predictions for each pixel if less than the chip size. Defaults to ``chip_sz``.",
               "type": "integer"
            },
            "batch_sz": {
               "title": "Batch Sz",
               "description": "Batch size to use during prediction.",
               "default": 8,
               "type": "integer"
            },
            "type_hint": {
               "title": "Type Hint",
               "default": "semantic_segmentation_predict_options",
               "enum": [
                  "semantic_segmentation_predict_options"
               ],
               "type": "string"
            },
            "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_options: Optional[SemanticSegmentationChipOptions] = 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_options: Optional[SemanticSegmentationPredictOptions] = 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_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

classmethod from_file(uri: str) Config#

Deserialize a Config from a JSON file, upgrading if possible.

Parameters

uri (str) – URI to load from.

Return type

Config

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

to_file(uri: str, with_rv_metadata: bool = True) None#

Save a Config to a JSON file, optionally with RV metadata.

Parameters
  • uri (str) – URI to save to.

  • with_rv_metadata (bool) – If True, inject Raster Vision metadata such as plugin_versions, so that the config can be upgraded when loaded.

Return type

None

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