-
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.
- Loading branch information
Showing
28 changed files
with
173 additions
and
222 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ | |
ChipOptions.__name__, | ||
WindowSamplingConfig.__name__, | ||
WindowSamplingMethod.__name__, | ||
PredictOptions.__name__, | ||
] |
30 changes: 1 addition & 29 deletions
30
rastervision_core/rastervision/core/rv_pipeline/object_detection.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,33 +1,5 @@ | ||
from typing import TYPE_CHECKING | ||
import logging | ||
|
||
from rastervision.core.rv_pipeline import RVPipeline | ||
from rastervision.core.data.label import ObjectDetectionLabels | ||
|
||
if TYPE_CHECKING: | ||
from rastervision.core.data import Labels, Scene | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class ObjectDetection(RVPipeline): | ||
def predict_scene(self, scene: 'Scene') -> 'Labels': | ||
if self.backend is None: | ||
self.build_backend() | ||
|
||
# Use strided windowing to ensure that each object is fully visible (ie. not | ||
# cut off) within some window. This means prediction takes 4x longer for object | ||
# detection :( | ||
chip_sz = self.config.predict_chip_sz | ||
stride = chip_sz // 2 | ||
labels = self.backend.predict_scene( | ||
scene, chip_sz=chip_sz, stride=stride) | ||
labels = self.post_process_predictions(labels, scene) | ||
return labels | ||
|
||
def post_process_predictions(self, labels: ObjectDetectionLabels, | ||
scene: 'Scene') -> ObjectDetectionLabels: | ||
return ObjectDetectionLabels.prune_duplicates( | ||
labels, | ||
score_thresh=self.config.predict_options.score_thresh, | ||
merge_thresh=self.config.predict_options.merge_thresh) | ||
pass |
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
50 changes: 1 addition & 49 deletions
50
rastervision_core/rastervision/core/rv_pipeline/semantic_segmentation.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,53 +1,5 @@ | ||
from typing import TYPE_CHECKING | ||
import logging | ||
|
||
import numpy as np | ||
|
||
from rastervision.core.rv_pipeline import RVPipeline | ||
|
||
if TYPE_CHECKING: | ||
from rastervision.core.data import ( | ||
Labels, | ||
Scene, | ||
) | ||
from rastervision.core.rv_pipeline.semantic_segmentation_config import ( | ||
SemanticSegmentationConfig) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class SemanticSegmentation(RVPipeline): | ||
def post_process_batch(self, windows, chips, labels): | ||
# Fill in null class for any NODATA pixels. | ||
null_class_id = self.config.dataset.class_config.null_class_id | ||
for window, chip in zip(windows, chips): | ||
nodata_mask = np.sum(chip, axis=2) == 0 | ||
labels.mask_fill(window, nodata_mask, fill_value=null_class_id) | ||
|
||
return labels | ||
|
||
def predict_scene(self, scene: 'Scene') -> 'Labels': | ||
if self.backend is None: | ||
self.build_backend() | ||
|
||
cfg: 'SemanticSegmentationConfig' = self.config | ||
chip_sz = cfg.predict_chip_sz | ||
stride = cfg.predict_options.stride | ||
crop_sz = cfg.predict_options.crop_sz | ||
|
||
if stride is None: | ||
stride = chip_sz | ||
|
||
if crop_sz == 'auto': | ||
overlap_sz = chip_sz - stride | ||
if overlap_sz % 2 == 1: | ||
log.warning( | ||
'Using crop_sz="auto" but overlap size (chip_sz minus ' | ||
'stride) is odd. This means that one pixel row/col will ' | ||
'still overlap after cropping.') | ||
crop_sz = overlap_sz // 2 | ||
|
||
labels = self.backend.predict_scene( | ||
scene, chip_sz=chip_sz, stride=stride, crop_sz=crop_sz) | ||
labels = self.post_process_predictions(labels, scene) | ||
return labels | ||
pass |
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
Oops, something went wrong.