-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2040 from AdeelH/chip
Reconcile chip-sampling functionality in `RVPipelines` with `GeoDatasets` (#1496)
- Loading branch information
Showing
61 changed files
with
1,322 additions
and
1,044 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
from pydantic import BaseModel | ||
from typing import Any, Literal, Optional | ||
from dataclasses import dataclass | ||
|
||
from numpy import ndarray | ||
|
||
from rastervision.core.box import Box | ||
from rastervision.core.data import Labels | ||
|
||
|
||
class DataSample(BaseModel): | ||
@dataclass | ||
class DataSample: | ||
"""A chip and labels along with metadata.""" | ||
chip: ndarray | ||
window: Box | ||
labels: Labels | ||
scene_id: str = 'default' | ||
is_train: bool = True | ||
|
||
class Config: | ||
arbitrary_types_allowed = True | ||
label: Optional[Any] = None | ||
split: Optional[Literal['train', 'valid', 'test']] = None | ||
scene_id: Optional[str] = None | ||
window: Optional[Box] = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 1 addition & 38 deletions
39
rastervision_core/rastervision/core/rv_pipeline/chip_classification.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,5 @@ | ||
from typing import List | ||
import logging | ||
|
||
from rastervision.core.rv_pipeline.rv_pipeline import RVPipeline | ||
from rastervision.core.rv_pipeline.utils import nodata_below_threshold | ||
from rastervision.core.box import Box | ||
from rastervision.core.data import Scene | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def get_train_windows(scene: Scene, | ||
chip_size: int, | ||
chip_nodata_threshold: float = 1.) -> List[Box]: | ||
train_windows = [] | ||
extent = scene.raster_source.extent | ||
stride = chip_size | ||
windows = extent.get_windows(chip_size, stride) | ||
|
||
total_windows = len(windows) | ||
if scene.aoi_polygons_bbox_coords: | ||
windows = Box.filter_by_aoi(windows, scene.aoi_polygons_bbox_coords) | ||
log.info(f'AOI filtering: {len(windows)}/{total_windows} ' | ||
'chips accepted') | ||
for window in windows: | ||
chip = scene.raster_source.get_chip(window) | ||
if nodata_below_threshold(chip, chip_nodata_threshold, nodata_val=0): | ||
train_windows.append(window) | ||
log.info('NODATA filtering: ' | ||
f'{len(train_windows)}/{len(windows)} chips accepted') | ||
return train_windows | ||
|
||
|
||
class ChipClassification(RVPipeline): | ||
def get_train_windows(self, scene: Scene) -> List[Box]: | ||
return get_train_windows( | ||
scene, | ||
self.config.train_chip_sz, | ||
chip_nodata_threshold=self.config.chip_nodata_threshold) | ||
|
||
def get_train_labels(self, window: Box, scene: Scene): | ||
return scene.label_source.get_labels(window=window) | ||
pass |
Oops, something went wrong.