Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into splits_prediction_refac
Browse files Browse the repository at this point in the history
  • Loading branch information
CatEek committed Feb 3, 2025
2 parents 96d715c + 426ba1d commit e668aa4
Show file tree
Hide file tree
Showing 87 changed files with 3,323 additions and 2,923 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ updates:
time: "08:00"
ignore:
- dependency-name: "numpy"
- dependency-name: "zarr"
83 changes: 65 additions & 18 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,80 @@
### Description
## Description

Please provide a brief description of the changes in this PR. Include any relevant context or background information.
<!-- This section provides the necessary background and information for reviewers to
understand the code and have the correct mindset when examining changes. -->

- **What**: Clearly and concisely describe what changes you have made.
- **Why**: Explain the reasoning behind these changes. What problem are you solving? Why is this change necessary?
- **How**: Describe how you implemented these changes. Provide an overview of the approach and any important implementation details.
> [!NOTE]
> **tldr**: <!-- Write a one sentence summary. -->
### Changes Made

- **Added**: List new features or files added.
- **Modified**: Describe existing features or files modified.
- **Removed**: Detail features or files that were removed.
### Background - why do we need this PR?

### Related Issues
<!-- What problem are you solving? Describe in a few sentences the state before
this PR. Use code examples if useful. -->

Link to any related issues or discussions. Use keywords like "Fixes", "Resolves", or "Closes" to link to issues automatically.
### Overview - what changed?

- Fixes #
- Resolves #
- Closes #
<!-- What aspects and mechanisms of the code base changed? Describe only the general
idea and overarching features. -->

### Implementation - how did you implement the changes?

<!-- How did you solve the issue technically? Explain why you chose this approach and
provide code examples if applicable (e.g. change in the API for users). -->


## Changes Made

<!-- This section highlights the important features and files that reviewers should
pay attention to when reviewing. Only list important features or files, this is useful for
reviewers to correctly assess how deeply the modifications impact the code base.
For instance:
### New features or files
- `NewClass` added to `new_file.py`
- `new_function` added to `existing_file.py`
...
-->

### New features or files

<!-- List new features or files added. -->
-

### Breaking changes
### Modified features or files

<!-- List important modified features or files. -->
-

### Removed features or files

<!-- List removed features or files. -->
-

## How has this been tested?

<!-- Describe the tests that you ran to verify your changes. This can be a short
description of the tests added to the PR or code snippet to reproduce the change
in behaviour. -->


## Related Issues

<!-- Link to any related issues or discussions. Use keywords like "Fixes", "Resolves",
or "Closes" to link to issues automatically. -->

- Resolves #

Describe any breaking change.
## Breaking changes

<!-- Describe any breaking changes introduced by this PR. -->

### Additional Notes and Examples
## Additional Notes and Examples

Include any additional notes or context that reviewers should be aware of, including snippets of code illustrating your new feature.
<!-- Provide any additional information that will help reviewers understand the
changes. This can be links to documentations, forum posts, past discussions etc. -->

---

Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: validate-pyproject

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
rev: v0.8.6
hooks:
- id: ruff
exclude: "^src/careamics/lvae_training/.*|^src/careamics/models/lvae/.*|^scripts/.*"
Expand All @@ -26,14 +26,15 @@ repos:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: "^src/"
exclude: "^src/careamics/lvae_training/.*|^src/careamics/models/lvae/.*|^src/careamics/config/likelihood_model.py|^src/careamics/losses/loss_factory.py|^src/careamics/losses/lvae/losses.py"
args: ["--config-file", "mypy.ini"]
additional_dependencies:
- numpy
- numpy<2.0.0
- pydantic
- types-PyYAML
- types-setuptools

Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[mypy]
ignore_missing_imports = True
plugins = pydantic.mypy

[mypy-careamics.lvae_training.*]
follow_imports = skip
Expand Down
14 changes: 8 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@ classifiers = [
]
dependencies = [
'numpy<2.0.0',
'torch>=2.0,<=2.5.1',
'torch>=2.0,<=2.6.0',
'torchvision<=0.21.0',
'torchvision<=0.20.1',
'bioimageio.core==0.7',
'tifffile<=2024.12.12',
'psutil<=6.1',
'tifffile<=2025.1.10',
'psutil<=6.1.1',
'pydantic>=2.5,<2.11',
'pytorch_lightning>=2.2,<=2.4',
'pytorch_lightning>=2.2,<=2.5.0.post0',
'pyyaml<=6.0.2,!=6.0.0',
'typer>=0.12.3,<=0.15.1',
'scikit-image<=0.25.0',
'scikit-image<=0.25.1',
'zarr<3.0.0',
'pillow<=11.0.0',
'pillow<=11.1.0',
'matplotlib<=3.10.0'
]

[project.optional-dependencies]
Expand Down
19 changes: 17 additions & 2 deletions src/careamics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@
except PackageNotFoundError:
__version__ = "uninstalled"

__all__ = ["CAREamist", "Configuration", "load_configuration", "save_configuration"]
__all__ = [
"CAREamist",
"Configuration",
"algorithm_factory",
"configuration_factory",
"data_factory",
"load_configuration",
"save_configuration",
]

from .careamist import CAREamist
from .config import Configuration, load_configuration, save_configuration
from .config import (
Configuration,
algorithm_factory,
configuration_factory,
data_factory,
load_configuration,
save_configuration,
)
7 changes: 4 additions & 3 deletions src/careamics/careamist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from pytorch_lightning.loggers import CSVLogger, TensorBoardLogger, WandbLogger

