careamics 0.0.9__py3-none-any.whl → 0.0.11__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 (63) hide show
  1. careamics/__init__.py +0 -4
  2. careamics/careamist.py +0 -1
  3. careamics/config/__init__.py +1 -13
  4. careamics/config/algorithms/care_algorithm_model.py +84 -0
  5. careamics/config/algorithms/n2n_algorithm_model.py +85 -0
  6. careamics/config/algorithms/n2v_algorithm_model.py +269 -1
  7. careamics/config/configuration.py +21 -13
  8. careamics/config/configuration_factories.py +179 -187
  9. careamics/config/configuration_io.py +2 -2
  10. careamics/config/data/__init__.py +1 -4
  11. careamics/config/data/data_model.py +46 -62
  12. careamics/config/support/supported_transforms.py +1 -1
  13. careamics/config/transformations/__init__.py +0 -2
  14. careamics/config/transformations/n2v_manipulate_model.py +15 -0
  15. careamics/config/transformations/transform_unions.py +0 -13
  16. careamics/dataset/dataset_utils/iterate_over_files.py +2 -2
  17. careamics/dataset/dataset_utils/running_stats.py +7 -3
  18. careamics/dataset/in_memory_dataset.py +3 -10
  19. careamics/dataset/in_memory_pred_dataset.py +3 -5
  20. careamics/dataset/in_memory_tiled_pred_dataset.py +2 -2
  21. careamics/dataset/iterable_dataset.py +2 -2
  22. careamics/dataset/iterable_pred_dataset.py +3 -5
  23. careamics/dataset/iterable_tiled_pred_dataset.py +3 -3
  24. careamics/dataset_ng/dataset/__init__.py +3 -0
  25. careamics/dataset_ng/dataset/dataset.py +184 -0
  26. careamics/dataset_ng/demo_dataset.ipynb +271 -0
  27. careamics/dataset_ng/demo_patch_extractor.py +53 -0
  28. careamics/dataset_ng/demo_patch_extractor_factory.py +37 -0
  29. careamics/dataset_ng/patch_extractor/__init__.py +10 -0
  30. careamics/dataset_ng/patch_extractor/demo_custom_image_stack_loader.py +111 -0
  31. careamics/dataset_ng/patch_extractor/image_stack/__init__.py +9 -0
  32. careamics/dataset_ng/patch_extractor/image_stack/image_stack_protocol.py +53 -0
  33. careamics/dataset_ng/patch_extractor/image_stack/in_memory_image_stack.py +55 -0
  34. careamics/dataset_ng/patch_extractor/image_stack/zarr_image_stack.py +163 -0
  35. careamics/dataset_ng/patch_extractor/image_stack_loader.py +140 -0
  36. careamics/dataset_ng/patch_extractor/patch_extractor.py +29 -0
  37. careamics/dataset_ng/patch_extractor/patch_extractor_factory.py +208 -0
  38. careamics/dataset_ng/patching_strategies/__init__.py +11 -0
  39. careamics/dataset_ng/patching_strategies/patching_strategy_protocol.py +82 -0
  40. careamics/dataset_ng/patching_strategies/random_patching.py +338 -0
  41. careamics/dataset_ng/patching_strategies/sequential_patching.py +75 -0
  42. careamics/lightning/lightning_module.py +78 -27
  43. careamics/lightning/train_data_module.py +8 -39
  44. careamics/losses/fcn/losses.py +17 -10
  45. careamics/model_io/bioimage/bioimage_utils.py +5 -3
  46. careamics/model_io/bioimage/model_description.py +3 -3
  47. careamics/model_io/bmz_io.py +2 -2
  48. careamics/model_io/model_io_utils.py +2 -2
  49. careamics/transforms/__init__.py +2 -1
  50. careamics/transforms/compose.py +5 -15
  51. careamics/transforms/n2v_manipulate_torch.py +143 -0
  52. careamics/transforms/pixel_manipulation.py +1 -0
  53. careamics/transforms/pixel_manipulation_torch.py +418 -0
  54. careamics/utils/version.py +38 -0
  55. {careamics-0.0.9.dist-info → careamics-0.0.11.dist-info}/METADATA +7 -8
  56. {careamics-0.0.9.dist-info → careamics-0.0.11.dist-info}/RECORD +59 -42
  57. careamics/config/care_configuration.py +0 -100
  58. careamics/config/data/n2v_data_model.py +0 -193
  59. careamics/config/n2n_configuration.py +0 -101
  60. careamics/config/n2v_configuration.py +0 -266
  61. {careamics-0.0.9.dist-info → careamics-0.0.11.dist-info}/WHEEL +0 -0
  62. {careamics-0.0.9.dist-info → careamics-0.0.11.dist-info}/entry_points.txt +0 -0
  63. {careamics-0.0.9.dist-info → careamics-0.0.11.dist-info}/licenses/LICENSE +0 -0
