Skip to content

Commit

Permalink
Merge pull request #40 from FR-DC/refactor-dataset
Browse files Browse the repository at this point in the history
FRML-101 Refactors `train.py` and affected code
  • Loading branch information
Eve-ning authored Dec 29, 2023
2 parents 2cc3ac9 + 1673227 commit a46e072
Show file tree
Hide file tree
Showing 35 changed files with 486 additions and 330 deletions.
15 changes: 8 additions & 7 deletions Writerside/topics/Retrieve-our-Datasets.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ Here, we'll download and load our
- `labels`: The labels of the trees (segments)

```python
from frdc.load.dataset import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset

ds = FRDCDataset(site="chestnut_nature_park", date="20201218", version=None)
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
bounds, labels = ds.get_bounds_and_labels()
```

### What Datasets are there? {collapsible="true"}

> To know what datasets are available, you can run
> We recommend to use FRDCDatasetPreset. However, if you want
> to know what other datasets are available, you can run
> [load.gcs](load.gcs.md)'s `list_gcs_datasets()`
> method
Expand Down Expand Up @@ -86,10 +87,10 @@ To segment the data, use [Extract Segments](preprocessing.extract_segments.md).
Here, we'll segment the data by the bounds.

```python
from frdc.load.dataset import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.extract_segments import extract_segments_from_bounds

ds = FRDCDataset(site="chestnut_nature_park", date="20201218", version=None)
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
bounds, labels = ds.get_bounds_and_labels()
segments = extract_segments_from_bounds(ar, bounds)
Expand All @@ -109,11 +110,11 @@ We can then use these data to plot out the first tree segment.
```python
import matplotlib.pyplot as plt

from frdc.load.dataset import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.extract_segments import extract_segments_from_bounds
from frdc.preprocess.scale import scale_0_1_per_band

ds = FRDCDataset(site="chestnut_nature_park", date="20201218", version=None)
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
bounds, labels = ds.get_bounds_and_labels()
segments = extract_segments_from_bounds(ar, bounds)
Expand Down
6 changes: 2 additions & 4 deletions Writerside/topics/load.dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ version.
For example, to load our Chestnut Nature Park dataset.

```python
from frdc.load import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset

ds = FRDCDataset(site='chestnut_nature_park',
date='20201218',
version=None)
ds = FRDCDatasetPreset.chestnut_20201218()
```

Then, we can use the `ds` object to load objects of the dataset:
Expand Down
12 changes: 4 additions & 8 deletions Writerside/topics/preprocessing.extract_segments.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,10 @@ Extract segments from bounds and labels.

```python
import numpy as np
from frdc.load import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.extract_segments import extract_segments_from_bounds

ds = FRDCDataset(site='chestnut_nature_park',
date='20201218',
version=None, )
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
bounds, labels = ds.get_bounds_and_labels()

Expand All @@ -155,7 +153,7 @@ Extract segments from a label classification.
from skimage.morphology import remove_small_objects, remove_small_holes
import numpy as np

from frdc.load import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.morphology import (
threshold_binary_mask, binary_watershed
)
Expand All @@ -164,9 +162,7 @@ from frdc.preprocess.extract_segments import (
extract_segments_from_labels, remove_small_segments_from_labels
)

ds = FRDCDataset(site='chestnut_nature_park',
date='20201218',
version=None, )
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
ar = scale_0_1_per_band(ar)
ar_mask = threshold_binary_mask(ar, -1, 90 / 256)
Expand Down
6 changes: 2 additions & 4 deletions Writerside/topics/preprocessing.morphology.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ classification</b>
Perform auto-segmentation on a dataset to yield a label classification.

```python
from frdc.load import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.morphology import (
threshold_binary_mask, binary_watershed
)

ds = FRDCDataset(site='chestnut_nature_park',
date='20201218',
version=None, )
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
mask = threshold_binary_mask(ar, order.index('NIR'), 90 / 256)
ar_label = binary_watershed(mask)
Expand Down
6 changes: 2 additions & 4 deletions Writerside/topics/preprocessing.scale.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ Take a look at <code>frdc.conf.BAND_MAX_CONFIG</code> for an example.
## Usage