from careamics.config import Configuration, FCNAlgorithmConfig, load_configuration
from careamics.config import Configuration, UNetBasedAlgorithm, load_configuration
from careamics.config.support import (
SupportedAlgorithm,
SupportedArchitecture,
Expand Down Expand Up @@ -137,7 +137,7 @@ def __init__(
self.cfg = source

# instantiate model
if isinstance(self.cfg.algorithm_config, FCNAlgorithmConfig):
if isinstance(self.cfg.algorithm_config, UNetBasedAlgorithm):
self.model = FCNModule(
algorithm_config=self.cfg.algorithm_config,
)
Expand All @@ -157,7 +157,8 @@ def __init__(
self.cfg = load_configuration(source)

# instantiate model
if isinstance(self.cfg.algorithm_config, FCNAlgorithmConfig):
# TODO call model factory here
if isinstance(self.cfg.algorithm_config, UNetBasedAlgorithm):
self.model = FCNModule(
algorithm_config=self.cfg.algorithm_config,
) # type: ignore
Expand Down
54 changes: 38 additions & 16 deletions src/careamics/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
"""Configuration module."""
"""CAREamics Pydantic configuration models.
To maintain clarity at the module level, we follow the following naming conventions:
`*_model` is specific for sub-configurations (e.g. architecture, data, algorithm),
while `*_configuration` is reserved for the main configuration models, including the
`Configuration` base class and its algorithm-specific child classes.
"""

__all__ = [
"CAREAlgorithm",
"CAREConfiguration",
"CheckpointModel",
"Configuration",
"CustomModel",
"DataConfig",
"FCNAlgorithmConfig",
"GaussianMixtureNMConfig",
"GeneralDataConfig",
"InferenceConfig",
"LVAELossConfig",
"MultiChannelNMConfig",
"N2NAlgorithm",
"N2NConfiguration",
"N2VAlgorithm",
"N2VConfiguration",
"N2VDataConfig",
"TrainingConfig",
"VAEAlgorithmConfig",
"clear_custom_models",
"UNetBasedAlgorithm",
"VAEBasedAlgorithm",
"algorithm_factory",
"configuration_factory",
"create_care_configuration",
"create_n2n_configuration",
"create_n2v_configuration",
"data_factory",
"load_configuration",
"register_model",
"save_configuration",
]
from .architectures import CustomModel, clear_custom_models, register_model

from .algorithms import (
CAREAlgorithm,
N2NAlgorithm,
N2VAlgorithm,
UNetBasedAlgorithm,
VAEBasedAlgorithm,
)
from .callback_model import CheckpointModel
from .configuration_factory import (
from .care_configuration import CAREConfiguration
from .configuration import Configuration
from .configuration_factories import (
algorithm_factory,
configuration_factory,
create_care_configuration,
create_n2n_configuration,
create_n2v_configuration,
data_factory,
)
from .configuration_model import (
Configuration,
load_configuration,
save_configuration,
)
from .data_model import DataConfig
from .fcn_algorithm_model import FCNAlgorithmConfig
from .configuration_io import load_configuration, save_configuration
from .data import DataConfig, GeneralDataConfig, N2VDataConfig
from .inference_model import InferenceConfig
from .loss_model import LVAELossConfig
from .n2n_configuration import N2NConfiguration
from .n2v_configuration import N2VConfiguration
from .nm_model import GaussianMixtureNMConfig, MultiChannelNMConfig
from .training_model import TrainingConfig
from .vae_algorithm_model import VAEAlgorithmConfig
15 changes: 15 additions & 0 deletions src/careamics/config/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Algorithm configurations."""

__all__ = [
"CAREAlgorithm",
"N2NAlgorithm",
"N2VAlgorithm",
"UNetBasedAlgorithm",
"VAEBasedAlgorithm",
]

from .care_algorithm_model import CAREAlgorithm
from .n2n_algorithm_model import N2NAlgorithm
from .n2v_algorithm_model import N2VAlgorithm
from .unet_algorithm_model import UNetBasedAlgorithm
from .vae_algorithm_model import VAEBasedAlgorithm
38 changes: 38 additions & 0 deletions src/careamics/config/algorithms/care_algorithm_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""CARE algorithm configuration."""

from typing import Annotated, Literal

from pydantic import AfterValidator

from careamics.config.architectures import UNetModel
from careamics.config.validators import (
model_without_final_activation,
model_without_n2v2,
)

from .unet_algorithm_model import UNetBasedAlgorithm


class CAREAlgorithm(UNetBasedAlgorithm):
"""CARE algorithm configuration.
Attributes
----------
algorithm : "care"
CARE Algorithm name.
loss : {"mae", "mse"}
CARE-compatible loss function.
"""

algorithm: Literal["care"] = "care"
"""CARE Algorithm name."""

loss: Literal["mae", "mse"] = "mae"
"""CARE-compatible loss function."""

model: Annotated[
UNetModel,
AfterValidator(model_without_n2v2),
AfterValidator(model_without_final_activation),
]
"""UNet without a final activation function and without the `n2v2` modifications."""
30 changes: 30 additions & 0 deletions src/careamics/config/algorithms/n2n_algorithm_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""N2N Algorithm configuration."""

from typing import Annotated, Literal

from pydantic import AfterValidator

from careamics.config.architectures import UNetModel
from careamics.config.validators import (
model_without_final_activation,
model_without_n2v2,
)

from .unet_algorithm_model import UNetBasedAlgorithm


class N2NAlgorithm(UNetBasedAlgorithm):
"""Noise2Noise Algorithm configuration."""

algorithm: Literal["n2n"] = "n2n"
"""N2N Algorithm name."""

loss: Literal["mae", "mse"] = "mae"
"""N2N-compatible loss function."""

model: Annotated[
UNetModel,
AfterValidator(model_without_n2v2),
AfterValidator(model_without_final_activation),
]
"""UNet without a final activation function and without the `n2v2` modifications."""
Loading

0 comments on commit e668aa4

Please sign in to comment.