@@ -1,266 +0,0 @@
1
- """N2V configuration."""
2
-
3
- from bioimageio.spec.generic.v0_3 import CiteEntry
4
- from pydantic import model_validator
5
- from typing_extensions import Self
6
-
7
- from careamics.config.algorithms import N2VAlgorithm
8
- from careamics.config.configuration import Configuration
9
- from careamics.config.data.n2v_data_model import N2VDataConfig
10
- from careamics.config.support import SupportedPixelManipulation
11
-
12
- N2V = "Noise2Void"
13
- N2V2 = "N2V2"
14
- STRUCT_N2V = "StructN2V"
15
- STRUCT_N2V2 = "StructN2V2"
16
-
17
- N2V_REF = CiteEntry(
18
- text='Krull, A., Buchholz, T.O. and Jug, F., 2019. "Noise2Void - Learning '
19
- 'denoising from single noisy images". In Proceedings of the IEEE/CVF '
20
- "conference on computer vision and pattern recognition (pp. 2129-2137).",
21
- doi="10.1109/cvpr.2019.00223",
22
- )
23
-
24
- N2V2_REF = CiteEntry(
25
- text="Höck, E., Buchholz, T.O., Brachmann, A., Jug, F. and Freytag, A., "
26
- '2022. "N2V2 - Fixing Noise2Void checkerboard artifacts with modified '
27
- 'sampling strategies and a tweaked network architecture". In European '
28
- "Conference on Computer Vision (pp. 503-518).",
29
- doi="10.1007/978-3-031-25069-9_33",
30
- )
31
-
32
- STRUCTN2V_REF = CiteEntry(
33
- text="Broaddus, C., Krull, A., Weigert, M., Schmidt, U. and Myers, G., 2020."
34
- '"Removing structured noise with self-supervised blind-spot '
35
- 'networks". In 2020 IEEE 17th International Symposium on Biomedical '
36
- "Imaging (ISBI) (pp. 159-163).",
37
- doi="10.1109/isbi45749.2020.9098336",
38
- )
39
-
40
- N2V_DESCRIPTION = (
41
- "Noise2Void is a UNet-based self-supervised algorithm that "
42
- "uses blind-spot training to denoise images. In short, in every "
43
- "patches during training, random pixels are selected and their "
44
- "value replaced by a neighboring pixel value. The network is then "
45
- "trained to predict the original pixel value. The algorithm "
46
- "relies on the continuity of the signal (neighboring pixels have "
47
- "similar values) and the pixel-wise independence of the noise "
48
- "(the noise in a pixel is not correlated with the noise in "
49
- "neighboring pixels)."
50
- )
51
-
52
- N2V2_DESCRIPTION = (
53
- "N2V2 is a variant of Noise2Void. "
54
- + N2V_DESCRIPTION
55
- + "\nN2V2 introduces blur-pool layers and removed skip "
56
- "connections in the UNet architecture to remove checkboard "
57
- "artefacts, a common artefacts ocurring in Noise2Void."
58
- )
59
-
60
- STR_N2V_DESCRIPTION = (
61
- "StructN2V is a variant of Noise2Void. "
62
- + N2V_DESCRIPTION
63
- + "\nStructN2V uses a linear mask (horizontal or vertical) to replace "
64
- "the pixel values of neighbors of the masked pixels by a random "
65
- "value. Such masking allows removing 1D structured noise from the "
66
- "the images, the main failure case of the original N2V."
67
- )
68
-
69
- STR_N2V2_DESCRIPTION = (
70
- "StructN2V2 is a a variant of Noise2Void that uses both "
71
- "structN2V and N2V2. "
72
- + N2V_DESCRIPTION
73
- + "\nStructN2V2 uses a linear mask (horizontal or vertical) to replace "
74
- "the pixel values of neighbors of the masked pixels by a random "
75
- "value. Such masking allows removing 1D structured noise from the "
76
- "the images, the main failure case of the original N2V."
77
- "\nN2V2 introduces blur-pool layers and removed skip connections in "
78
- "the UNet architecture to remove checkboard artefacts, a common "
79
- "artefacts ocurring in Noise2Void."
80
- )
81
-
82
-
83
- class N2VConfiguration(Configuration):
84
- """N2V configuration."""
85
-
86
- algorithm_config: N2VAlgorithm
87
-
88
- data_config: N2VDataConfig
89
-
90
- @model_validator(mode="after")
91
- def validate_n2v2(self) -> Self:
92
- """Validate that the N2V2 strategy and models are set correctly.
93
-
94
- Returns
95
- -------
96
- Self
97
- The validateed configuration.
98
-
99
-
100
- Raises
101
- ------
102
- ValueError
103
- If N2V2 is used with the wrong pixel manipulation strategy.
104
- """
105
- if self.algorithm_config.model.n2v2:
106
- if (
107
- self.data_config.get_masking_strategy()
108
- != SupportedPixelManipulation.MEDIAN.value
109
- ):
110
- raise ValueError(
111
- f"N2V2 can only be used with the "
112
- f"{SupportedPixelManipulation.MEDIAN} pixel manipulation strategy"
113
- f". Change the N2VManipulate transform strategy."
114
- )
115
- else:
116
- if (
117
- self.data_config.get_masking_strategy()
118
- != SupportedPixelManipulation.UNIFORM.value
119
- ):
120
- raise ValueError(
121
- f"N2V can only be used with the "
122
- f"{SupportedPixelManipulation.UNIFORM} pixel manipulation strategy"
123
- f". Change the N2VManipulate transform strategy."
124
- )
125
- return self
126
-
127
- def set_n2v2(self, use_n2v2: bool) -> None:
128
- """
129
- Set the configuration to use N2V2 or the vanilla Noise2Void.
130
-
131
- Parameters
132
- ----------
133
- use_n2v2 : bool
134
- Whether to use N2V2.
135
- """
136
- self.data_config.set_n2v2(use_n2v2)
137
- self.algorithm_config.model.n2v2 = use_n2v2
138
-
139
- def get_algorithm_friendly_name(self) -> str:
140
- """
141
- Get the friendly name of the algorithm.
142
-
143
- Returns
144
- -------
145
- str
146
- Friendly name.
147
- """
148
- use_n2v2 = self.algorithm_config.model.n2v2
149
- use_structN2V = self.data_config.is_using_struct_n2v()
150
-
151
- if use_n2v2 and use_structN2V:
152
- return STRUCT_N2V2
153
- elif use_n2v2:
154
- return N2V2
155
- elif use_structN2V:
156
- return STRUCT_N2V
157
- else:
158
- return N2V
159
-
160
- def get_algorithm_keywords(self) -> list[str]:
161
- """
162
- Get algorithm keywords.
163
-
164
- Returns
165
- -------
166
- list[str]
167
- List of keywords.
168
- """
169
- use_n2v2 = self.algorithm_config.model.n2v2
170
- use_structN2V = self.data_config.is_using_struct_n2v()
171
-
172
- keywords = [
173
- "denoising",
174
- "restoration",
175
- "UNet",
176
- "3D" if "Z" in self.data_config.axes else "2D",
177
- "CAREamics",
178
- "pytorch",
179
- N2V,
180
- ]
181
-
182
- if use_n2v2:
183
- keywords.append(N2V2)
184
- if use_structN2V:
185
- keywords.append(STRUCT_N2V)
186
-
187
- return keywords
188
-
189
- def get_algorithm_references(self) -> str:
190
- """
191
- Get the algorithm references.
192
-
193
- This is used to generate the README of the BioImage Model Zoo export.
194
-
195
- Returns
196
- -------
197
- str
198
- Algorithm references.
199
- """
200
- use_n2v2 = self.algorithm_config.model.n2v2
201
- use_structN2V = self.data_config.is_using_struct_n2v()
202
-
203
- references = [
204
- N2V_REF.text + " doi: " + N2V_REF.doi,
205
- N2V2_REF.text + " doi: " + N2V2_REF.doi,
206
- STRUCTN2V_REF.text + " doi: " + STRUCTN2V_REF.doi,
207
- ]
208
-
209
- # return the (struct)N2V(2) references
210
- if use_n2v2 and use_structN2V:
211
- return "\n".join(references)
212
- elif use_n2v2:
213
- references.pop(-1)
214
- return "\n".join(references)
215
- elif use_structN2V:
216
- references.pop(-2)
217
- return "\n".join(references)
218
- else:
219
- return references[0]
220
-
221
- def get_algorithm_citations(self) -> list[CiteEntry]:
222
- """
223
- Return a list of citation entries of the current algorithm.
224
-
225
- This is used to generate the model description for the BioImage Model Zoo.
226
-
227
- Returns
228
- -------
229
- List[CiteEntry]
230
- List of citation entries.
231
- """
232
- use_n2v2 = self.algorithm_config.model.n2v2
233
- use_structN2V = self.data_config.is_using_struct_n2v()
234
-
235
- references = [N2V_REF]
236
-
237
- if use_n2v2:
238
- references.append(N2V2_REF)
239
-
240
- if use_structN2V:
241
- references.append(STRUCTN2V_REF)
242
-
243
- return references
244
-
245
- def get_algorithm_description(self) -> str:
246
- """
247
- Return a description of the algorithm.
248
-
249
- This method is used to generate the README of the BioImage Model Zoo export.
250
-
251
- Returns
252
- -------
253
- str
254
- Description of the algorithm.
255
- """
256
- use_n2v2 = self.algorithm_config.model.n2v2
257
- use_structN2V = self.data_config.is_using_struct_n2v()
258
-
259
- if use_n2v2 and use_structN2V:
260
- return STR_N2V2_DESCRIPTION
261
- elif use_n2v2:
262
- return N2V2_DESCRIPTION
263
- elif use_structN2V:
264
- return STR_N2V_DESCRIPTION
265
- else:
266
- return N2V_DESCRIPTION