Skip to content

Commit

Permalink
Merge pull request #1546 from azavea/lf/lightning
Browse files Browse the repository at this point in the history
Add RV + Lightning notebook
  • Loading branch information
lewfish authored Nov 22, 2022
2 parents 0235559 + b40ca44 commit bc6357b
Show file tree
Hide file tree
Showing 7 changed files with 866 additions and 48 deletions.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def setup(app: 'Sphinx') -> None:
# The _images dir is under build/html. This looks brittle but using the
# more natural img/tensorboard.png path does not work.
'tutorials/train': '_images/tensorboard.png',
'tutorials/lightning_workflow': '_images/lightning-logo.png',
}
nbsphinx_prolog = r"""
{% set docpath = env.doc2path(env.docname, base=False) %}
Expand Down Expand Up @@ -333,7 +334,7 @@ def setup(app: 'Sphinx') -> None:
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static', 'img']

# A list of CSS files. The entry must be a filename string or a tuple
# containing the filename string and the attributes dictionary. The filename
Expand Down
Binary file added docs/img/lightning-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/tensorboard-lightning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following tutorials highlight many of the things you can do with Raster Visi
scenes_and_aois
visualize_data_samples
train
lightning_workflow
pred_and_eval_ss
misc

Expand Down
791 changes: 791 additions & 0 deletions docs/tutorials/lightning_workflow.ipynb

Large diffs are not rendered by default.

74 changes: 30 additions & 44 deletions docs/tutorials/sampling_training_data.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Union, Optional, Tuple, Any, TypeVar
from typing_extensions import Literal
import logging

import numpy as np
import albumentations as A
Expand All @@ -14,6 +15,8 @@
TF_TYPE_TO_TF_FUNC)
from rastervision.pytorch_learner.dataset.utils import AoiSampler

log = logging.getLogger(__name__)


class AlbumentationsDataset(Dataset):
"""An adapter to use arbitrary datasets with albumentations transforms."""
Expand All @@ -28,8 +31,15 @@ def __init__(self,
Args:
orig_dataset (Any): An object with a __getitem__ and __len__.
transform (A.BasicTransform, optional): An Albumentations
transform. Defaults to None.
transform (A.BasicTransform, optional): Albumentations
transform to apply to the windows. Defaults to None.
Each transform in Albumentations takes images of type uint8, and
sometimes other data types. The data type requirements can be
seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ # noqa
If there is a mismatch between the data type of imagery and the
transform requirements, a RasterTransformer should be set
on the RasterSource that converts to uint8, such as
MinMaxTransformer or StatsTransformer.
transform_type (TransformType): The type of transform so that its
inputs and outputs can be handled correctly. Defaults to
TransformType.noop.
Expand All @@ -51,7 +61,15 @@ def __init__(self,

def __getitem__(self, key) -> Tuple[torch.Tensor, torch.Tensor]:
val = self.orig_dataset[key]
x, y = self.transform(val)

try:
x, y = self.transform(val)
except Exception as exc:
log.warn(
'Many albumentations transforms require uint8 input. Therefore, we '
'recommend passing a MinMaxTransformer or StatsTransformer to the '
'RasterSource so the input will be converted to uint8.')
raise exc

if self.normalize and np.issubdtype(x.dtype, np.unsignedinteger):
max_val = np.iinfo(x.dtype).max
Expand Down Expand Up @@ -97,6 +115,13 @@ def __init__(self,
scene (Scene): A Scene object.
transform (Optional[A.BasicTransform], optional): Albumentations
transform to apply to the windows. Defaults to None.
Each transform in Albumentations takes images of type uint8, and
sometimes other data types. The data type requirements can be
seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ # noqa
If there is a mismatch between the data type of imagery and the
transform requirements, a RasterTransformer should be set
on the RasterSource that converts to uint8, such as
MinMaxTransformer or StatsTransformer.
transform_type (Optional[TransformType], optional): Type of
transform. Defaults to None.
normalize (bool, optional): If True, x is normalized to [0, 1]
Expand Down Expand Up @@ -163,6 +188,13 @@ def __init__(self,
paddiong is zero. Defaults to 'end'.
transform (Optional[A.BasicTransform], optional): Albumentations
transform to apply to the windows. Defaults to None.
Each transform in Albumentations takes images of type uint8, and
sometimes other data types. The data type requirements can be
seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ # noqa
If there is a mismatch between the data type of imagery and the
transform requirements, a RasterTransformer should be set
on the RasterSource that converts to uint8, such as
MinMaxTransformer or StatsTransformer.
transform_type (Optional[TransformType], optional): Type of
transform. Defaults to None.
"""
Expand Down Expand Up @@ -241,6 +273,13 @@ def __init__(self,
np.inf. Defaults to None.
transform (Optional[A.BasicTransform], optional): Albumentations
transform to apply to the windows. Defaults to None.
Each transform in Albumentations takes images of type uint8, and
sometimes other data types. The data type requirements can be
seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ # noqa
If there is a mismatch between the data type of imagery and the
transform requirements, a RasterTransformer should be set
on the RasterSource that converts to uint8, such as
MinMaxTransformer or StatsTransformer.
transform_type (Optional[TransformType], optional): Type of
transform. Defaults to None.
max_sample_attempts (NonNegInt, optional): Max attempts when trying
Expand Down

0 comments on commit bc6357b

Please sign in to comment.