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

Feature/refactor + dependabot #32

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 13 additions & 5 deletions .github/workflows/test.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which circumstances we want to perform the tests for individual pushes ? As we have the rule of creating PR before sending pushes to main I thought it was already covered by the pull request instruction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a good point. Tbh I mostly took this from what I saw on TorchGeo. Could it be for the case where a force push to main happens?

Copy link
Member

@Joao-L-S-Almeida Joao-L-S-Almeida Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I believe it won't affect our current workflow, but it could cover the exceptional cases in which we need to directly push to the master. I agree.

Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
name: terratorch tuning toolkit

on: [pull_request]
on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Clone repo
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand All @@ -20,8 +27,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -e .
pip install -r requirements/required.txt -r requirements/test.txt
- name: List pip dependencies
run: pip list
- name: Test with pytest
run: |
pytest tests
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you prefer to get the most recent version of the main branch, install the lib

TerraTorch requires gdal to be installed, which can be quite a complex process. If you don't have GDAL set up on your system, we reccomend using a conda environment and installing it with `conda install -c conda-forge gdal`.

To install as a developer (e.g. to extend the library) clone this repo, install dependencies using `pip install -r requirements.txt` and run `pip install -e .`
To install as a developer (e.g. to extend the library) clone this repo, install dependencies using `pip install -r requirements/required.txt -r requirements/dev.txt` and run `pip install -e .`

## Quick start

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"coverage",
"pytest",
"torch>=2.1.0",
"torchvision>=0.16.0",
"torchgeo>=0.5.1",
Expand All @@ -50,6 +48,11 @@ dev = [
"mkdocstrings[python]"
]

test = [
"coverage",
"pytest"
]

[project.urls]
Documentation = "https://github.com/IBM/terratorch#readme"
Issues = "https://github.com/IBM/terratorch/issues"
Expand Down
3 changes: 0 additions & 3 deletions requirements-dev.txt → requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
coverage[toml]>=6.5
pytest-cov==4.1.0
pytest==7.4.3
mkdocs-material==9.4.14
mkdocstrings[python]
h5py==3.10.0
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage[toml]>=6.5
pytest-cov==4.1.0
pytest==7.4.3
3 changes: 0 additions & 3 deletions src/terratorch/models/backbones/__init__.py

This file was deleted.

File renamed without changes.
2 changes: 2 additions & 0 deletions src/terratorch/__init__.py → terratorch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

