Too many duplicate track names to Set Instance Track #1678
-
Related to #1083 and #1664, is there a good way to switch track identities when I have too many tracks to be able to use Set Instance Track? Changing the name doesn't work, and with 160 videos I have 1280 different tracks, which means I cannot easily scroll through the entire Set Instance Track menu. Is there a way to force only showing the tracks in the current video, or switch track identities in some other way? Renaming the tracks also renames them previous to the current frame, and I'm not sure that it would connect them anyways. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Closing this because I found the workaround that I missed before. Just including the slightly modified code here for reference if anyone needs it, but you can see the problem solved in #1652. While I didn't need to merge the tracks, it does make everything easier to work with. I'm not merging two sleap files, so less needs to be done with the videos, as it's just merging the labels. There might be an easier way to do it, but this worked. import sleap
sleap.versions()
n_frames = 0
all_frames = []
reference_tracks = {}
slp_files = [
"labels.v001.slp",
]
first_labels = None
ffirst_labels = None
for slp_file in slp_files:
# Load saved labels.
labels = sleap.load_file(slp_file, match_to=first_labels)
if first_labels is None:
first_labels = labels
print(labels)
new_frames = []
for i, lf in enumerate(labels):
# Update the track reference to use the reference tracks to prevent duplication.
for instance in lf:
if instance.track is not None:
if instance.track.name in reference_tracks:
instance.track = reference_tracks[instance.track.name]
else:
reference_tracks[instance.track.name] = instance.track
# Append the labeled frame to the list of frames we're keeping from these labels.
new_frames.append(lf)
all_frames.extend(new_frames)
n_frames += len(new_frames)
merged_labels = sleap.Labels(all_frames)
print(merged_labels)
print(merged_labels.tracks)
merged_labels.save("merged_labels.slp") |
Beta Was this translation helpful? Give feedback.
Closing this because I found the workaround that I missed before. Just including the slightly modified code here for reference if anyone needs it, but you can see the problem solved in #1652. While I didn't need to merge the tracks, it does make everything easier to work with. I'm not merging two sleap files, so less needs to be done with the videos, as it's just merging the labels. There might be an easier way to do it, but this worked.