|
1 | 1 | import argparse
|
| 2 | +from collections import OrderedDict |
2 | 3 | import json
|
3 | 4 | import math
|
4 | 5 | import os
|
@@ -63,11 +64,20 @@ def initialize(self):
|
63 | 64 | self.parser.add_argument('--mye', action='store_true')
|
64 | 65 | self.parser.add_argument('--mye_thresh', type=float, default=0.5)
|
65 | 66 | self.parser.add_argument('--blv', action='store_true')
|
66 |
| - self.parser.add_argument('--blv_num_channels', type=int, default=2) |
67 |
| - self.parser.add_argument('--glia', action='store_true') |
| 67 | + self.parser.add_argument('--blv_num_channels', type=int, default=1) |
| 68 | + self.parser.add_argument('--glia', action='store_true') |
68 | 69 | self.parser.add_argument('--sem', action='store_true')
|
69 | 70 | self.parser.add_argument('--img', action='store_true')
|
70 | 71 |
|
| 72 | + # Semantic segmentation |
| 73 | + self.parser.add_argument('--semantic', action='store_true') |
| 74 | + self.parser.add_argument('--dend', action='store_true') # Dendrite |
| 75 | + self.parser.add_argument('--axon', action='store_true') # Axon |
| 76 | + self.parser.add_argument('--soma', action='store_true') # Soma |
| 77 | + self.parser.add_argument('--nucl', action='store_true') # Nucleus |
| 78 | + self.parser.add_argument('--ecs', action='store_true') # Extracellular space |
| 79 | + self.parser.add_argument('--other', action='store_true') # Other class |
| 80 | + |
71 | 81 | # Test-time augmentation
|
72 | 82 | self.parser.add_argument('--test_aug', type=int, default=None, nargs='+')
|
73 | 83 | self.parser.add_argument('--test_aug16', action='store_true')
|
@@ -203,6 +213,35 @@ def parse(self):
|
203 | 213 | opt.out_spec['bvessel'] = (1,) + opt.outputsz
|
204 | 214 | if opt.img:
|
205 | 215 | opt.out_spec['image'] = (1,) + opt.outputsz
|
| 216 | + if opt.dend: |
| 217 | + opt.out_spec['dendrite'] = (1,) + opt.outputsz |
| 218 | + if opt.axon: |
| 219 | + opt.out_spec['axon'] = (1,) + opt.outputsz |
| 220 | + if opt.soma: |
| 221 | + opt.out_spec['soma'] = (1,) + opt.outputsz |
| 222 | + if opt.nucl: |
| 223 | + opt.out_spec['nucleus'] = (1,) + opt.outputsz |
| 224 | + if opt.ecs: |
| 225 | + opt.out_spec['extracellular_space'] = (1,) + opt.outputsz |
| 226 | + if opt.other: |
| 227 | + opt.out_spec['other_class'] = (1,) + opt.outputsz |
| 228 | + |
| 229 | + # Semantic segmentation |
| 230 | + if opt.semantic: |
| 231 | + required_keys = ['soma', 'axon', 'dendrite', 'glia', 'blood_vessel'] |
| 232 | + |
| 233 | + # Ensure all required keys are present in the opt.out_spec |
| 234 | + assert all(key in opt.out_spec for key in required_keys) |
| 235 | + |
| 236 | + # Use OrderedDict to maintain order of required keys followed by other keys |
| 237 | + out_spec_new = OrderedDict((key, opt.out_spec[key]) for key in required_keys) |
| 238 | + |
| 239 | + # Add remaining keys to out_spec_new |
| 240 | + out_spec_new.update((key, opt.out_spec[key]) for key in opt.out_spec if key not in required_keys) |
| 241 | + |
| 242 | + # Convert back to standard dict if necessary |
| 243 | + opt.out_spec = dict(out_spec_new) |
| 244 | + |
206 | 245 | assert(len(opt.out_spec) > 0)
|
207 | 246 |
|
208 | 247 | # Scan spec
|
@@ -240,6 +279,34 @@ def parse(self):
|
240 | 279 | opt.scan_spec['bvessel'] = (1,) + opt.outputsz
|
241 | 280 | if opt.img:
|
242 | 281 | opt.scan_spec['image'] = (1,) + opt.outputsz
|
| 282 | + if opt.dend: |
| 283 | + opt.scan_spec['dendrite'] = (1,) + opt.outputsz |
| 284 | + if opt.axon: |
| 285 | + opt.scan_spec['axon'] = (1,) + opt.outputsz |
| 286 | + if opt.soma: |
| 287 | + opt.scan_spec['soma'] = (1,) + opt.outputsz |
| 288 | + if opt.nucl: |
| 289 | + opt.scan_spec['nucleus'] = (1,) + opt.outputsz |
| 290 | + if opt.ecs: |
| 291 | + opt.scan_spec['extracellular_space'] = (1,) + opt.outputsz |
| 292 | + if opt.other: |
| 293 | + opt.scan_spec['other_class'] = (1,) + opt.outputsz |
| 294 | + |
| 295 | + # Semantic segmentation |
| 296 | + if opt.semantic: |
| 297 | + required_keys = ['soma', 'axon', 'dendrite', 'glia', 'blood_vessel'] |
| 298 | + |
| 299 | + # Ensure all required keys are present in the opt.scan_spec |
| 300 | + assert all(key in opt.scan_spec for key in required_keys) |
| 301 | + |
| 302 | + # Use OrderedDict to maintain order of required keys followed by other keys |
| 303 | + scan_spec_new = OrderedDict((key, opt.scan_spec[key]) for key in required_keys) |
| 304 | + |
| 305 | + # Add remaining keys to scan_spec_new |
| 306 | + scan_spec_new.update((key, opt.scan_spec[key]) for key in opt.scan_spec if key not in required_keys) |
| 307 | + |
| 308 | + # Convert back to standard dict if necessary |
| 309 | + opt.scan_spec = dict(scan_spec_new) |
243 | 310 |
|
244 | 311 | # Test-time augmentation
|
245 | 312 | if opt.test_aug16:
|
|
0 commit comments