From 9987e5118f80849640b018c4b706324366495657 Mon Sep 17 00:00:00 2001 From: William Patton Date: Tue, 21 Jan 2025 11:11:31 -0800 Subject: [PATCH] black reformatting --- .../experiments/architectures/architecture.py | 3 +-- .../architectures/cnnectome_unet.py | 11 ++++----- .../architectures/cnnectome_unet_impl.py | 1 + .../architectures/model_zoo_config.py | 24 +++++++++---------- dacapo/experiments/tasks/affinities_task.py | 6 +++-- dacapo/experiments/tasks/distance_task.py | 2 +- dacapo/experiments/tasks/dummy_task.py | 2 +- dacapo/experiments/tasks/hot_distance_task.py | 2 +- .../experiments/tasks/inner_distance_task.py | 2 +- dacapo/experiments/tasks/one_hot_task.py | 2 +- dacapo/experiments/tasks/task.py | 2 +- dacapo/store/local_weights_store.py | 7 ++++-- tests/components/test_architectures.py | 8 ++++--- tests/operations/test_architecture.py | 4 +--- 14 files changed, 40 insertions(+), 36 deletions(-) diff --git a/dacapo/experiments/architectures/architecture.py b/dacapo/experiments/architectures/architecture.py index ebeac764..611d63d9 100644 --- a/dacapo/experiments/architectures/architecture.py +++ b/dacapo/experiments/architectures/architecture.py @@ -37,7 +37,6 @@ def module(self) -> torch.nn.Module: """ pass - @property @abstractmethod def input_shape(self) -> Coordinate: @@ -78,4 +77,4 @@ def scale(self, input_voxel_size: Coordinate) -> Coordinate: """ Method to scale the input voxel size as required by the architecture. """ - return input_voxel_size \ No newline at end of file + return input_voxel_size diff --git a/dacapo/experiments/architectures/cnnectome_unet.py b/dacapo/experiments/architectures/cnnectome_unet.py index 7f41fd32..becad754 100644 --- a/dacapo/experiments/architectures/cnnectome_unet.py +++ b/dacapo/experiments/architectures/cnnectome_unet.py @@ -130,12 +130,15 @@ class CNNectomeUNetConfig(ArchitectureConfig): default=False, metadata={"help_text": "Whether to use batch normalization."}, ) + @property def input_shape(self) -> Coordinate: return self._input_shape + @property def input_shape(self) -> Coordinate: return Coordinate(self._input_shape) + @input_shape.setter def input_shape(self, value: Coordinate): self._input_shape = value @@ -147,15 +150,11 @@ def module(self) -> torch.nn.Module: if self.kernel_size_down is not None: kernel_size_down = self.kernel_size_down else: - kernel_size_down = [ - [(3,) * self.dims, (3,) * self.dims] - ] * levels + kernel_size_down = [[(3,) * self.dims, (3,) * self.dims]] * levels if self.kernel_size_up is not None: kernel_size_up = self.kernel_size_up else: - kernel_size_up = [ - [(3,) * self.dims, (3,) * self.dims] - ] * (levels - 1) + kernel_size_up = [[(3,) * self.dims, (3,) * self.dims]] * (levels - 1) # downsample factors has to be a list of tuples downsample_factors = [tuple(x) for x in self.downsample_factors] diff --git a/dacapo/experiments/architectures/cnnectome_unet_impl.py b/dacapo/experiments/architectures/cnnectome_unet_impl.py index 5caf5f9c..963fcf21 100644 --- a/dacapo/experiments/architectures/cnnectome_unet_impl.py +++ b/dacapo/experiments/architectures/cnnectome_unet_impl.py @@ -3,6 +3,7 @@ import math + class CNNectomeUNetModule(torch.nn.Module): """ A U-Net module for 3D or 4D data. The U-Net expects 3D or 4D tensors shaped diff --git a/dacapo/experiments/architectures/model_zoo_config.py b/dacapo/experiments/architectures/model_zoo_config.py index b3de4c36..df378081 100644 --- a/dacapo/experiments/architectures/model_zoo_config.py +++ b/dacapo/experiments/architectures/model_zoo_config.py @@ -91,16 +91,16 @@ def model_description(self) -> ModelDescr: @property def input_desc(self) -> InputTensorDescr: - assert len(self.model_description.inputs) == 1, ( - f"Only models with one input are supported, found {self.model_description.inputs}" - ) + assert ( + len(self.model_description.inputs) == 1 + ), f"Only models with one input are supported, found {self.model_description.inputs}" return self.model_description.inputs[0] @property def output_desc(self) -> OutputTensorDescr: - assert len(self.model_description.outputs) == 1, ( - f"Only models with one output are supported, found {self.model_description.outputs}" - ) + assert ( + len(self.model_description.outputs) == 1 + ), f"Only models with one output are supported, found {self.model_description.outputs}" return self.model_description.outputs[0] @property @@ -115,9 +115,9 @@ def input_shape(self): @property def num_in_channels(self) -> int: channel_axes = [axis for axis in self.input_desc.axes if axis.type == "channel"] - assert len(channel_axes) == 1, ( - f"Only models with one input channel axis are supported, found {channel_axes}" - ) + assert ( + len(channel_axes) == 1 + ), f"Only models with one input channel axis are supported, found {channel_axes}" return channel_axes[0].size @property @@ -125,9 +125,9 @@ def num_out_channels(self) -> int: channel_axes = [ axis for axis in self.output_desc.axes if axis.type == "channel" ] - assert len(channel_axes) == 1, ( - f"Only models with one output channel axis are supported, found {channel_axes}" - ) + assert ( + len(channel_axes) == 1 + ), f"Only models with one output channel axis are supported, found {channel_axes}" return channel_axes[0].size def scale(self, input_voxel_size: Coordinate) -> Coordinate: diff --git a/dacapo/experiments/tasks/affinities_task.py b/dacapo/experiments/tasks/affinities_task.py index a541aea0..8762a00f 100644 --- a/dacapo/experiments/tasks/affinities_task.py +++ b/dacapo/experiments/tasks/affinities_task.py @@ -50,8 +50,10 @@ def __init__(self, task_config): self.post_processor = WatershedPostProcessor(offsets=task_config.neighborhood) self.evaluator = InstanceEvaluator() - self._channels = [f"aff_{'.'.join(map(str, n))}" for n in task_config.neighborhood] + self._channels = [ + f"aff_{'.'.join(map(str, n))}" for n in task_config.neighborhood + ] @property def channels(self) -> list[str]: - return self._channels \ No newline at end of file + return self._channels diff --git a/dacapo/experiments/tasks/distance_task.py b/dacapo/experiments/tasks/distance_task.py index 27d5ba61..d0053f17 100644 --- a/dacapo/experiments/tasks/distance_task.py +++ b/dacapo/experiments/tasks/distance_task.py @@ -58,4 +58,4 @@ def __init__(self, task_config): @property def channels(self) -> list[str]: - return self._channels \ No newline at end of file + return self._channels diff --git a/dacapo/experiments/tasks/dummy_task.py b/dacapo/experiments/tasks/dummy_task.py index 62f152fc..7fa1fc0b 100644 --- a/dacapo/experiments/tasks/dummy_task.py +++ b/dacapo/experiments/tasks/dummy_task.py @@ -54,4 +54,4 @@ def __init__(self, task_config): @property def channels(self) -> list[str]: - return self._channels \ No newline at end of file + return self._channels diff --git a/dacapo/experiments/tasks/hot_distance_task.py b/dacapo/experiments/tasks/hot_distance_task.py index 5ebece8e..f707ea5c 100644 --- a/dacapo/experiments/tasks/hot_distance_task.py +++ b/dacapo/experiments/tasks/hot_distance_task.py @@ -62,4 +62,4 @@ def __init__(self, task_config): @property def channels(self) -> list[str]: - return self._channels \ No newline at end of file + return self._channels diff --git a/dacapo/experiments/tasks/inner_distance_task.py b/dacapo/experiments/tasks/inner_distance_task.py index 0227d746..292dbdd6 100644 --- a/dacapo/experiments/tasks/inner_distance_task.py +++ b/dacapo/experiments/tasks/inner_distance_task.py @@ -51,4 +51,4 @@ def __init__(self, task_config): @property def channels(self) -> list[str]: - return self._channels \ No newline at end of file + return self._channels diff --git a/dacapo/experiments/tasks/one_hot_task.py b/dacapo/experiments/tasks/one_hot_task.py index 9cbc5e02..4b52fc99 100644 --- a/dacapo/experiments/tasks/one_hot_task.py +++ b/dacapo/experiments/tasks/one_hot_task.py @@ -51,4 +51,4 @@ def __init__(self, task_config): @property def channels(self) -> list[str]: - return self._classes \ No newline at end of file + return self._classes diff --git a/dacapo/experiments/tasks/task.py b/dacapo/experiments/tasks/task.py index 9f5269bd..f1714fdb 100644 --- a/dacapo/experiments/tasks/task.py +++ b/dacapo/experiments/tasks/task.py @@ -23,7 +23,7 @@ def evaluation_scores(self) -> EvaluationScores: def create_model(self, architecture): return self.predictor.create_model(architecture=architecture) - + @property @abstractmethod def channels(self) -> list[str]: diff --git a/dacapo/store/local_weights_store.py b/dacapo/store/local_weights_store.py index 727a2a1e..9e2367ed 100644 --- a/dacapo/store/local_weights_store.py +++ b/dacapo/store/local_weights_store.py @@ -72,7 +72,11 @@ def save_trace(self, run: RunConfig): if not trace_file.parent.exists(): trace_file.parent.mkdir(parents=True, exist_ok=True) if not trace_file.exists(): - in_shape = (1, run.architecture.num_in_channels, *run.architecture.input_shape) + in_shape = ( + 1, + run.architecture.num_in_channels, + *run.architecture.input_shape, + ) in_data = torch.randn(in_shape) try: torch.jit.save( @@ -82,7 +86,6 @@ def save_trace(self, run: RunConfig): except SystemError as e: print(f"Error saving trace: {e}, this model will not be traced") trace_file.touch() - def latest_iteration(self, run: str) -> Optional[int]: """ diff --git a/tests/components/test_architectures.py b/tests/components/test_architectures.py index 45fa4cf3..3f84d1dd 100644 --- a/tests/components/test_architectures.py +++ b/tests/components/test_architectures.py @@ -120,13 +120,15 @@ def build_test_architecture_config( tmp_path / "dacapo_modelzoo_test.zip", authors=[Author(name="Test")] ) return ModelZooConfig( - model_id = tmp_path / "dacapo_modelzoo_test.zip", name="test_model_zoo" + model_id=tmp_path / "dacapo_modelzoo_test.zip", name="test_model_zoo" ) # TODO: Move unet parameters that don't affect interaction with other modules # to a separate architcture test -@pytest.mark.filterwarnings("ignore::FutureWarning") # pytest treats this as an error but we don't care for now +@pytest.mark.filterwarnings( + "ignore::FutureWarning" +) # pytest treats this as an error but we don't care for now @pytest.mark.parametrize("data_dims", [2, 3]) @pytest.mark.parametrize("channels", [True, False]) @pytest.mark.parametrize("architecture_dims", [2, 3]) @@ -155,7 +157,7 @@ def test_architectures( use_attention, padding, source, - tmp_path + tmp_path, ) in_data = torch.rand( diff --git a/tests/operations/test_architecture.py b/tests/operations/test_architecture.py index 34c5573f..7408efdc 100644 --- a/tests/operations/test_architecture.py +++ b/tests/operations/test_architecture.py @@ -35,9 +35,7 @@ def test_stored_architecture( architecture = retrieved_arch_config - assert ( - architecture.dims is not None - ), f"Architecture dims are None {architecture}" + assert architecture.dims is not None, f"Architecture dims are None {architecture}" @pytest.mark.parametrize(