SemanticSegmentationChipOptions#

Note

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

pydantic model SemanticSegmentationChipOptions[source]#

Chipping options for semantic segmentation.

Show JSON schema
{
   "title": "SemanticSegmentationChipOptions",
   "description": "Chipping options for semantic segmentation.",
   "type": "object",
   "properties": {
      "sampling": {
         "anyOf": [
            {
               "$ref": "#/$defs/WindowSamplingConfig"
            },
            {
               "additionalProperties": {
                  "$ref": "#/$defs/WindowSamplingConfig"
               },
               "type": "object"
            }
         ],
         "description": "Window sampling config.",
         "title": "Sampling"
      },
      "nodata_threshold": {
         "default": 1.0,
         "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.",
         "maximum": 1.0,
         "minimum": 0.0,
         "title": "Nodata Threshold",
         "type": "number"
      },
      "type_hint": {
         "const": "semantic_segmentation_chip_options",
         "default": "semantic_segmentation_chip_options",
         "enum": [
            "semantic_segmentation_chip_options"
         ],
         "title": "Type Hint",
         "type": "string"
      },
      "target_class_ids": {
         "anyOf": [
            {
               "items": {
                  "type": "integer"
               },
               "type": "array"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "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.",
         "title": "Target Class Ids"
      },
      "negative_survival_prob": {
         "default": 1.0,
         "description": "Probability of keeping a negative chip.",
         "title": "Negative Survival Prob",
         "type": "number"
      },
      "target_count_threshold": {
         "default": 1000,
         "description": "Minimum number of pixels covering target_classes that a chip must have. Applies to the random_sample window method.",
         "title": "Target Count Threshold",
         "type": "integer"
      }
   },
   "$defs": {
      "WindowSamplingConfig": {
         "additionalProperties": false,
         "description": "Configure the sampling of chip windows.",
         "properties": {
            "method": {
               "$ref": "#/$defs/WindowSamplingMethod",
               "default": "sliding",
               "description": ""
            },
            "size": {
               "anyOf": [
                  {
                     "exclusiveMinimum": 0,
                     "type": "integer"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        },
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  }
               ],
               "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).",
               "title": "Size"
            },
            "stride": {
               "anyOf": [
                  {
                     "exclusiveMinimum": 0,
                     "type": "integer"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        },
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "Stride of sliding window. Only used if method = sliding.",
               "title": "Stride"
            },
            "padding": {
               "anyOf": [
                  {
                     "minimum": 0,
                     "type": "integer"
                  },
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "minimum": 0,
                           "type": "integer"
                        },
                        {
                           "minimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "How many pixels are windows allowed to overflow the edges of the raster source.",
               "title": "Padding"
            },
            "pad_direction": {
               "default": "end",
               "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 padding is zero. Defaults to \"end\".",
               "enum": [
                  "both",
                  "start",
                  "end"
               ],
               "title": "Pad Direction",
               "type": "string"
            },
            "size_lims": {
               "anyOf": [
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        },
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "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).",
               "title": "Size Lims"
            },
            "h_lims": {
               "anyOf": [
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        },
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "[min, max] interval from which window heights will be uniformly randomly sampled. Only used if method = random.",
               "title": "H Lims"
            },
            "w_lims": {
               "anyOf": [
                  {
                     "maxItems": 2,
                     "minItems": 2,
                     "prefixItems": [
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        },
                        {
                           "exclusiveMinimum": 0,
                           "type": "integer"
                        }
                     ],
                     "type": "array"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "description": "[min, max] interval from which window widths will be uniformly randomly sampled. Only used if method = random.",
               "title": "W Lims"
            },
            "max_windows": {
               "default": 10000,
               "description": "Max number of windows to sample. Only used if method = random.",
               "minimum": 0,
               "title": "Max Windows",
               "type": "integer"
            },
            "max_sample_attempts": {
               "default": 100,
               "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.",
               "exclusiveMinimum": 0,
               "title": "Max Sample Attempts",
               "type": "integer"
            },
            "efficient_aoi_sampling": {
               "default": true,
               "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",
               "title": "Efficient Aoi Sampling",
               "type": "boolean"
            },
            "within_aoi": {
               "default": true,
               "description": "If True and if the scene has an AOI, only sample windows that lie fully within the AOI. If False, windows only partially intersecting the AOI will also be allowed.",
               "title": "Within Aoi",
               "type": "boolean"
            },
            "type_hint": {
               "const": "window_sampling",
               "default": "window_sampling",
               "enum": [
                  "window_sampling"
               ],
               "title": "Type Hint",
               "type": "string"
            }
         },
         "required": [
            "size"
         ],
         "title": "WindowSamplingConfig",
         "type": "object"
      },
      "WindowSamplingMethod": {
         "description": "Enum for window sampling methods.\n\nAttributes:\n    sliding: Sliding windows.\n    random: Randomly sampled windows.",
         "enum": [
            "sliding",
            "random"
         ],
         "title": "WindowSamplingMethod",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "sampling"
   ]
}

Config:
  • extra: str = forbid

  • validate_assignment: bool = True

Fields:
field negative_survival_prob: float = 1.0#

Probability of keeping a negative chip.

field nodata_threshold: Proportion = 1.0#

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.

Constraints:
  • ge = 0

  • le = 1

field sampling: WindowSamplingConfig | dict[str, WindowSamplingConfig] [Required]#

Window sampling config.

field target_class_ids: list[int] | None = None#

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.

field target_count_threshold: int = 1000#

Minimum number of pixels covering target_classes that a chip must have. Applies to the random_sample window method.

field type_hint: Literal['semantic_segmentation_chip_options'] = 'semantic_segmentation_chip_options'#
build()#

Build an instance of the corresponding type of object using this config.

For example, BackendConfig will build a Backend object. The arguments to this method will vary depending on the type of Config.

classmethod deserialize(inp: str | dict | Config) Self#

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

If inp is already a Config, it is returned as is.

Parameters:

inp (str | dict | Config) – a URI to a JSON file or a dict.

Return type:

Self

enough_target_pixels(label_arr: ndarray) bool[source]#

Check if label raster has enough pixels of the target classes.

Parameters:

label_arr (ndarray) – The label raster for a chip.

Returns:

True (the window does contain interesting pixels) or False.

Return type:

bool

classmethod from_dict(cfg_dict: dict) Self#

Deserialize Config from a dict.

Parameters:

cfg_dict (dict) – Dict to deserialize.

Return type:

Self

classmethod from_file(uri: str) Self#

Deserialize Config from a JSON file, upgrading if possible.

Parameters:

uri (str) – URI to load from.

Return type:

Self

get_chip_sz(scene_id: str | None = None) int#
Parameters:

scene_id (str | None) –

Return type:

int

keep_chip(chip: ndarray, label: ndarray) bool[source]#

Decide whether to keep or discard chip.

Parameters:
  • chip (ndarray) – Chip raster.

  • label (ndarray) – Associated label.

Return type:

bool

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().

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(*args, **kwargs)#

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