Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most Configuration via Hydra #532

Merged
merged 78 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
1cb78a1
Bump setuptools from 69.1.1 to 70.0.0 in /requirements
dependabot[bot] Jul 15, 2024
9cdf01f
Merge pull request #507 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 15, 2024
2eb3ac4
Bump onnx2torch from 1.5.13 to 1.5.14 in /requirements
dependabot[bot] Jul 15, 2024
df10b20
Bump sphinx from 7.2.6 to 7.4.4 in /requirements
dependabot[bot] Jul 15, 2024
16872ad
Bump requests from 2.32.2 to 2.32.3 in /requirements
dependabot[bot] Jul 15, 2024
807b26d
Merge pull request #510 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 16, 2024
2d59d50
Merge pull request #509 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 16, 2024
6b3f893
Merge pull request #508 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 16, 2024
1ebfef7
Bump psutil from 5.9.8 to 6.0.0 in /requirements
dependabot[bot] Jul 22, 2024
cbb6d1e
Bump pre-commit from 3.6.2 to 3.7.1 in /requirements
dependabot[bot] Jul 22, 2024
134cfec
Bump tox from 4.14.2 to 4.16.0 in /requirements
dependabot[bot] Jul 22, 2024
761d426
Merge pull request #513 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 23, 2024
d27a942
Merge pull request #512 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 23, 2024
ca2174c
Merge pull request #511 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Jul 23, 2024
37528f8
Bump ipykernel from 6.29.3 to 6.29.5 in /requirements
dependabot[bot] Jul 29, 2024
6f7ffa8
Bump setuptools from 70.0.0 to 72.1.0 in /requirements
dependabot[bot] Jul 29, 2024
f9a8f6a
Merge pull request #516 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 1, 2024
d0fc2a5
Merge pull request #514 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 1, 2024
5eff0ae
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 5, 2024
6249e7e
Bump onnx from 1.16.1 to 1.16.2 in /requirements
dependabot[bot] Aug 5, 2024
a023141
Bump pre-commit from 3.7.1 to 3.8.0 in /requirements
dependabot[bot] Aug 5, 2024
5811321
Merge pull request #520 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 6, 2024
dea4a01
Merge pull request #519 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 6, 2024
599a03f
Merge pull request #518 from Pale-Blue-Dot-97/pre-commit-ci-update-co…
Pale-Blue-Dot-97 Aug 6, 2024
8877e8c
Bump mlflow from 2.13.2 to 2.15.1 in /requirements
dependabot[bot] Aug 12, 2024
cd50786
Bump lightly from 1.4.25 to 1.5.11 in /requirements
dependabot[bot] Aug 12, 2024
f31982a
Merge pull request #523 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 13, 2024
cd0b158
Merge pull request #521 from Pale-Blue-Dot-97/dependabot/pip/requirem…
Pale-Blue-Dot-97 Aug 13, 2024
f2e06a0
Merge branch 'beta' into 524-hydra-transforms
Pale-Blue-Dot-97 Aug 19, 2024
bd0af8b
Use `hydra` to instantiate transforms
Pale-Blue-Dot-97 Aug 19, 2024
88ed09c
Cut back UNet test to 2 epochs
Pale-Blue-Dot-97 Aug 20, 2024
031d490
Fixed `RandomApply` transforms special case
Pale-Blue-Dot-97 Aug 20, 2024
a559460
Use `hydra.utils.instantiate` to init the samplers
Pale-Blue-Dot-97 Aug 20, 2024
e49fdb3
Ensure that `Trainer.model` is updated from last training epoch
Pale-Blue-Dot-97 Aug 20, 2024
bef77ad
Use `hydra.utils.instantiate` to create datasets
Pale-Blue-Dot-97 Aug 23, 2024
545c38c
Fixed `RecursionError` with paired datasets
Pale-Blue-Dot-97 Aug 23, 2024
611ec86
Replace `module` and `name` fields with `_target_` for defining `task…
Pale-Blue-Dot-97 Aug 27, 2024
49f9cf8
Added gridlines to `DFC2020.plot` subplots
Pale-Blue-Dot-97 Aug 27, 2024
e197f98
Added `AdjustGamma` to `DFC2020.plot`
Pale-Blue-Dot-97 Aug 27, 2024
e6d9015
Use each subplot's shape to determine gridlines
Pale-Blue-Dot-97 Aug 27, 2024
728e14f
Use `hydra.utils.get_method` to import the collator
Pale-Blue-Dot-97 Aug 27, 2024
2a06b93
Update `example_autoencoder_config`
Pale-Blue-Dot-97 Aug 27, 2024
de1910c
Update collator tests
Pale-Blue-Dot-97 Aug 27, 2024
c7e250c
Updated tests for new collator finding
Pale-Blue-Dot-97 Aug 27, 2024
1f5ecf2
Fixed scheduler params in tests
Pale-Blue-Dot-97 Aug 27, 2024
61190f6
Fixed `mypy` issues
Pale-Blue-Dot-97 Aug 27, 2024
e703e8d
Use `hydra.utils.instantiate` for making models
Pale-Blue-Dot-97 Aug 28, 2024
20b914a
Specify dist backend protocol from config (and default to `GLOO`)
Pale-Blue-Dot-97 Aug 28, 2024
16ddddc
Switch to `opencv-python-headless` to remove potential external depen…
Pale-Blue-Dot-97 Aug 28, 2024
32bbda9
Fixed `trainer` tests
Pale-Blue-Dot-97 Aug 29, 2024
6c21b21
Fixed `test_transforms`
Pale-Blue-Dot-97 Aug 29, 2024
e0aa04c
Reduce number of new variables in `modelio`
Pale-Blue-Dot-97 Aug 30, 2024
361a110
Minor depenendcy updates
Pale-Blue-Dot-97 Aug 30, 2024
238dfc8
Bump `torch` --> `2.4.0` and `torchvision` --> `0.19.0`
Pale-Blue-Dot-97 Aug 30, 2024
040a439
Bump `segmentation-models-pytorch` --> `0.3.4`
Pale-Blue-Dot-97 Aug 30, 2024
279a6df
Minor dependency updates
Pale-Blue-Dot-97 Aug 30, 2024
d623a6a
Added `opencv-python` to `minerva` dependencies
Pale-Blue-Dot-97 Aug 30, 2024
0c4b8a3
Bump `torchgeo` --> `0.6.0`
Pale-Blue-Dot-97 Sep 2, 2024
7a85297
Account for case where index is not found
Pale-Blue-Dot-97 Sep 2, 2024
2145bcd
Updated example for new `OSCD` signature
Pale-Blue-Dot-97 Sep 2, 2024
91238b8
Update `n_classes` only if `elim=True` and `train=True` for a task
Pale-Blue-Dot-97 Sep 2, 2024
54bd298
Added `compare_models` function
Pale-Blue-Dot-97 Sep 2, 2024
d3e9d1b
Construct missing paths for datasets
Pale-Blue-Dot-97 Sep 3, 2024
4efc7d5
Fixed change detection handling for `torchgeo==0.6.0`
Pale-Blue-Dot-97 Sep 4, 2024
f88546c
Renamed `modelio` functions to clarify their purpose
Pale-Blue-Dot-97 Sep 4, 2024
dfa74aa
Import `modelio` function via `hydra`
Pale-Blue-Dot-97 Sep 4, 2024
a0a27d7
Use `hydra` for initing the `task_logger` and `step_logger`
Pale-Blue-Dot-97 Sep 4, 2024
00bff82
Removed `minerva.logger.steplog.get_logger`
Pale-Blue-Dot-97 Sep 4, 2024
a790e00
Added 4 seasons of a patch for `SSL4EO_S12` tests
Pale-Blue-Dot-97 Sep 5, 2024
81320fa
Added season transform to test
Pale-Blue-Dot-97 Sep 5, 2024
409253e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 5, 2024
bb72b6d
Dropped support for Python 3.9
Pale-Blue-Dot-97 Sep 5, 2024
4b53ef6
Removed globbing of paths in `utils.compile_dataset_paths` (now handl…
Pale-Blue-Dot-97 Sep 6, 2024
a78b6f1
`mypy` fixes
Pale-Blue-Dot-97 Sep 6, 2024
da54cf3
Eliminated `Dict`, `List`, `Tuple` and `Union` type hints
Pale-Blue-Dot-97 Sep 6, 2024
deb49ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 6, 2024
c5f4e78
Reintroduced `Union` type hint for self-refernecing type hints
Pale-Blue-Dot-97 Sep 6, 2024
2287698
Import `SGD` direct from `torch.optim`
Pale-Blue-Dot-97 Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']
exclude:
- os: windows-latest
python-version: '3.12'
Expand Down
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ lightning_logs/
**/results/*
**/cache/*
**/outputs/*
tests/tmp/cache/*
tests/tmp/results/*
tests/tmp/*
user_cfgs/*

inbuilt_cfgs/config.yml
Expand All @@ -162,8 +161,14 @@ inbuilt_cfgs/mf_config.yml
.vscode/settings.json

# Exclusions
!docs/
docs/*
!docs/images/
docs/images/*
!docs/images/*.png

!tests/fixtures/data/**/*.png
!tests/fixtures/data/**/*.txt
!tests/fixtures/data/**/*.csv
!tests/fixtures/data/**/*.tif
!tests/fixtures/data/**/*.json
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repos:
- id: requirements-txt-fixer

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ datasets with upcoming support for [torchvision](https://pytorch.org/vision/stab

Required Python modules for `minerva` are stated in the `setup.cfg`.

`minerva` currently only supports `python` 3.9 -- 3.12.
`minerva` currently only supports `python` 3.10 -- 3.12.

<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down
27 changes: 9 additions & 18 deletions minerva/datasets/collators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,36 @@
# =====================================================================================================================
# IMPORTS
# =====================================================================================================================
from typing import Any, Callable, Dict, Iterable, Optional, Tuple
from typing import Any, Callable, Iterable

from hydra.utils import get_method
from torchgeo.datasets.utils import stack_samples

from minerva.utils import utils


# =====================================================================================================================
# METHODS
# =====================================================================================================================
def get_collator(
collator_params: Optional[Dict[str, str]] = None
collator_target: str = "torchgeo.datasets.stack_samples",
) -> Callable[..., Any]:
"""Gets the function defined in parameters to collate samples together to form a batch.

Args:
collator_params (dict[str, str]): Optional; Dictionary that must contain keys for
``'module'`` and ``'name'`` of the collation function. Defaults to ``config['collator']``.
collator_target (str): Dot based import path for collator method.
Defaults to :meth:`torchgeo.datasets.stack_samples`

Returns:
~typing.Callable[..., ~typing.Any]: Collation function found from parameters given.
~typing.Callable[..., ~typing.Any]: Collation function found from target path given.
"""
collator: Callable[..., Any]
if collator_params is not None:
module = collator_params.pop("module", "")
if module == "":
collator = globals()[collator_params["name"]]
else:
collator = utils.func_by_str(module, collator_params["name"])
else:
collator = stack_samples

collator = get_method(collator_target)
assert callable(collator)
return collator


def stack_sample_pairs(
samples: Iterable[Tuple[Dict[Any, Any], Dict[Any, Any]]]
) -> Tuple[Dict[Any, Any], Dict[Any, Any]]:
samples: Iterable[tuple[dict[Any, Any], dict[Any, Any]]]
) -> tuple[dict[Any, Any], dict[Any, Any]]:
"""Takes a list of paired sample dicts and stacks them into a tuple of batches of sample dicts.

Args:
Expand Down
81 changes: 64 additions & 17 deletions minerva/datasets/dfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# =====================================================================================================================
from glob import glob
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any, Callable, Optional

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -84,7 +84,7 @@
S2_BANDS_MR = [5, 6, 7, 9, 12, 13]
S2_BANDS_LR = [1, 10, 11]

splits: List[str] = []
splits: list[str] = []

igbp = False

Expand Down Expand Up @@ -133,13 +133,13 @@
# Make sure parent dir exists.
assert self.root.exists()

self.samples: List[Dict[str, str]]
self.samples: list[dict[str, str]]

def load_sample(
self,
sample: Dict[str, str],
sample: dict[str, str],
index: int,
) -> Dict[str, Any]:
) -> dict[str, Any]:
"""Util function for reading data from single sample.

Args:
Expand Down Expand Up @@ -192,7 +192,7 @@
n_inputs += 2
return n_inputs

def get_display_channels(self) -> Tuple[List[int], int]:
def get_display_channels(self) -> tuple[list[int], int]:
"""Select channels for preview images.

Returns:
Expand Down Expand Up @@ -303,7 +303,7 @@

return lc

def __getitem__(self, index: int) -> Dict[str, Any]:
def __getitem__(self, index: int) -> dict[str, Any]:
"""Get a single example from the dataset"""

# Get and load sample from index file.
Expand Down Expand Up @@ -393,11 +393,11 @@

def plot(
self,
sample: Dict[str, Tensor],
sample: dict[str, Tensor],
show_titles: bool = True,
suptitle: Optional[str] = None,
classes: Optional[Dict[int, str]] = None,
colours: Optional[Dict[int, str]] = None,
classes: Optional[dict[int, str]] = None,
colours: Optional[dict[int, str]] = None,
) -> Figure:
"""Plot a sample from the dataset.

Expand All @@ -420,10 +420,15 @@
# Reorder image from BGR to RGB.
from kornia.color import BgrToRgb

from minerva.transforms import AdjustGamma

bgr_to_rgb = BgrToRgb()
adjust_gamma = AdjustGamma(gamma=0.8)

# Reorder channels from BGR to RGB and adjust the gamma ready for plotting.
image = adjust_gamma(bgr_to_rgb(sample["image"][:3])).permute(1, 2, 0).numpy()

image = bgr_to_rgb(sample["image"][:3])
image = image.permute(1, 2, 0).numpy()
block_size_factor = 8

# Use inbuilt class colours and classes mappings.
if classes is None or colours is None:
Expand Down Expand Up @@ -454,30 +459,72 @@

# Plot the image.
axs[0].imshow(image)
axs[0].axis("off")

# Sets tick intervals to block size.
axs[0].set_xticks(
np.arange(0, image.shape[0] + 1, image.shape[0] // block_size_factor)
)
axs[0].set_yticks(
np.arange(0, image.shape[1] + 1, image.shape[1] // block_size_factor)
)

# Add grid overlay.
axs[0].grid(which="both", color="#CCCCCC", linestyle=":")

# Plot the ground truth mask and predicted mask.
mask_plot: Axes
if showing_mask:
mask_plot = axs[1].imshow(
mask, cmap=cmap, vmin=vmin, vmax=vmax, interpolation="none"
)
axs[1].axis("off")

# Sets tick intervals to block size.
axs[1].set_xticks(
np.arange(0, mask.shape[0] + 1, mask.shape[0] // block_size_factor)
)
axs[1].set_yticks(
np.arange(0, mask.shape[1] + 1, mask.shape[1] // block_size_factor)
)

# Add grid overlay.
axs[1].grid(which="both", color="#CCCCCC", linestyle=":")

if showing_prediction:
axs[2].imshow(
pred, cmap=cmap, vmin=vmin, vmax=vmax, interpolation="none"
)
axs[2].axis("off")

# Sets tick intervals to block size.
axs[2].set_xticks(
np.arange(0, pred.shape[0] + 1, pred.shape[0] // block_size_factor)
)
axs[2].set_yticks(
np.arange(0, pred.shape[1] + 1, pred.shape[1] // block_size_factor)
)

# Add grid overlay.
axs[2].grid(which="both", color="#CCCCCC", linestyle=":")

elif showing_prediction:
mask_plot = axs[1].imshow(
pred, cmap=cmap, vmin=vmin, vmax=vmax, interpolation="none"
)
axs[1].axis("off")

# Sets tick intervals to block size.
axs[1].set_xticks(

Check warning on line 514 in minerva/datasets/dfc.py

View check run for this annotation

Codecov / codecov/patch

minerva/datasets/dfc.py#L514

Added line #L514 was not covered by tests
np.arange(0, pred.shape[0] + 1, pred.shape[0] // block_size_factor)
)
axs[1].set_yticks(

Check warning on line 517 in minerva/datasets/dfc.py

View check run for this annotation

Codecov / codecov/patch

minerva/datasets/dfc.py#L517

Added line #L517 was not covered by tests
np.arange(0, pred.shape[1] + 1, pred.shape[1] // block_size_factor)
)

# Add grid overlay.
axs[1].grid(which="both", color="#CCCCCC", linestyle=":")

Check warning on line 522 in minerva/datasets/dfc.py

View check run for this annotation

Codecov / codecov/patch

minerva/datasets/dfc.py#L522

Added line #L522 was not covered by tests

if showing_mask or showing_prediction:
# Plots colour bar onto figure.
clb = fig.colorbar(
mask_plot,
mask_plot, # type: ignore[arg-type]
ax=axs,
location="top",
ticks=np.arange(0, len(colours)),
Expand Down
Loading
Loading