Skip to content

Commit 61b1fc9

Browse files
anna-grimanna-grim
andauthored
refactor: update merge training (#702)
* refactor: update merge training * feat: generate neg exs, site sampling * rm exaspim dataloader * refactor: image loader working for merge detection * refactor: image config * refactor: configs * refactor: class rebalancing, ds creation * refactor: improved swc and graph loader * bug: config subclassing * refactor: random site generation --------- Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 94b99dd commit 61b1fc9

19 files changed

Lines changed: 1269 additions & 2538 deletions

src/neuron_proofreader/config.py

Lines changed: 0 additions & 180 deletions
This file was deleted.

src/neuron_proofreader/configs.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Created on Frid Sept 15 16:00:00 2024
3+
4+
@author: Anna Grim
5+
@email: anna.grim@alleninstitute.org
6+
7+
Connfiguration classes used for setting storing parameters used in neuron
8+
proofreading pipelines.
9+
10+
"""
11+
12+
from abc import ABC
13+
from dataclasses import asdict, dataclass
14+
from typing import Tuple
15+
16+
import os
17+
18+
from neuron_proofreader.utils import util
19+
20+
21+
class Config(ABC):
22+
23+
def to_dict(self):
24+
"""
25+
Converts configuration attributes to a dictionary.
26+
27+
Returns
28+
-------
29+
attrs : dict
30+
Dictionary containing configuration attributes.
31+
"""
32+
attrs = asdict(self)
33+
for k, v in attrs.items():
34+
if isinstance(v, tuple):
35+
attrs[k] = list(v)
36+
return attrs
37+
38+
def save(self, output_dir):
39+
"""
40+
Saves configuration attributes to a JSON file.
41+
42+
dir_path : str
43+
Path to directory to save JSON file.
44+
"""
45+
path = os.path.join(output_dir, f"{self.name}.json")
46+
util.write_json(path, self.to_dict())
47+
48+
49+
@dataclass
50+
class GraphConfig(Config):
51+
"""
52+
Configuration class for skeleton graph parameters.
53+
54+
Attributes
55+
----------
56+
anisotropy : Tuple[float]
57+
Scaling factors used to transform physical to image coordinates.
58+
min_cable_length : float
59+
Minimum path length (in microns) of SWC files loaded into graph.
60+
node_spacing : float
61+
Physcial spacing (in microns) between nodes.
62+
prune_depth : int
63+
...
64+
remove_doubles : bool
65+
Indication of whether to remove fragments that are likely a double of
66+
another.
67+
verbose : bool
68+
Indication of whether to display a progress bar.
69+
"""
70+
71+
anisotropy: Tuple[float, float, float] = (1.0, 1.0, 1.0)
72+
min_cable_length: float = 0.0
73+
min_swc_pts: int = 1
74+
name: str = "graph_config"
75+
node_spacing: float = 1.0
76+
prune_depth: float = 20.0
77+
remove_doubles: bool = True
78+
use_anisotropy: bool = True
79+
verbose: bool = False
80+
81+
82+
@dataclass
83+
class ImageConfig(Config):
84+
"""
85+
Configuration class for image processing parameters.
86+
87+
Attributes
88+
----------
89+
brightness_clip : int
90+
Intensity value that voxel brightness is clipped to.
91+
percentiles : Tuple[float], optional
92+
Percentiles used to normalize patches.
93+
patch_shape : Tuple[int]
94+
Shape of patch to be read from image.
95+
transform : bool
96+
Indication of whether to use image augmentation.
97+
"""
98+
99+
brightness_clip: int = 400
100+
name: str = "image_config"
101+
percentiles: Tuple[float, float] = (1, 99.5)
102+
patch_shape: Tuple[int, int, int] = (128, 128, 128)
103+
transform: bool = False
104+
105+
def set_train_mode(self):
106+
self.transform = True
107+
108+
109+
@dataclass
110+
class ProposalsConfig(Config):
111+
"""
112+
Configuration class for skeleton graph parameters.
113+
114+
Attributes
115+
----------
116+
allow_nonleaf_proposals : bool
117+
Indication of whether to generate proposals between leaf and nodes
118+
with degree 2.
119+
proposals_per_leaf : int
120+
Maximum number of proposals generated at leaf nodes.
121+
trim_endpoints_bool : bool
122+
Indication of whether trim endpoints of isolated leaf-to-leaf
123+
proposals.
124+
"""
125+
126+
allow_nonleaf_proposals: bool = False
127+
proposals_per_leaf: int = 3
128+
trim_endpoints_bool: bool = True

0 commit comments

Comments
 (0)