# register models with timm
import terratorch.models
from terratorch.models.backbones import * # noqa: F403
2 changes: 2 additions & 0 deletions src/terratorch/__main__.py → terratorch/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Command-line interface to TerraTorch."""

from terratorch.cli_tools import build_lightning_cli
Expand Down
2 changes: 2 additions & 0 deletions src/terratorch/cli_tools.py → terratorch/cli_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

import logging # noqa: I001
import os
import warnings
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These datamodules are being imported but not used, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not being used, but they enable from terratorch.datamodules import, rather than needing to go down to the module

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from terratorch.datamodules.fire_scars import FireScarsNonGeoDataModule
from terratorch.datamodules.generic_pixel_wise_data_module import (
GenericNonGeoPixelwiseRegressionDataModule,
Expand All @@ -6,26 +8,26 @@
from terratorch.datamodules.generic_scalar_label_data_module import (
GenericNonGeoClassificationDataModule,
)

# GenericNonGeoRegressionDataModule,
from terratorch.datamodules.sen1floods11 import Sen1Floods11NonGeoDataModule
from terratorch.datamodules.torchgeo_data_module import TorchGeoDataModule, TorchNonGeoDataModule

# geobench classification datamodules
from terratorch.datamodules.m_eurosat import MEuroSATNonGeoDataModule
from terratorch.datamodules.m_bigearthnet import MBigEarthNonGeoDataModule
from terratorch.datamodules.m_brick_kiln import MBrickKilnNonGeoDataModule
from terratorch.datamodules.m_forestnet import MForestNetNonGeoDataModule
from terratorch.datamodules.m_so2sat import MSo2SatNonGeoDataModule
from terratorch.datamodules.m_pv4ger import MPv4gerNonGeoDataModule

# geobench segmentation datamodules
from terratorch.datamodules.m_cashew_plantation import MBeninSmallHolderCashewsNonGeoDataModule
from terratorch.datamodules.m_nz_cattle import MNzCattleNonGeoDataModule
from terratorch.datamodules.m_chesapeake_landcover import MChesapeakeLandcoverNonGeoDataModule

# geobench classification datamodules
from terratorch.datamodules.m_eurosat import MEuroSATNonGeoDataModule
from terratorch.datamodules.m_forestnet import MForestNetNonGeoDataModule
from terratorch.datamodules.m_neontree import MNeonTreeNonGeoDataModule
from terratorch.datamodules.m_nz_cattle import MNzCattleNonGeoDataModule
from terratorch.datamodules.m_pv4ger import MPv4gerNonGeoDataModule
from terratorch.datamodules.m_pv4ger_seg import MPv4gerSegNonGeoDataModule
from terratorch.datamodules.m_SA_crop_type import MSACropTypeNonGeoDataModule
from terratorch.datamodules.m_neontree import MNeonTreeNonGeoDataModule
from terratorch.datamodules.m_so2sat import MSo2SatNonGeoDataModule

# GenericNonGeoRegressionDataModule,
from terratorch.datamodules.sen1floods11 import Sen1Floods11NonGeoDataModule
from terratorch.datamodules.torchgeo_data_module import TorchGeoDataModule, TorchNonGeoDataModule

__all__ = (
"GenericNonGeoSegmentationDataModule",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from typing import Any

import kornia.augmentation as K # noqa: N812
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""
This module contains generic data modules for instantiation at runtime.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""
This module contains generic data modules for instantiation at runtime.
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from pathlib import Path
from typing import Any

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Ugly proxy objects so parsing config file works with transforms.

These are necessary since, for LightningCLI to instantiate arguments as
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import albumentations as A
# Copyright contributors to the Terratorch project

from typing import Iterable

import albumentations as A


def wrap_in_compose_is_list(transform_list):
# set check shapes to false because of the multitemporal case
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question asked for the other init file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, same thing.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from terratorch.datasets.fire_scars import FireScarsHLS, FireScarsNonGeo, FireScarsSegmentationMask
from terratorch.datasets.generic_pixel_wise_dataset import (
GenericNonGeoPixelwiseRegressionDataset,
Expand All @@ -6,30 +8,30 @@
from terratorch.datasets.generic_scalar_label_dataset import (
GenericNonGeoClassificationDataset,
)

# GenericNonGeoRegressionDataset,
from terratorch.datasets.sen1floods11 import Sen1Floods11NonGeo
from terratorch.datasets.utils import HLSBands

# TorchGeo RasterDatasets
from terratorch.datasets.wsf import WSF2019, WSFEvolution
from terratorch.datasets.hls import HLSL30, HLSS30

# geobench datasets classification
from terratorch.datasets.m_eurosat import MEuroSATNonGeo
from terratorch.datasets.m_bigearthnet import MBigEarthNonGeo
from terratorch.datasets.m_brick_kiln import MBrickKilnNonGeo
from terratorch.datasets.m_forestnet import MForestNetNonGeo
from terratorch.datasets.m_so2sat import MSo2SatNonGeo
from terratorch.datasets.m_pv4ger import MPv4gerNonGeo

# geobench datasets segmentation
from terratorch.datasets.m_cashew_plantation import MBeninSmallHolderCashewsNonGeo
from terratorch.datasets.m_nz_cattle import MNzCattleNonGeo
from terratorch.datasets.m_chesapeake_landcover import MChesapeakeLandcoverNonGeo

# geobench datasets classification
from terratorch.datasets.m_eurosat import MEuroSATNonGeo
from terratorch.datasets.m_forestnet import MForestNetNonGeo
from terratorch.datasets.m_neontree import MNeonTreeNonGeo
from terratorch.datasets.m_nz_cattle import MNzCattleNonGeo
from terratorch.datasets.m_pv4ger import MPv4gerNonGeo
from terratorch.datasets.m_pv4ger_seg import MPv4gerSegNonGeo
from terratorch.datasets.m_SA_crop_type import MSACropTypeNonGeo
from terratorch.datasets.m_neontree import MNeonTreeNonGeo
from terratorch.datasets.m_so2sat import MSo2SatNonGeo

# GenericNonGeoRegressionDataset,
from terratorch.datasets.sen1floods11 import Sen1Floods11NonGeo
from terratorch.datasets.utils import HLSBands

# TorchGeo RasterDatasets
from terratorch.datasets.wsf import WSF2019, WSFEvolution

__all__ = (
"GenericNonGeoSegmentationDataset",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

import dataclasses
import glob
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Module containing generic dataset classes
"""
import glob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Module containing generic dataset classes
"""
import glob
Expand Down
7 changes: 4 additions & 3 deletions src/terratorch/datasets/hls.py → terratorch/datasets/hls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright (c) IBM Corp. All rights reserved.
# Licensed under the MIT License.
# Copyright contributors to the Terratorch project


"""Harmonized Landsat and Sentinel-2 datasets."""

import abc
from collections.abc import Iterable, Sequence
from typing import Any, Callable, Optional, Union

from rasterio.crs import CRS
from torchgeo.datasets import Landsat
from typing import Any, Callable, Optional, Union


class HLS(Landsat, abc.ABC):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

import dataclasses
import glob
import os
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from albumentations import BasicTransform, Compose, ImageOnlyTransform
from einops import rearrange
from torch import Tensor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

import os
from collections.abc import Iterator
from enum import Enum
Expand Down
10 changes: 5 additions & 5 deletions src/terratorch/datasets/wsf.py → terratorch/datasets/wsf.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright (c) IBM Corp. All rights reserved.
# Licensed under the MIT License.
# Copyright contributors to the Terratorch project


"""World Settlement Footprint datasets."""

import abc
from collections.abc import Iterable, Sequence
from typing import Any, Callable, Optional, Union

import matplotlib.pyplot as plt
import numpy as np

from collections.abc import Iterable, Sequence
from rasterio.crs import CRS
from torchgeo.datasets import RasterDataset
from typing import Any, Callable, Optional, Union


class WSF(RasterDataset, abc.ABC):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from terratorch.models.prithvi_model_factory import PrithviModelFactory
from terratorch.models.satmae_model_factory import SatMAEModelFactory
from terratorch.models.scalemae_model_factory import ScaleMAEModelFactory
Expand Down
5 changes: 5 additions & 0 deletions terratorch/models/backbones/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright contributors to the Terratorch project

# import so they get registered
import terratorch.models.backbones.prithvi_swin
import terratorch.models.backbones.prithvi_vit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

import logging

import torch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""This module handles registering prithvi_swin models into timm.
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) IBM Corp. All rights reserved.
# Licensed under the MIT License.
# Copyright contributors to the Terratorch project


import logging
from functools import partial
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Swin transformer implementation. Mix of MMSegmentation implementation and timm implementation.

We use this implementation instead of the original implementation or timm's.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# DeiT: https://github.com/facebookresearch/deit
# --------------------------------------------------------

# Copyright contributors to the Terratorch project


from functools import lru_cache

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright contributors to the Terratorch project

from terratorch.models.decoders.fcn_decoder import FCNDecoder
from terratorch.models.decoders.identity_decoder import IdentityDecoder
from terratorch.models.decoders.upernet_decoder import UperNetDecoder
from terratorch.models.decoders.satmae_head import SatMAEHead, SatMAEHeadViT
from terratorch.models.decoders.upernet_decoder import UperNetDecoder

__all__ = ["FCNDecoder", "UperNetDecoder", "IdentityDecoder", "SatMAEHead", "SatMAEHeadViT"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

from torch import Tensor, nn


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright contributors to the Terratorch project

"""Pass the features straight through
"""

Expand Down
Loading
Loading