careamics 0.0.5__py3-none-any.whl → 0.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of careamics might be problematic. Click here for more details.

Files changed (98) hide show
  1. careamics/__init__.py +17 -2
  2. careamics/careamist.py +4 -3
  3. careamics/cli/conf.py +1 -2
  4. careamics/cli/main.py +1 -2
  5. careamics/cli/utils.py +3 -3
  6. careamics/config/__init__.py +47 -25
  7. careamics/config/algorithms/__init__.py +15 -0
  8. careamics/config/algorithms/care_algorithm_model.py +50 -0
  9. careamics/config/algorithms/n2n_algorithm_model.py +42 -0
  10. careamics/config/algorithms/n2v_algorithm_model.py +35 -0
  11. careamics/config/algorithms/unet_algorithm_model.py +88 -0
  12. careamics/config/{vae_algorithm_model.py → algorithms/vae_algorithm_model.py} +14 -12
  13. careamics/config/architectures/__init__.py +1 -11
  14. careamics/config/architectures/architecture_model.py +3 -3
  15. careamics/config/architectures/lvae_model.py +6 -1
  16. careamics/config/architectures/unet_model.py +1 -0
  17. careamics/config/care_configuration.py +100 -0
  18. careamics/config/configuration.py +354 -0
  19. careamics/config/{configuration_factory.py → configuration_factories.py} +103 -36
  20. careamics/config/configuration_io.py +85 -0
  21. careamics/config/data/__init__.py +10 -0
  22. careamics/config/{data_model.py → data/data_model.py} +58 -198
  23. careamics/config/data/n2v_data_model.py +193 -0
  24. careamics/config/likelihood_model.py +1 -2
  25. careamics/config/n2n_configuration.py +101 -0
  26. careamics/config/n2v_configuration.py +266 -0
  27. careamics/config/nm_model.py +1 -2
  28. careamics/config/support/__init__.py +7 -7
  29. careamics/config/support/supported_algorithms.py +0 -3
  30. careamics/config/support/supported_architectures.py +0 -4
  31. careamics/config/transformations/__init__.py +10 -4
  32. careamics/config/transformations/transform_model.py +3 -3
  33. careamics/config/transformations/transform_unions.py +42 -0
  34. careamics/config/validators/validator_utils.py +3 -3
  35. careamics/dataset/__init__.py +2 -2
  36. careamics/dataset/dataset_utils/__init__.py +3 -3
  37. careamics/dataset/dataset_utils/dataset_utils.py +4 -6
  38. careamics/dataset/dataset_utils/file_utils.py +9 -9
  39. careamics/dataset/dataset_utils/iterate_over_files.py +4 -3
  40. careamics/dataset/in_memory_dataset.py +11 -12
  41. careamics/dataset/iterable_dataset.py +4 -4
  42. careamics/dataset/iterable_pred_dataset.py +2 -1
  43. careamics/dataset/iterable_tiled_pred_dataset.py +2 -1
  44. careamics/dataset/patching/random_patching.py +11 -10
  45. careamics/dataset/patching/sequential_patching.py +26 -26
  46. careamics/dataset/patching/validate_patch_dimension.py +3 -3
  47. careamics/dataset/tiling/__init__.py +2 -2
  48. careamics/dataset/tiling/collate_tiles.py +3 -3
  49. careamics/dataset/tiling/lvae_tiled_patching.py +2 -1
  50. careamics/dataset/tiling/tiled_patching.py +11 -10
  51. careamics/file_io/__init__.py +5 -5
  52. careamics/file_io/read/__init__.py +1 -1
  53. careamics/file_io/read/get_func.py +2 -2
  54. careamics/file_io/write/__init__.py +2 -2
  55. careamics/lightning/__init__.py +5 -5
  56. careamics/lightning/callbacks/__init__.py +1 -1
  57. careamics/lightning/callbacks/prediction_writer_callback/__init__.py +3 -3
  58. careamics/lightning/callbacks/prediction_writer_callback/prediction_writer_callback.py +2 -1
  59. careamics/lightning/callbacks/prediction_writer_callback/write_strategy.py +2 -1
  60. careamics/lightning/callbacks/progress_bar_callback.py +2 -2
  61. careamics/lightning/lightning_module.py +11 -7
  62. careamics/lightning/train_data_module.py +26 -26
  63. careamics/losses/__init__.py +3 -3
  64. careamics/model_io/__init__.py +1 -1
  65. careamics/model_io/bioimage/__init__.py +1 -1
  66. careamics/model_io/bioimage/_readme_factory.py +1 -1
  67. careamics/model_io/bioimage/model_description.py +17 -17
  68. careamics/model_io/bmz_io.py +6 -17
  69. careamics/model_io/model_io_utils.py +9 -9
  70. careamics/models/layers.py +16 -16
  71. careamics/models/lvae/lvae.py +0 -3
  72. careamics/models/model_factory.py +2 -15
  73. careamics/models/unet.py +8 -8
  74. careamics/prediction_utils/__init__.py +1 -1
  75. careamics/prediction_utils/prediction_outputs.py +15 -15
  76. careamics/prediction_utils/stitch_prediction.py +6 -6
  77. careamics/transforms/__init__.py +5 -5
  78. careamics/transforms/compose.py +13 -13
  79. careamics/transforms/n2v_manipulate.py +3 -3
  80. careamics/transforms/pixel_manipulation.py +9 -9
  81. careamics/transforms/xy_random_rotate90.py +4 -4
  82. careamics/utils/__init__.py +5 -5
  83. careamics/utils/context.py +2 -1
  84. careamics/utils/logging.py +11 -10
  85. careamics/utils/torch_utils.py +7 -7
  86. {careamics-0.0.5.dist-info → careamics-0.0.6.dist-info}/METADATA +11 -11
  87. {careamics-0.0.5.dist-info → careamics-0.0.6.dist-info}/RECORD +90 -85
  88. careamics/config/architectures/custom_model.py +0 -162
  89. careamics/config/architectures/register_model.py +0 -103
  90. careamics/config/configuration_model.py +0 -603
  91. careamics/config/fcn_algorithm_model.py +0 -152
  92. careamics/config/references/__init__.py +0 -45
  93. careamics/config/references/algorithm_descriptions.py +0 -132
  94. careamics/config/references/references.py +0 -39
  95. careamics/config/transformations/transform_union.py +0 -20
  96. {careamics-0.0.5.dist-info → careamics-0.0.6.dist-info}/WHEEL +0 -0
  97. {careamics-0.0.5.dist-info → careamics-0.0.6.dist-info}/entry_points.txt +0 -0
  98. {careamics-0.0.5.dist-info → careamics-0.0.6.dist-info}/licenses/LICENSE +0 -0
