Skip to content

Commit ba00244

Browse files
Add more outputs to debug performance (#108)
1 parent e2f4efa commit ba00244

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

synapse_net/inference/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, scale, verbose):
5454
self.scale = scale
5555

5656
def scale_input(self, input_volume, is_segmentation=False):
57+
t0 = time.time()
5758
if self.scale is None:
5859
return input_volume
5960

@@ -73,10 +74,11 @@ def scale_input(self, input_volume, is_segmentation=False):
7374
input_volume = rescale(input_volume, self.scale, preserve_range=True).astype(input_volume.dtype)
7475

7576
if self.verbose:
76-
print("Rescaled volume from", self._original_shape, "to", input_volume.shape)
77+
print("Rescaled volume from", self._original_shape, "to", input_volume.shape, "in", time.time() - t0, "s")
7778
return input_volume
7879

7980
def rescale_output(self, output, is_segmentation):
81+
t0 = time.time()
8082
if self.scale is None:
8183
return output
8284

@@ -91,6 +93,9 @@ def rescale_output(self, output, is_segmentation):
9193
else:
9294
output = resize(output, out_shape, preserve_range=True).astype(output.dtype)
9395

96+
if self.verbose:
97+
print("Resized prediction back to original shape", output.shape, "in", time.time() - t0, "s")
98+
9499
return output
95100

96101

@@ -463,7 +468,6 @@ def get_default_tiling(is_2d: bool = False) -> Dict[str, Dict[str, int]]:
463468
tiling = {"tile": tile, "halo": halo}
464469
print(f"Determined tile size for MPS: {tiling}")
465470

466-
467471
# I am not sure what is reasonable on a cpu. For now choosing very small tiling.
468472
# (This will not work well on a CPU in any case.)
469473
else:

synapse_net/tools/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def segmentation_cli():
146146
"By default, the scaling factor will be derived from the voxel size of the input data. "
147147
"If this parameter is given it will over-ride the default behavior. "
148148
)
149+
parser.add_argument(
150+
"--verbose", "-v", action="store_true",
151+
help="Whether to print verbose information about the segmentation progress."
152+
)
149153
args = parser.parse_args()
150154

151155
if args.checkpoint is None:
@@ -169,7 +173,7 @@ def segmentation_cli():
169173
scale = (2 if is_2d else 3) * (args.scale,)
170174

171175
segmentation_function = partial(
172-
run_segmentation, model=model, model_type=args.model, verbose=False, tiling=tiling,
176+
run_segmentation, model=model, model_type=args.model, verbose=args.verbose, tiling=tiling,
173177
)
174178
inference_helper(
175179
args.input_path, args.output_path, segmentation_function,

0 commit comments

Comments
 (0)