```python
from frdc.load import FRDCDataset
from frdc.load.preset import FRDCDatasetPreset
from frdc.preprocess.scale import (
scale_0_1_per_band, scale_normal_per_band, scale_static_per_band
)
from frdc.conf import BAND_MAX_CONFIG

ds = FRDCDataset(site='chestnut_nature_park',
date='20201218',
version=None, )
ds = FRDCDatasetPreset.chestnut_20201218()
ar, order = ds.get_ar_bands()
ar_01 = scale_0_1_per_band(ar)
ar_norm = scale_normal_per_band(ar)
Expand Down
2 changes: 1 addition & 1 deletion docs/HelpTOC.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"entities":{"pages":{"Overview":{"id":"Overview","title":"Overview","url":"overview.html","level":0,"tabIndex":0},"Getting-Started":{"id":"Getting-Started","title":"Getting Started","url":"getting-started.html","level":0,"pages":["Get-Started-with-Dev-Containers"],"tabIndex":1},"Get-Started-with-Dev-Containers":{"id":"Get-Started-with-Dev-Containers","title":"Get Started with Dev Containers","url":"get-started-with-dev-containers.html","level":1,"parentId":"Getting-Started","tabIndex":0},"e8e19623_66291":{"id":"e8e19623_66291","title":"Tutorials","level":0,"pages":["Retrieve-our-Datasets"],"tabIndex":2},"Retrieve-our-Datasets":{"id":"Retrieve-our-Datasets","title":"Retrieve our Datasets","url":"retrieve-our-datasets.html","level":1,"parentId":"e8e19623_66291","tabIndex":0},"mix-match":{"id":"mix-match","title":"MixMatch","url":"mix-match.html","level":0,"pages":["mix-match-module","custom-k-aug-dataloaders"],"tabIndex":3},"mix-match-module":{"id":"mix-match-module","title":"MixMatch Module","url":"mix-match-module.html","level":1,"parentId":"mix-match","tabIndex":0},"custom-k-aug-dataloaders":{"id":"custom-k-aug-dataloaders","title":"Custom K-Aug Dataloaders","url":"custom-k-aug-dataloaders.html","level":1,"parentId":"mix-match","tabIndex":1},"e8e19623_66296":{"id":"e8e19623_66296","title":"Model Tests","level":0,"pages":["Model-Test-Chestnut-May-Dec"],"tabIndex":4},"Model-Test-Chestnut-May-Dec":{"id":"Model-Test-Chestnut-May-Dec","title":"Model Test Chestnut May-Dec","url":"model-test-chestnut-may-dec.html","level":1,"parentId":"e8e19623_66296","tabIndex":0},"e8e19623_66298":{"id":"e8e19623_66298","title":"API","level":0,"pages":["load.dataset","load.gcs","preprocessing.scale","preprocessing.extract_segments","preprocessing.morphology","preprocessing.glcm_padded","train.frdc_lightning"],"tabIndex":5},"load.dataset":{"id":"load.dataset","title":"load.dataset","url":"load-dataset.html","level":1,"parentId":"e8e19623_66298","tabIndex":0},"load.gcs":{"id":"load.gcs","title":"load.gcs","url":"load-gcs.html","level":1,"parentId":"e8e19623_66298","tabIndex":1},"preprocessing.scale":{"id":"preprocessing.scale","title":"preprocessing.scale","url":"preprocessing-scale.html","level":1,"parentId":"e8e19623_66298","tabIndex":2},"preprocessing.extract_segments":{"id":"preprocessing.extract_segments","title":"preprocessing.extract_segments","url":"preprocessing-extract-segments.html","level":1,"parentId":"e8e19623_66298","tabIndex":3},"preprocessing.morphology":{"id":"preprocessing.morphology","title":"preprocessing.morphology","url":"preprocessing-morphology.html","level":1,"parentId":"e8e19623_66298","tabIndex":4},"preprocessing.glcm_padded":{"id":"preprocessing.glcm_padded","title":"preprocessing.glcm_padded","url":"preprocessing-glcm-padded.html","level":1,"parentId":"e8e19623_66298","tabIndex":5},"train.frdc_lightning":{"id":"train.frdc_lightning","title":"train.frdc_datamodule \u0026 frdc_module","url":"train-frdc-lightning.html","level":1,"parentId":"e8e19623_66298","tabIndex":6}}},"topLevelIds":["Overview","Getting-Started","e8e19623_66291","mix-match","e8e19623_66296","e8e19623_66298"]}
{"entities":{"pages":{"Overview":{"id":"Overview","title":"Overview","url":"overview.html","level":0,"tabIndex":0},"Getting-Started":{"id":"Getting-Started","title":"Getting Started","url":"getting-started.html","level":0,"pages":["Get-Started-with-Dev-Containers"],"tabIndex":1},"Get-Started-with-Dev-Containers":{"id":"Get-Started-with-Dev-Containers","title":"Get Started with Dev Containers","url":"get-started-with-dev-containers.html","level":1,"parentId":"Getting-Started","tabIndex":0},"f6c570e4_4234":{"id":"f6c570e4_4234","title":"Tutorials","level":0,"pages":["Retrieve-our-Datasets"],"tabIndex":2},"Retrieve-our-Datasets":{"id":"Retrieve-our-Datasets","title":"Retrieve our Datasets","url":"retrieve-our-datasets.html","level":1,"parentId":"f6c570e4_4234","tabIndex":0},"mix-match":{"id":"mix-match","title":"MixMatch","url":"mix-match.html","level":0,"pages":["mix-match-module","custom-k-aug-dataloaders"],"tabIndex":3},"mix-match-module":{"id":"mix-match-module","title":"MixMatch Module","url":"mix-match-module.html","level":1,"parentId":"mix-match","tabIndex":0},"custom-k-aug-dataloaders":{"id":"custom-k-aug-dataloaders","title":"Custom K-Aug Dataloaders","url":"custom-k-aug-dataloaders.html","level":1,"parentId":"mix-match","tabIndex":1},"f6c570e4_4239":{"id":"f6c570e4_4239","title":"Model Tests","level":0,"pages":["Model-Test-Chestnut-May-Dec"],"tabIndex":4},"Model-Test-Chestnut-May-Dec":{"id":"Model-Test-Chestnut-May-Dec","title":"Model Test Chestnut May-Dec","url":"model-test-chestnut-may-dec.html","level":1,"parentId":"f6c570e4_4239","tabIndex":0},"f6c570e4_4241":{"id":"f6c570e4_4241","title":"API","level":0,"pages":["load.dataset","load.gcs","preprocessing.scale","preprocessing.extract_segments","preprocessing.morphology","preprocessing.glcm_padded","train.frdc_lightning"],"tabIndex":5},"load.dataset":{"id":"load.dataset","title":"load.dataset","url":"load-dataset.html","level":1,"parentId":"f6c570e4_4241","tabIndex":0},"load.gcs":{"id":"load.gcs","title":"load.gcs","url":"load-gcs.html","level":1,"parentId":"f6c570e4_4241","tabIndex":1},"preprocessing.scale":{"id":"preprocessing.scale","title":"preprocessing.scale","url":"preprocessing-scale.html","level":1,"parentId":"f6c570e4_4241","tabIndex":2},"preprocessing.extract_segments":{"id":"preprocessing.extract_segments","title":"preprocessing.extract_segments","url":"preprocessing-extract-segments.html","level":1,"parentId":"f6c570e4_4241","tabIndex":3},"preprocessing.morphology":{"id":"preprocessing.morphology","title":"preprocessing.morphology","url":"preprocessing-morphology.html","level":1,"parentId":"f6c570e4_4241","tabIndex":4},"preprocessing.glcm_padded":{"id":"preprocessing.glcm_padded","title":"preprocessing.glcm_padded","url":"preprocessing-glcm-padded.html","level":1,"parentId":"f6c570e4_4241","tabIndex":5},"train.frdc_lightning":{"id":"train.frdc_lightning","title":"train.frdc_datamodule \u0026 frdc_module","url":"train-frdc-lightning.html","level":1,"parentId":"f6c570e4_4241","tabIndex":6}}},"topLevelIds":["Overview","Getting-Started","f6c570e4_4234","mix-match","f6c570e4_4239","f6c570e4_4241"]}
6 changes: 3 additions & 3 deletions docs/custom-k-aug-dataloaders.html

Large diffs are not rendered by default.

Loading

0 comments on commit a46e072

Please sign in to comment.