-
Hello We're trying to figure out a programatic way to edit a human-labelled .slp track. In particular we'd like to delete all human labeled features in the bottom left hand of these videos as they represent huddles of gerbils together and we've decided to completely remove/occlude this part of the video during training + prediction. https://drive.google.com/file/d/1FzXH6Vi-Pg_jOUHVOAGTzb_8WNMgKQ3o/view?usp=share_link We have an .slp file here with 1000 human labeled frames. And the goal would be to be able to edit the .slp file programatically and delete any feature within N pixels of location (x,y). https://drive.google.com/file/d/1folo1zAyePzL84GVSJzr_ipnlCgneDCv/view?usp=share_link Can someone help / show us how to do this? I can do it easily after converting .slp->h5->.npy file, but I don't know how to pack the arrays back into the .slp file. Thanks so much, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hi @catubc, Update: Just use the API as suggested below. The below suggestion is too complicated.
Thanks, |
Beta Was this translation helpful? Give feedback.
-
I realize that the above answer might get a bit hairy when dealing with a project with lots of videos (and therefore lots of analysis files) - if this is the case, let me know, and I can give an example for editing the |
Beta Was this translation helpful? Give feedback.
-
Hi @roomrys, thanks for the comments. So you're suggesting that we:
It is not clear to us what all these variables are? I think a working example would help via cli or api otherwise. Maybe you can also comment on why tracks in .slp files can't be edited directly? There are at least 15-30 videos per training datasets of 1000 labeled frames, so not sure manually tracking all these details individually in each video (e.g. which frame in which video is being labeled) is that easy. Otherwise, here's some of our questions:
Thanks so much for the help. |
Beta Was this translation helpful? Give feedback.
-
Hi @catubc, Through the SLEAP API, you can access the points of instances in a certain area and remove instances meeting a certain criteria: import sleap
ds = "path/to/slp"
labels = sleap.load_file(ds)
labels.videos # Use in ipython to print list of videos in the labels object
video_idx = 0 # Change this select the video of interest from the labels.video list
video = labels.videos[video_idx]
labeled_frames_from_video = labels.get(video)
# Loop through all labeled frames (from a specific video)
for lf in labeled_frames_from_video:
# Loop through all user instances in the current labeled frame
for inst in lf.user_instances:
remove_inst = False
points_array = inst.points_array # Returns a (num_nodes, 2) np.recarray
# Add some logic here to determine whether to remove instance using points_array
if remove_inst:
lf.instances.remove(inst)
# Save the modified slp
new_filename = "path/to/save/modified/slp" # Use a different path from the current slp to be safe
labels.save_file(labels, new_filename) This is somewhat undesirable because of the nested for loop, but should do the trick. Let me know if you have any trouble. Thanks, |
Beta Was this translation helpful? Give feedback.
Hi @catubc,
Through the SLEAP API, you can access the points of instances in a certain area and remove instances meeting a certain criteria: