Skip to content

Commit

Permalink
modify snapshot index determination
Browse files Browse the repository at this point in the history
  • Loading branch information
sidhulyalkar committed Nov 30, 2023
1 parent 6278148 commit 556556b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions element_deeplabcut/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,28 @@ def make(self, key):
except KeyboardInterrupt: # Instructions indicate to train until interrupt
print("DLC training stopped via Keyboard Interrupt")

snapshots = list(model_train_folder.glob("*index*"))
snapshots = sorted(list(model_train_folder.glob("*index*")))
max_modified_time = 0
# DLC goes by snapshot magnitude when judging 'latest' for evaluation
# Here, we mean most recently generated

# `snapshotindex` refers to the file index of the snapshot generated
# The most recent snapshot index will be the number of snapshots - 1
# because it is an index
for snapshot in snapshots:
modified_time = os.path.getmtime(snapshot)
if modified_time > max_modified_time:
latest_snapshot_file = snapshot
latest_snapshot = int(latest_snapshot_file.stem[9:])
max_modified_time = modified_time

# update snapshotindex in the config
latest_snapshot = len(snapshots)-1
dlc_config["snapshotindex"] = latest_snapshot
snapshotindex = snapshots.index(latest_snapshot_file)

dlc_config["snapshotindex"] = snapshotindex
edit_config(
dlc_cfg_filepath,
{"snapshotindex": latest_snapshot},
{"snapshotindex": snapshotindex},
)

self.insert1(
{**key, "latest_snapshot": latest_snapshot, "config_template": dlc_config}
)


0 comments on commit 556556b

Please sign in to comment.