careamics 0.1.0rc1__py3-none-any.whl → 0.1.0rc2__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.

@@ -4,8 +4,6 @@ Convenience functions using torch.
4
4
  These functions are used to control certain aspects and behaviours of PyTorch.
5
5
  """
6
6
  import logging
7
- import os
8
- import sys
9
7
 
10
8
  import torch
11
9
 
@@ -28,66 +26,64 @@ def get_device() -> torch.device:
28
26
  return device
29
27
 
30
28
 
31
- def compile_model(model: torch.nn.Module) -> torch.nn.Module:
32
- """
33
- Torch.compile wrapper.
34
-
35
- Parameters
36
- ----------
37
- model : torch.nn.Module
38
- Model.
39
-
40
- Returns
41
- -------
42
- torch.nn.Module
43
- Compiled model if compile is available, the model itself otherwise.
44
- """
45
- if hasattr(torch, "compile") and sys.version_info.minor <= 9:
46
- return torch.compile(model, mode="reduce-overhead")
47
- else:
48
- return model
49
-
50
-
51
- def seed_everything(seed: int) -> None:
52
- """
53
- Seed all random number generators for reproducibility.
54
-
55
- Parameters
56
- ----------
57
- seed : int
58
- Seed.
59
- """
60
- import random
61
-
62
- import numpy as np
63
-
64
- random.seed(seed)
65
- np.random.seed(seed)
66
- torch.manual_seed(seed)
67
- torch.cuda.manual_seed_all(seed)
68
-
69
-
70
- def setup_cudnn_reproducibility(
71
- deterministic: bool = True, benchmark: bool = True
72
- ) -> None:
73
- """
74
- Prepare CuDNN benchmark and sets it to be deterministic/non-deterministic mode.
75
-
76
- https://pytorch.org/docs/stable/notes/randomness.html#cuda-convolution-benchmarking.
77
-
78
- Parameters
79
- ----------
80
- deterministic : bool
81
- Deterministic mode, if running CuDNN backend.
82
- benchmark : bool
83
- If True, uses CuDNN heuristics to figure out which algorithm will be most
84
- performant for your model architecture and input. False may slow down training.
85
- """
86
- if torch.cuda.is_available():
87
- if deterministic:
88
- deterministic = os.environ.get("CUDNN_DETERMINISTIC", "True") == "True"
89
- torch.backends.cudnn.deterministic = deterministic
90
-
91
- if benchmark:
92
- benchmark = os.environ.get("CUDNN_BENCHMARK", "True") == "True"
93
- torch.backends.cudnn.benchmark = benchmark
29
+ # def compile_model(model: torch.nn.Module) -> torch.nn.Module:
30
+ # """
31
+ # Torch.compile wrapper.
32
+
33
+ # Parameters
34
+ # ----------
35
+ # model : torch.nn.Module
36
+ # Model.
37
+
38
+ # Returns
39
+ # -------
40
+ # torch.nn.Module
41
+ # Compiled model if compile is available, the model itself otherwise.
42
+ # """
43
+ # if hasattr(torch, "compile") and sys.version_info.minor <= 9:
44
+ # return torch.compile(model, mode="reduce-overhead")
45
+ # else:
46
+ # return model
47
+
48
+
49
+ # def seed_everything(seed: int) -> None:
50
+ # """
51
+ # Seed all random number generators for reproducibility.
52
+
53
+ # Parameters
54
+ # ----------
55
+ # seed : int
56
+ # Seed.
57
+ # """
58
+ # import random
59
+
60
+ # import numpy as np
61
+
62
+ # random.seed(seed)
63
+ # np.random.seed(seed)
64
+ # torch.manual_seed(seed)
65
+ # torch.cuda.manual_seed_all(seed)
66
+
67
+
68
+ # def setup_cudnn_reproducibility(
69
+ # deterministic: bool = True, benchmark: bool = True
70
+ # ) -> None:
71
+ # """
72
+ # Prepare CuDNN benchmark and sets it to be deterministic/non-deterministic mode.
73
+
74
+ # Parameters
75
+ # ----------
76
+ # deterministic : bool
77
+ # Deterministic mode, if running CuDNN backend.
78
+ # benchmark : bool
79
+ # If True, uses CuDNN heuristics to figure out which algorithm will be most
80
+ # performant for your model architecture and input. False may slow down training
81
+ # """
82
+ # if torch.cuda.is_available():
83
+ # if deterministic:
84
+ # deterministic = os.environ.get("CUDNN_DETERMINISTIC", "True") == "True"
85
+ # torch.backends.cudnn.deterministic = deterministic
86
+
87
+ # if benchmark:
88
+ # benchmark = os.environ.get("CUDNN_BENCHMARK", "True") == "True"
89
+ # torch.backends.cudnn.benchmark = benchmark
@@ -10,7 +10,7 @@ import numpy as np
10
10
  AXES = "STCZYX"
