Skip to content

Commit

Permalink
chore: Bump version to 0.1.3 in pyproject.toml, implement lazy loadin…
Browse files Browse the repository at this point in the history
…g for submodules in Architecture class, and fix min_output_shape calculation
  • Loading branch information
rhoadesScholar committed Jan 15, 2025
1 parent 83f4b69 commit b00a5ea
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = { text = "BSD 3-Clause License" }
authors = [
{ email = "[email protected]", name = "Jeff Rhoades" },
]
version = "0.1.2"
version = "0.1.3"
dependencies = [
'torch',
'torchvision',
Expand Down
19 changes: 18 additions & 1 deletion src/cellmap_models/pytorch/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
from . import cosem, cellpose, untrained_models
import lazy_loader as lazy

# Lazy-load submodules
__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
"cellpose": [
"add_model",
"load_model",
"get_model",
"download_checkpoint",
"models_dict",
"models_list",
]
},
)

from . import cosem, untrained_models
41 changes: 21 additions & 20 deletions src/cellmap_models/pytorch/cosem/load_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,29 @@ def compute_minimal_shapes(self):

min_input_shape += total_pad

# PART 3: calculate the minimum output shape by propagating from the "bottom right" to the output of the U-Net
min_output_shape = np.copy(min_bottom_right)
for lv in range(len(self.downsample_factors))[
::-1
]: # go through upsampling path
min_output_shape *= self.downsample_factors[
lv
] # calculate shape after upsampling

# calculate shape after convolutions on current level
kernels = np.copy(self.kernel_sizes_up[lv])
total_pad = np.sum(
[np.array(k) - np.array((1.0, 1.0, 1.0)) for k in kernels], axis=0
)

# same rational for translational equivariance as above in PART 1
total_pad = np.ceil(
total_pad / np.prod(self.downsample_factors[lv:], axis=0, dtype=float)
) * np.prod(self.downsample_factors[lv:], axis=0)
min_output_shape -= total_pad
# # PART 3: calculate the minimum output shape by propagating from the "bottom right" to the output of the U-Net
# min_output_shape = np.copy(min_bottom_right)
# for lv in range(len(self.downsample_factors))[
# ::-1
# ]: # go through upsampling path
# min_output_shape *= self.downsample_factors[
# lv
# ] # calculate shape after upsampling

# # calculate shape after convolutions on current level
# kernels = np.copy(self.kernel_sizes_up[lv])
# total_pad = np.sum(
# [np.array(k) - np.array((1.0, 1.0, 1.0)) for k in kernels], axis=0
# )

# # same rational for translational equivariance as above in PART 1
# total_pad = np.ceil(
# total_pad / np.prod(self.downsample_factors[lv:], axis=0, dtype=float)
# ) * np.prod(self.downsample_factors[lv:], axis=0)
# min_output_shape -= total_pad

self.min_input_shape = [int(s) for s in min_input_shape]
min_output_shape = self(torch.ones((1, 1, *self.min_input_shape))).shape[2:]
self.min_output_shape = [int(s) for s in min_output_shape]
self.input_size_step = [int(s) for s in step]

Expand Down

0 comments on commit b00a5ea

Please sign in to comment.