@@ -1,152 +0,0 @@
1
- """Module containing `FCNAlgorithmConfig` class."""
2
-
3
- from pprint import pformat
4
- from typing import Literal, Union
5
-
6
- from pydantic import BaseModel, ConfigDict, Field, model_validator
7
- from typing_extensions import Self
8
-
9
- from careamics.config.architectures import CustomModel, UNetModel
10
- from careamics.config.optimizer_models import LrSchedulerModel, OptimizerModel
11
-
12
-
13
- class FCNAlgorithmConfig(BaseModel):
14
- """Algorithm configuration.
15
-
16
- This Pydantic model validates the parameters governing the components of the
17
- training algorithm: which algorithm, loss function, model architecture, optimizer,
18
- and learning rate scheduler to use.
19
-
20
- Currently, we only support N2V, CARE, N2N and custom models. The `n2v` algorithm is
21
- only compatible with `n2v` loss and `UNet` architecture. The `custom` algorithm
22
- allows you to register your own architecture and select it using its name as
23
- `name` in the custom pydantic model.
24
-
25
- Attributes
26
- ----------
27
- algorithm : {"n2v", "care", "n2n", "custom"}
28
- Algorithm to use.
29
- loss : {"n2v", "mae", "mse"}
30
- Loss function to use.
31
- model : UNetModel or CustomModel
32
- Model architecture to use.
33
- optimizer : OptimizerModel, optional
34
- Optimizer to use.
35
- lr_scheduler : LrSchedulerModel, optional
36
- Learning rate scheduler to use.
37
-
38
- Raises
39
- ------
40
- ValueError
41
- Algorithm parameter type validation errors.
42
- ValueError
43
- If the algorithm, loss and model are not compatible.
44
-
45
- Examples
46
- --------
47
- Minimum example:
48
- >>> from careamics.config import FCNAlgorithmConfig
49
- >>> config_dict = {
50
- ... "algorithm": "n2v",
51
- ... "loss": "n2v",
52
- ... "model": {
53
- ... "architecture": "UNet",
54
- ... }
55
- ... }
56
- >>> config = FCNAlgorithmConfig(**config_dict)
57
- """
58
-
59
- # Pydantic class configuration
60
- model_config = ConfigDict(
61
- protected_namespaces=(), # allows to use model_* as a field name
62
- validate_assignment=True,
63
- extra="allow",
64
- )
65
-
66
- # Mandatory fields
67
- algorithm: Literal["n2v", "care", "n2n", "custom"]
68
- """Name of the algorithm, as defined in SupportedAlgorithm. Use `custom` for custom
69
- model architecture."""
70
-
71
- loss: Literal["n2v", "mae", "mse"]
72
- """Loss function to use, as defined in SupportedLoss."""
73
-
74
- model: Union[UNetModel, CustomModel] = Field(discriminator="architecture")
75
- """Model architecture to use, along with its parameters. Compatible architectures
76
- are defined in SupportedArchitecture, and their Pydantic models in
77
- `careamics.config.architectures`."""
78
- # TODO supported architectures are now all the architectures but does not warn users
79
- # of the compatibility with the algorithm
80
-
81
- # Optional fields
82
- optimizer: OptimizerModel = OptimizerModel()
83
- """Optimizer to use, defined in SupportedOptimizer."""
84
-
85
- lr_scheduler: LrSchedulerModel = LrSchedulerModel()
86
- """Learning rate scheduler to use, defined in SupportedLrScheduler."""
87
-
88
- @model_validator(mode="after")
89
- def algorithm_cross_validation(self: Self) -> Self:
90
- """Validate the algorithm model based on `algorithm`.
91
-
92
- N2V:
93
- - loss must be n2v
94
- - model must be a `UNetModel`
95
-
96
- Returns
97
- -------
98
- Self
99
- The validated model.
100
- """
101
- # N2V
102
- if self.algorithm == "n2v":
103
- # n2v is only compatible with the n2v loss
104
- if self.loss != "n2v":
105
- raise ValueError(
106
- f"Algorithm {self.algorithm} only supports loss `n2v`."
107
- )
108
-
109
- # n2v is only compatible with the UNet model
110
- if not isinstance(self.model, UNetModel):
111
- raise ValueError(
112
- f"Model for algorithm {self.algorithm} must be a `UNetModel`."
113
- )
114
-
115
- # n2v requires the number of input and output channels to be the same
116
- if self.model.in_channels != self.model.num_classes:
117
- raise ValueError(
118
- "N2V requires the same number of input and output channels. Make "
119
- "sure that `in_channels` and `num_classes` are the same."
120
- )
121
-
122
- if self.algorithm == "care" or self.algorithm == "n2n":
123
- if self.loss == "n2v":
124
- raise ValueError("Supervised algorithms do not support loss `n2v`.")
125
-
126
- if (self.algorithm == "custom") != (self.model.architecture == "custom"):
127
- raise ValueError(
128
- "Algorithm and model architecture must be both `custom` or not."
129
- )
130
-
131
- return self
132
-
133
- def __str__(self) -> str:
134
- """Pretty string representing the configuration.
135
-
136
- Returns
137
- -------
138
- str
139
- Pretty string.
140
- """
141
- return pformat(self.model_dump())
142
-
143
- @classmethod
144
- def get_compatible_algorithms(cls) -> list[str]:
145
- """Get the list of compatible algorithms.
146
-
147
- Returns
148
- -------
149
- list of str
150
- List of compatible algorithms.
151
- """
152
- return ["n2v", "care", "n2n"]
@@ -1,45 +0,0 @@
1
- """Module containing references to the algorithm used in CAREamics."""
2
-
3
- __all__ = [
4
- "N2V2Ref",
5
- "N2VRef",
6
- "StructN2VRef",
7
- "N2VDescription",
8
- "N2V2Description",
9
- "StructN2VDescription",
10
- "StructN2V2Description",
11
- "N2V",
12
- "N2V2",
13
- "STRUCT_N2V",
14
- "STRUCT_N2V2",
15
- "CUSTOM",
16
- "N2N",
17
- "CARE",
18
- "CAREDescription",
19
- "N2NDescription",
20
- "CARERef",
21
- "N2NRef",
22
- ]
23
-
24
- from .algorithm_descriptions import (
25
- CARE,
26
- CUSTOM,
27
- N2N,
28
- N2V,
29
- N2V2,
30
- STRUCT_N2V,
31
- STRUCT_N2V2,
32
- CAREDescription,
33
- N2NDescription,
34
- N2V2Description,
35
- N2VDescription,
36
- StructN2V2Description,
37
- StructN2VDescription,
38
- )
39
- from .references import (
40
- CARERef,
41
- N2NRef,
42
- N2V2Ref,
43
- N2VRef,
44
- StructN2VRef,
45
- )
@@ -1,132 +0,0 @@
1
- """Descriptions of the algorithms used in CAREmics."""
2
-
3
- from pydantic import BaseModel
4
-
5
- CUSTOM = "Custom"
6
- N2V = "Noise2Void"
7
- N2V2 = "N2V2"
8
- STRUCT_N2V = "StructN2V"
9
- STRUCT_N2V2 = "StructN2V2"
10
- N2N = "Noise2Noise"
11
- CARE = "CARE"
12
-
13
-
14
- N2V_DESCRIPTION = (
15
- "Noise2Void is a UNet-based self-supervised algorithm that "
16
- "uses blind-spot training to denoise images. In short, in every "
17
- "patches during training, random pixels are selected and their "
18
- "value replaced by a neighboring pixel value. The network is then "
19
- "trained to predict the original pixel value. The algorithm "
20
- "relies on the continuity of the signal (neighboring pixels have "
21
- "similar values) and the pixel-wise independence of the noise "
22
- "(the noise in a pixel is not correlated with the noise in "
23
- "neighboring pixels)."
24
- )
25
-
26
-
27
- class AlgorithmDescription(BaseModel):
28
- """Description of an algorithm.
29
-
30
- Attributes
31
- ----------
32
- description : str
33
- Description of the algorithm.
34
- """
35
-
36
- description: str
37
-
38
-
39
- class N2VDescription(AlgorithmDescription):
40
- """Description of Noise2Void.
41
-
42
- Attributes
43
- ----------
44
- description : str
45
- Description of Noise2Void.
46
- """
47
-
48
- description: str = N2V_DESCRIPTION
49
-
50
-
51
- class N2V2Description(AlgorithmDescription):
52
- """Description of N2V2.
53
-
54
- Attributes
55
- ----------
56
- description : str
57
- Description of N2V2.
58
- """
59
-
60
- description: str = (
61
- "N2V2 is a variant of Noise2Void. "
62
- + N2V_DESCRIPTION
63
- + "\nN2V2 introduces blur-pool layers and removed skip "
64
- "connections in the UNet architecture to remove checkboard "
65
- "artefacts, a common artefacts ocurring in Noise2Void."
66
- )
67
-
68
-
69
- class StructN2VDescription(AlgorithmDescription):
70
- """Description of StructN2V.
71
-
72
- Attributes
73
- ----------
74
- description : str
75
- Description of StructN2V.
76
- """
77
-
78
- description: str = (
79
- "StructN2V is a variant of Noise2Void. "
80
- + N2V_DESCRIPTION
81
- + "\nStructN2V uses a linear mask (horizontal or vertical) to replace "
82
- "the pixel values of neighbors of the masked pixels by a random "
83
- "value. Such masking allows removing 1D structured noise from the "
84
- "the images, the main failure case of the original N2V."
85
- )
86
-
87
-
88
- class StructN2V2Description(AlgorithmDescription):
89
- """Description of StructN2V2.
90
-
91
- Attributes
92
- ----------
93
- description : str
94
- Description of StructN2V2.
95
- """
96
-
97
- description: str = (
98
- "StructN2V2 is a a variant of Noise2Void that uses both "
99
- "structN2V and N2V2. "
100
- + N2V_DESCRIPTION
101
- + "\nStructN2V2 uses a linear mask (horizontal or vertical) to replace "
102
- "the pixel values of neighbors of the masked pixels by a random "
103
- "value. Such masking allows removing 1D structured noise from the "
104
- "the images, the main failure case of the original N2V."
105
- "\nN2V2 introduces blur-pool layers and removed skip connections in "
106
- "the UNet architecture to remove checkboard artefacts, a common "
107
- "artefacts ocurring in Noise2Void."
108
- )
109
-
110
-
111
- class N2NDescription(AlgorithmDescription):
112
- """Description of Noise2Noise.
113
-
114
- Attributes
115
- ----------
116
- description : str
117
- Description of Noise2Noise.
118
- """
119
-
120
- description: str = "Noise2Noise" # TODO
121
-
122
-
123
- class CAREDescription(AlgorithmDescription):
124
- """Description of CARE.
125
-
126
- Attributes
127
- ----------
128
- description : str
129
- Description of CARE.
130
- """
131
-
132
- description: str = "CARE" # TODO
@@ -1,39 +0,0 @@
1
- """References for the CAREamics algorithms."""
2
-
3
- from bioimageio.spec.generic.v0_3 import CiteEntry
4
-
5
- N2VRef = CiteEntry(
6
- text='Krull, A., Buchholz, T.O. and Jug, F., 2019. "Noise2Void - Learning '
7
- 'denoising from single noisy images". In Proceedings of the IEEE/CVF '
8
- "conference on computer vision and pattern recognition (pp. 2129-2137).",
9
- doi="10.1109/cvpr.2019.00223",
10
- )
11
-
12
- N2V2Ref = CiteEntry(
13
- text="Höck, E., Buchholz, T.O., Brachmann, A., Jug, F. and Freytag, A., "
14
- '2022. "N2V2 - Fixing Noise2Void checkerboard artifacts with modified '
15
- 'sampling strategies and a tweaked network architecture". In European '
16
- "Conference on Computer Vision (pp. 503-518).",
17
- doi="10.1007/978-3-031-25069-9_33",
18
- )
19
-
20
- StructN2VRef = CiteEntry(
21
- text="Broaddus, C., Krull, A., Weigert, M., Schmidt, U. and Myers, G., 2020."
22
- '"Removing structured noise with self-supervised blind-spot '
23
- 'networks". In 2020 IEEE 17th International Symposium on Biomedical '
24
- "Imaging (ISBI) (pp. 159-163).",
25
- doi="10.1109/isbi45749.2020.9098336",
26
- )
27
-
28
- N2NRef = CiteEntry(
29
- text="Lehtinen, J., Munkberg, J., Hasselgren, J., Laine, S., Karras, T., "
30
- 'Aittala, M. and Aila, T., 2018. "Noise2Noise: Learning image restoration '
31
- 'without clean data". arXiv preprint arXiv:1803.04189.',
32
- doi="10.48550/arXiv.1803.04189",
33
- )
34
-
35
- CARERef = CiteEntry(
36
- text='Weigert, Martin, et al. "Content-aware image restoration: pushing the '
37
- 'limits of fluorescence microscopy." Nature methods 15.12 (2018): 1090-1097.',
38
- doi="10.1038/s41592-018-0216-7",
39
- )
@@ -1,20 +0,0 @@
1
- """Type used to represent all transformations users can create."""
2
-
3
- from typing import Union
4
-
5
- from pydantic import Discriminator
6
- from typing_extensions import Annotated
7
-
8
- from .n2v_manipulate_model import N2VManipulateModel
9
- from .xy_flip_model import XYFlipModel
10
- from .xy_random_rotate90_model import XYRandomRotate90Model
11
-
12
- TRANSFORMS_UNION = Annotated[
13
- Union[
14
- XYFlipModel,
15
- XYRandomRotate90Model,
16
- N2VManipulateModel,
17
- ],
18
- Discriminator("name"), # used to tell the different transform models apart
19
- ]
20
- """Available transforms in CAREamics."""