11
11
 
12
12
 
13
- def check_axes_validity(axes: str) -> bool:
13
+ def check_axes_validity(axes: str) -> None:
14
14
  """
15
15
  Sanity check on axes.
16
16
 
@@ -26,11 +26,6 @@ def check_axes_validity(axes: str) -> bool:
26
26
  ----------
27
27
  axes : str
28
28
  Axes to validate.
29
-
30
- Returns
31
- -------
32
- bool
33
- True if axes are valid, False otherwise.
34
29
  """
35
30
  _axes = axes.upper()
36
31
 
@@ -56,7 +51,7 @@ def check_axes_validity(axes: str) -> bool:
56
51
  if "C" in _axes:
57
52
  raise NotImplementedError("Currently, C axis is not supported.")
58
53
 
59
- # prevent S and T axes together
54
+ # prevent S and T axes at the same time
60
55
  if "T" in _axes and "S" in _axes:
61
56
  raise NotImplementedError(
62
57
  f"Invalid axes {axes}. Cannot contain both S and T axes."
@@ -79,26 +74,45 @@ def check_axes_validity(axes: str) -> bool:
79
74
  f"Invalid axes {axes}. Axes must be in the order {AXES}."
80
75
  )
81
76
 
82
- return True
83
-
84
77
 
85
- def check_array_validity(array: np.ndarray, axes: str) -> None:
78
+ def add_axes(input_array: np.ndarray, axes: str) -> np.ndarray:
86
79
  """
87
- Check that the numpy array is compatible with the axes.
80
+ Add missing axes to the input, typically batch and channel.
81
+
82
+ This method validates the axes first. Then it inspects the input array and add
83
+ missing dimensions if necessary.
88
84
 
89
85
  Parameters
90
86
  ----------
91
- array : np.ndarray
92
- Numpy array.
87
+ input_array : np.ndarray
88
+ Input array.
93
89
  axes : str
94
- Valid axes (see check_axes_validity).
90
+ Axes to add.
91
+
92
+ Returns
93
+ -------
94
+ np.ndarray
95
+ Array with new singleton axes.
95
96
  """
96
- if len(array.shape) - 2 != len(axes):
97
- raise ValueError(
98
- f"Array has {len(array.shape)} dimensions, but axes are {len(axes)}."
99
- f"Externally provided arrays must have extra dimensions for batch and"
100
- f"channel to be compatible with the batchnorm layers."
101
- )
97
+ # validate axes
98
+ check_axes_validity(axes)
99
+
100
+ # is 3D
101
+ is_3D = "Z" in axes
102
+
103
+ # number of dims
104
+ n_dims = 5 if is_3D else 4
105
+
106
+ # array of dim 2, 3 or 4
107
+ if len(input_array.shape) < n_dims:
108
+ if "S" not in axes and "T" not in axes:
109
+ input_array = input_array[np.newaxis, ...]
110
+
111
+ # still missing C dimension
112
+ if len(input_array.shape) < n_dims:
113
+ input_array = input_array[:, np.newaxis, ...]
114
+
115
+ return input_array
102
116
 
103
117
 
104
118
  def check_tiling_validity(tile_shape: List[int], overlaps: List[int]) -> None:
careamics/utils/wandb.py CHANGED
@@ -10,7 +10,7 @@ from typing import Dict, Union
10
10
  import torch
11
11
  import wandb
12
12
 
13
- from ..config import Configuration
13
+ from careamics.config import Configuration
14
14
 
15
15
 
16
16
  def is_notebook() -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: careamics
3
- Version: 0.1.0rc1
3
+ Version: 0.1.0rc2
4
4
  Summary: Toolbox for running N2V and friends.
5
5
  Project-URL: homepage, https://careamics.github.io/
