Skip to content

Commit dfcf56b

Browse files
brunosanromeokienzlerpre-commit-ci[bot]Copilot
authored
Create package (#359)
* convert to pypi package, init * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reorg package struckure to match standard * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix incomplete import migration from src to claymodel - Update trainer.py imports to use claymodel instead of src - Fix all notebook files to use claymodel imports - Fix circular import in claymodel/callbacks_wandb.py - Add pip installation instructions to README - All import paths now consistently use claymodel package Resolves the ModuleNotFoundError issues and makes the package properly installable via pip. * Enhance package configuration and initialization - Improve pyproject.toml with proper metadata, license, and flexible dependencies - Add comprehensive package documentation and usage examples - Create structured __init__.py files for better package organization - Update dependency versions to use >= for better compatibility - Add proper package metadata for PyPI publication The package now has professional-grade configuration suitable for distribution while maintaining all functionality. * Complete import migration for all example scripts - Fix remaining finetune imports in classify.py, segment.py, regression.py - Update internal imports in model files (eurosat_model.py, etc.) - All scripts now use claymodel.finetune.* imports consistently - Ready for full testing in proper environment All import migration work completed: ✅ trainer.py fixed ✅ All 12 notebooks updated ✅ All finetune example scripts fixed ✅ Internal cross-module imports updated * Add comprehensive testing status documentation - Documents all completed import migration work - Lists all fixed files (6 Python scripts + 12 notebooks) - Provides testing checklist for clean environment - Ready for validation in proper PyTorch environment * Add minimum version constraints for better dependency resolution - Add lightning>=2.0.0 to ensure compatibility - Add timm>=0.6.0 for stable API - Maintain flexible upper bounds for PyTorch ecosystem This ensures users get compatible versions while allowing for future updates. The flexible bounds prevent the version conflicts we encountered in testing environments. * Remove outdated testing status documentation - Delete the TESTING_STATUS.md file as it is no longer relevant - This file contained information on completed import migration and testing status - The removal reflects the transition to a new testing framework or documentation approach This change simplifies the repository by eliminating obsolete documentation, ensuring that only current and relevant information is maintained. * """ Update documentation and .gitignore for improved usability - Add new entries to .gitignore to exclude checkpoint files (*.ckpt) from version control - Enhance documentation by adding a Quick Start guide and a Migration guide to facilitate user onboarding - Update installation instructions to reflect the new pip-installable package structure - Include detailed examples for generating embeddings and using pretrained models These changes aim to streamline the user experience, making it easier for new users to get started with the Clay Foundation Model while ensuring that unnecessary files are not tracked in the repository. """ * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make ruff happy * ruff-ing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Refactor function and condition checks for clarity - Corrected the type check in `initialize_weights` method to use a tuple for `isinstance`, ensuring proper evaluation of both `nn.Linear` and `nn.Conv2d`. - Fixed a typo in the function name `list_uniqe_ids` to `list_unique_ids` for consistency and accuracy in `preprocess_data.py`. - Updated the call to the corrected function name in the `process` function. These changes enhance code readability and maintainability by ensuring correct type checks and function naming conventions. * Refactor tutorial notebook for clarity and error handling - Removed unnecessary output cells from the `tutorial_digital_earth_pacific_patch_level.ipynb` notebook, which included warnings and installation logs that cluttered the output. - Updated the execution count for code cells to `null` to reset the notebook state, ensuring a clean slate for users running the tutorial. - This refactoring enhances the user experience by providing a cleaner and more focused tutorial without extraneous information. These changes aim to improve the clarity and usability of the tutorial notebook, making it easier for users to follow along without distractions. * Update docs/index.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Romeo Kienzler <romeo.kienzler1@ibm.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 12a61c0 commit dfcf56b

53 files changed

Lines changed: 888 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,7 @@ datadisk/
6767

6868
# vscode
6969
.vscode
70+
71+
# pip
72+
.venv
73+
*.ckpt

.ruff.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ruff configuration for Clay Foundation Model
2+
target-version = "py39"
3+
4+
[lint]
5+
# Allow fixes for auto-fixable rules
6+
fixable = ["ALL"]
7+
8+
# Ignore specific rules for notebooks since they contain tutorial code
9+
[lint.per-file-ignores]
10+
# Ignore notebook-specific issues
11+
"*.ipynb" = [
12+
"PLR0913", # Too many arguments (acceptable in tutorial functions)
13+
"PLR2004", # Magic value comparison (acceptable in demos)
14+
"E501", # Line too long (acceptable for URLs and strings)
15+
]
16+
17+
[lint.flake8-bugbear]
18+
extend-immutable-calls = ["fastapi.Depends"]
19+
20+
[format]
21+
# Use single quotes for strings
22+
quote-style = "double"

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,22 @@ Launch into a [JupyterLab](https://jupyterlab.readthedocs.io) environment on
2121

2222
## Installation
2323

24-
### Basic
24+
### Pip Installation (Recommended)
25+
26+
The easiest way to install Clay Foundation Model is via pip:
27+
28+
pip install git+https://github.com/Clay-foundation/model.git
29+
30+
This will install the `claymodel` package and all its dependencies. You can then import and use it in your Python code:
31+
32+
```python
33+
from claymodel.datamodule import ClayDataModule
34+
from claymodel.module import ClayMAEModule
35+
```
36+
37+
### Development Installation
38+
39+
For development or advanced usage, you can set up the full development environment:
2540

2641
To help out with development, start by cloning this [repo-url](/../../)
2742

@@ -60,6 +75,10 @@ Finally, double-check that the libraries have been installed.
6075

6176
The neural network model can be ran via
6277
[LightningCLI v2](https://pytorch-lightning.medium.com/introducing-lightningcli-v2supercharge-your-training-c070d43c7dd6).
78+
79+
> [!NOTE]
80+
> If you installed via pip, you'll need to clone the repository to access the trainer script and config files.
81+
6382
To check out the different options available, and look at the hyperparameter
6483
configurations, run:
6584

claymodel/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Clay Foundation Model - An open source AI model and interface for Earth observation.
3+
4+
This package provides tools for working with satellite imagery and Earth
5+
observation data using foundation models built on Vision Transformers.
6+
7+
Example usage:
8+
from claymodel.datamodule import ClayDataModule
9+
from claymodel.module import ClayMAEModule
10+
11+
# Create data module and model
12+
datamodule = ClayDataModule(...)
13+
model = ClayMAEModule(...)
14+
"""
15+
16+
__version__ = "1.5.0"
17+
18+
# Main components available for import
19+
__all__ = [
20+
"ClayMAEModule",
21+
"ClayDataModule",
22+
"clay_mae_base",
23+
"clay_mae_large",
24+
"clay_mae_small",
25+
"clay_mae_tiny",
26+
]
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
```
1111
import lightning as L
1212
13-
from src.callbacks_wandb import LogMAEReconstruction
13+
from claymodel.callbacks_wandb import LogMAEReconstruction
1414
1515
trainer = L.Trainer(
1616
...,
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import random
88
from collections import defaultdict
99
from pathlib import Path
10-
from typing import List, Literal
10+
from typing import Literal
1111

1212
import lightning as L
1313
import numpy as np
@@ -27,7 +27,7 @@ class EODataset(Dataset):
2727
"""Reads different Earth Observation data sources from a directory."""
2828

2929
def __init__(
30-
self, chips_path: List[Path], size: int, platforms: list, metadata: Box
30+
self, chips_path: list[Path], size: int, platforms: list, metadata: Box
3131
) -> None:
3232
super().__init__()
3333
self.chips_path = chips_path
@@ -322,3 +322,20 @@ def predict_dataloader(self):
322322
num_workers=self.num_workers,
323323
shuffle=False,
324324
)
325+
326+
327+
# Import additional DataModules for finetune tasks
328+
try:
329+
from claymodel.finetune.classify.eurosat_datamodule import EuroSATDataModule
330+
from claymodel.finetune.regression.biomasters_datamodule import BioMastersDataModule
331+
from claymodel.finetune.segment.chesapeake_datamodule import ChesapeakeDataModule
332+
333+
__all__ = [
334+
"ClayDataModule",
335+
"EuroSATDataModule",
336+
"ChesapeakeDataModule",
337+
"BioMastersDataModule",
338+
]
339+
except ImportError:
340+
# Some finetune modules may not be available
341+
__all__ = ["ClayDataModule"]

src/factory.py renamed to claymodel/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from einops import rearrange
1010
from torch import nn
1111

12-
from src.utils import posemb_sincos_1d
12+
from claymodel.utils import posemb_sincos_1d
1313

1414

1515
class FCBlock(nn.Module):

claymodel/finetune/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Fine-tuning modules for Clay Foundation Model.
3+
4+
This subpackage contains modules for fine-tuning the Clay model on various
5+
downstream tasks including classification, segmentation, regression, and
6+
embedding extraction.
7+
"""
8+
9+
try:
10+
# Classification
11+
from .classify.eurosat_datamodule import EuroSATDataModule
12+
from .classify.eurosat_model import EuroSATClassifier
13+
14+
# Regression
15+
from .regression.biomasters_datamodule import BioMastersDataModule
16+
from .regression.factory import Regressor
17+
18+
# Segmentation
19+
from .segment.chesapeake_datamodule import ChesapeakeDataModule
20+
from .segment.chesapeake_model import ChesapeakeSegmentor
21+
22+
__all__ = [
23+
"EuroSATDataModule",
24+
"EuroSATClassifier",
25+
"ChesapeakeDataModule",
26+
"ChesapeakeSegmentor",
27+
"BioMastersDataModule",
28+
"Regressor",
29+
]
30+
except ImportError:
31+
# Allow subpackage to be imported even if specific components fail
32+
__all__ = []

0 commit comments

Comments
 (0)