Skip to content

Commit

Permalink
Add timing outputs (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape authored Jul 10, 2024
1 parent 6ad5e67 commit ed14bb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions micro_sam/sam_annotator/image_series_annotator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time

from glob import glob
from pathlib import Path
Expand Down Expand Up @@ -28,6 +29,8 @@ def _precompute(
tile_shape, halo, precompute_amg_state,
checkpoint_path, device, ndim, prefer_decoder,
):
t_start = time.time()

device = util.get_device(device)
predictor, state = util.get_sam_model(
model_type=model_type, checkpoint_path=checkpoint_path, device=device, return_state=True
Expand All @@ -54,6 +57,11 @@ def _precompute(
]
assert all(os.path.exists(emb_path) for emb_path in embedding_paths)

t_run = time.time() - t_start
minutes = int(t_run // 60)
seconds = int(round(t_run % 60, 0))
print("Precomputation took", t_run, f"seconds (= {minutes:02}:{seconds:02} minutes)")

return predictor, decoder, embedding_paths


Expand Down
9 changes: 9 additions & 0 deletions micro_sam/training/training.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
from glob import glob
from typing import Any, Dict, List, Optional, Tuple, Union

Expand Down Expand Up @@ -181,6 +182,8 @@ def train_sam(
save_every_kth_epoch: Save checkpoints after every kth epoch separately.
pbar_signals: Controls for napari progress bar.
"""
t_start = time.time()

_check_loader(train_loader, with_segmentation_decoder)
_check_loader(val_loader, with_segmentation_decoder)

Expand Down Expand Up @@ -281,6 +284,12 @@ def train_sam(

trainer.fit(**trainer_fit_params)

t_run = time.time() - t_start
hours = int(t_run // 3600)
minutes = int(t_run // 60)
seconds = int(round(t_run % 60, 0))
print("Training took", t_run, f"seconds (= {hours:02}:{minutes:02}:{seconds:02} hours)")


def _update_patch_shape(patch_shape, raw_paths, raw_key, with_channels):
if not isinstance(raw_paths, (str, os.PathLike)):
Expand Down

0 comments on commit ed14bb8

Please sign in to comment.