6
6
  Project-URL: repository, https://github.com/CAREamics/careamics
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.8
14
14
  Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
17
18
  Classifier: Typing :: Typed
18
19
  Requires-Python: >=3.8
19
20
  Requires-Dist: bioimageio-core
@@ -26,6 +27,7 @@ Requires-Dist: torchvision
26
27
  Requires-Dist: zarr
27
28
  Provides-Extra: all
28
29
  Requires-Dist: careamics-portfolio; extra == 'all'
30
+ Requires-Dist: ipython; extra == 'all'
29
31
  Requires-Dist: itkwidgets; extra == 'all'
30
32
  Requires-Dist: jupyter; extra == 'all'
31
33
  Requires-Dist: pre-commit; extra == 'all'
@@ -43,12 +45,11 @@ Requires-Dist: ipython; extra == 'notebooks'
43
45
  Requires-Dist: itkwidgets; extra == 'notebooks'
44
46
  Requires-Dist: jupyter; extra == 'notebooks'
45
47
  Requires-Dist: torchsummary; extra == 'notebooks'
48
+ Requires-Dist: wandb; extra == 'notebooks'
46
49
  Provides-Extra: test
47
50
  Requires-Dist: pytest; extra == 'test'
48
51
  Requires-Dist: pytest-cov; extra == 'test'
49
52
  Requires-Dist: wandb; extra == 'test'
50
- Provides-Extra: wandb
51
- Requires-Dist: wandb; extra == 'wandb'
52
53
  Description-Content-Type: text/markdown
53
54
 
54
55
  <p align="center">
@@ -1,46 +1,47 @@
1
1
  careamics/__init__.py,sha256=loM0NCye76AI06vlOtB0sb0B_lqza4xbV5wylrhebzI,383
2
- careamics/engine.py,sha256=H4eXgfW-JovqRVp82FvzMG-hOgiass2-zJpdvmx1Yt8,31652
2
+ careamics/engine.py,sha256=EAK_EtJwGrCNUGoEPPEdFit9tpnMQILhrvg-q0LMqQU,34132
3
3
  careamics/py.typed,sha256=esB4cHc6c07uVkGtqf8at7ttEnprwRxwk8obY8Qumq4,187
4
- careamics/bioimage/__init__.py,sha256=YhTiikELn3IVsgwBR4GcDsFKRfxr5xGU7swJxpz1R3o,314
5
- careamics/bioimage/io.py,sha256=6NuM1NYGXKeT0uxfjEDAsnBHRrw_GNX2YKyR4EN-Oko,7683
4
+ careamics/bioimage/__init__.py,sha256=hXD6_jCPkqJHOBjbsmYmGiH4_kM9_ol5KtX0ECK3rgQ,334
5
+ careamics/bioimage/io.py,sha256=Z4lqUyX9nic1pRmLIS2ulxoOTPPf_XaVHOfq38CUdAM,5533
6
+ careamics/bioimage/rdf.py,sha256=CvVMAZqQGS2Ga-Rm0V1AxuhUTeMGOunEI_HlnD6cxiw,3003
6
7
  careamics/bioimage/docs/Noise2Void.md,sha256=tY66itOlXuVso4tHBM7zfPocjxNuQ4rya6DY7qgs_ro,271
7
8
  careamics/bioimage/docs/__init__.py,sha256=pbN_tkgjycF2Ps1PvrMKzVX7i210LbN6qxmE6lm9yVg,63
8
9
  careamics/config/__init__.py,sha256=NiHGEY0EPcyEPXJs5zPFLQ8LpJqcIN51L51AlzeBzWI,252
9
10
  careamics/config/algorithm.py,sha256=cd4G2O3ih4sLmqU4BAdwHE1UJcjfs6GC9sgGQRsVyL0,6318
10
- careamics/config/config.py,sha256=nDzcowyUEFC23ybP6p7Ru-Y4sITo3lKXiRlMtWwQRsI,8181
11
+ careamics/config/config.py,sha256=TYeTQT9fzvSqzimLRSjFFAuFivzi192lZqFKgnp-Y6g,8291
11
12
  careamics/config/config_filter.py,sha256=nUPdZvvN8hb8P8rc-S938MnOL46DRK1RkOs-3KpXAh8,1082
12
- careamics/config/data.py,sha256=rFgt8glDijY66_qh4RcrvSPhXT-Qx6UXEjNdP1AZPQs,4982
13
+ careamics/config/data.py,sha256=8HIHHoEwLaapX9b1UD39vBJ5EoPUFGxmGqoTXXW3ggA,5027
13
14
  careamics/config/torch_optim.py,sha256=YyicWpULiHY1jVB_MKi7HHqV5DMjvhmGOSS1tfJ3mm8,3096
14
15
  careamics/config/training.py,sha256=E21Pp8fX_NVffeemPRA_twyzEpgtg2ak1ffwx-SeTgc,15451
15
16
  careamics/dataset/__init__.py,sha256=LomFfq1GKNkTXke2Q2t3hJ8sqwfUd1DKX63svU4eL2o,22
16
- careamics/dataset/dataset_utils.py,sha256=ajTUDvzrmZQnnuX-S1lc0xxKPp9BGTsZ7RYiQpz9F8w,2988
17
+ careamics/dataset/dataset_utils.py,sha256=oo2yfeTgVONTlv4R1eey0RhsoJqT4VkEQgRaReJHzeE,2822
17
18
  careamics/dataset/extraction_strategy.py,sha256=rzoggAHhXlq3h66X5C1aYG-AKG7ik-2Ifr-ESWWd1eI,485
18
- careamics/dataset/in_memory_dataset.py,sha256=cmEe5Dnx__eC0YEJ3IQg8Rg3vqpaNVerg-z25svGRLk,6888
19
- careamics/dataset/patching.py,sha256=5MaUrX225qys4abNnm04AHPs5ofB1YH1fjG388lKA-o,15403
20
- careamics/dataset/prepare_dataset.py,sha256=7xOvHYm2LZMMrQHdf3yVwpNgbe_k4T38aU9K4UOD4Do,5110
21
- careamics/dataset/tiff_dataset.py,sha256=Sje50pqA13O_bsyeW8-z4VpeoNZe4gVjzI2nkZO7x5U,7591
19
+ careamics/dataset/in_memory_dataset.py,sha256=-2FPfj4oNNqO4HSpDstpjzgLvBJ2wby9RCHOy-7-Rew,6905
20
+ careamics/dataset/patching.py,sha256=vVgZ4_cxYTn4ycqjYdy3XapSJKCpfGzTR8YnndXtfD4,15344
21
+ careamics/dataset/prepare_dataset.py,sha256=-Ln9vOYNJReD1-U9kU-0hWtscWxKFc19ZrSwGTZH-mQ,5135
22
+ careamics/dataset/tiff_dataset.py,sha256=bMdovjRC_CIlGdYPG73CWSR7R9HBSg2jLl2p4TD2WTU,7664
22
23
  careamics/losses/__init__.py,sha256=U8d0ohvezpFiUF7cBvr8Mb0tAhzZracw5i4GN-5ErOo,94
23
- careamics/losses/loss_factory.py,sha256=ZAIg_u9KvEqzbleSsQqLhw_08MvvuS_w-aFdsX7X0FE,757
24
+ careamics/losses/loss_factory.py,sha256=SAkO8rv3xlQrtd21svXYLihLLK_SZfq1r86TTERAgkM,774
24
25
  careamics/losses/losses.py,sha256=HElIXbgsP1ujsvQhebl2n3KFKERIaG64K-bolI9CGDk,751
25
26
  careamics/manipulation/__init__.py,sha256=eJ5FrR0683tkEpfjVehtPXrGdrxrboOjE92gaMt54MU,119
26
27
  careamics/manipulation/pixel_manipulation.py,sha256=XeJQwHhPDjQhhLke2t_hQh4Arf9dC2wd3qxgGdG2rB4,5056
27
28
  careamics/models/__init__.py,sha256=zZE6_dg4Xv6eZZO0b9N1x-xGUyoziSpL2gOgeXRcp14,110
28
29
  careamics/models/layers.py,sha256=4xrqr6VYFKM3Eto_ll5P_h_IXzEtHOO7GES7T95cIVo,4700
29
- careamics/models/model_factory.py,sha256=ROvJgls01DQsvoZdmPNSu8_UN9twtkQqnP8NskJNKXo,7368
30
+ careamics/models/model_factory.py,sha256=d3LyDt28CAhDGcLKEFDCWi4Uvb3rIsOfRaWfP1a71-Q,7892
30
31
  careamics/models/unet.py,sha256=Xon6x717SxhutOKzSsh4dCnSLesq5GrIQL4UXJ66CTY,10053
31
32
  careamics/prediction/__init__.py,sha256=zIFx-zPhpreGM5hcV5R3rxTdfWw3wnXEMg2fbYqQNfw,183
32
- careamics/prediction/prediction_utils.py,sha256=eK3-Xhz77mKK7UnllZSNI4ohAO6pNThhCqNT2U3UDxk,2564
33
- careamics/utils/__init__.py,sha256=XUMMYeM5_ZkOY9i-H-GXmBUoHUXvyugFZMsDBVX9TNE,479
33
+ careamics/prediction/prediction_utils.py,sha256=CcSSUWw9f9xIXh5Y6QHBQC-GGaIWv_fc913_AN1wpr0,2933
34
+ careamics/utils/__init__.py,sha256=wFqhdFsdE39x1ToFvH4iN8qAb0sMN-u4O74VWulBsJA,419
34
35
  careamics/utils/ascii_logo.txt,sha256=lWwzJbuZLEpKw8R8LU1-KEwzYWqW9G_8IZLb7z8kYO0,942
35
36
  careamics/utils/augment.py,sha256=NltOlCgUQ-kFx5M8uUrJz7JfINDxpS-Nzx9UQCH89M8,1793
36
37
  careamics/utils/context.py,sha256=4xMOMQGkfX-Sookb1BobRVBh2v8t2y4linOluHKpdec,956
37
38
  careamics/utils/logging.py,sha256=VP6QK4GqVGZiVCOHcFwrfOY6qrvMvqP6_Wj2sZpbvfc,10321
38
39
  careamics/utils/metrics.py,sha256=X5umq3mKt1J5u75imlFMJwvwkwHErAcIQfAk0bfQdrA,3484
39
40
  careamics/utils/normalization.py,sha256=8OHnv2dsuTcNBbjmYf1zjODru8Zm7oIxHZvshPJnR6g,1129
40
- careamics/utils/torch_utils.py,sha256=hPD_kDFloX80_WH9rOs_uEerK4xlwRMArGnYbg-tnhk,2360
41
- careamics/utils/validators.py,sha256=vpwCVa5X8XklqK3MvjT5IW_cgRre-nAcDHSou8SAvAM,4706
42
- careamics/utils/wandb.py,sha256=iSEIHesWukpwLjnUfwhdc1SuIHGjD8Pef5xiWFHUeYo,3087
43
- careamics-0.1.0rc1.dist-info/METADATA,sha256=MlGWIfYFGaibrTN-6CctqKJ1LXQD1NcBtOPyNqszueQ,3057
44
- careamics-0.1.0rc1.dist-info/WHEEL,sha256=9QBuHhg6FNW7lppboF2vKVbCGTVzsFykgRQjjlajrhA,87
45
- careamics-0.1.0rc1.dist-info/licenses/LICENSE,sha256=6zdNW-k_xHRKYWUf9tDI_ZplUciFHyj0g16DYuZ2udw,1509
46
- careamics-0.1.0rc1.dist-info/RECORD,,
41
+ careamics/utils/torch_utils.py,sha256=vJh9AwkHvYMWMLmICHaZwXay6CJN5rg3RnuNxZG-WxY,2348
42
+ careamics/utils/validators.py,sha256=eiAmsJs04rfDJq_iJ7WaBbeAYCuMXEd0nnEcHdGAViQ,4965
43
+ careamics/utils/wandb.py,sha256=2h8kM99JFDsPo9Hup_Q-3fglc2QrFN-8ZGiyjZ2BZU8,3095
44
+ careamics-0.1.0rc2.dist-info/METADATA,sha256=fs7yIZ89pIuqh-Ejca_liuT_Xlsn89qX0XZrqZtQqec,3129
45
+ careamics-0.1.0rc2.dist-info/WHEEL,sha256=mRYSEL3Ih6g5a_CVMIcwiF__0Ae4_gLYh01YFNwiq1k,87
46
+ careamics-0.1.0rc2.dist-info/licenses/LICENSE,sha256=6zdNW-k_xHRKYWUf9tDI_ZplUciFHyj0g16DYuZ2udw,1509
47
+ careamics-0.1.0rc2.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.18.0
2
+ Generator: hatchling 1.21.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any