Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(3a -> 3) Add method to match instances across views #1579

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
71db786
Update methods to allow triangulating multiple instances at once
Oct 31, 2023
f6be8c4
Return instances and coords as a dictionary with cams
Oct 31, 2023
c4690ec
Update get_instance_across_views to handle multiple frames
Oct 31, 2023
e495241
[wip] Update calculate reprojected points to support multiple frames
roomrys Nov 1, 2023
4470c0e
Finish support for multi-frame reprojection
Nov 2, 2023
d83ea64
Remove code to put in next PR
Nov 2, 2023
9020afb
Merge branch 'liezl/asc-initial-update-instances-across-views' of htt…
roomrys Dec 6, 2023
443d410
(3b -> 3a) Add method to get single instance permutations (#1586)
roomrys Jan 20, 2024
c3a8173
(3e -> 3a) Add `InstanceGroup` class (#1618)
roomrys Apr 12, 2024
9d61980
Only use user-`Instance`s for triangulation
roomrys Apr 12, 2024
08eb996
Remove unused code
roomrys Apr 12, 2024
34a4dcd
Use `LabeledFrame` class instead of dummy labeled frame
roomrys Apr 12, 2024
a330c69
Limit which methods can update `Labels.labeled_frames`
roomrys Apr 15, 2024
e78642e
Update cache when Labels. remove_session_video
roomrys Apr 15, 2024
712319c
Remove RecordingSession.instance_groups
roomrys Apr 15, 2024
ddbd19c
[wip] Maintain cached FrameGroup dictionaries
roomrys Apr 15, 2024
9454943
Add unique name (per FrameGroup) requirement for InstanceGroup
roomrys Apr 16, 2024
545dd44
Lint
roomrys Apr 16, 2024
3fe0246
Fix remove_video bug
roomrys Apr 17, 2024
118cf37
Add RecordingSession.new_frame_group method
roomrys Apr 17, 2024
f7b178b
Add TODO comments for later
roomrys Apr 17, 2024
ca6319a
Fix RecordingSesssion.remove_video bug
roomrys Apr 17, 2024
176efb2
Remove FrameGroup._frame_idx_registry class attribute
Apr 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
461 changes: 83 additions & 378 deletions sleap/gui/commands.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sleap/gui/dialogs/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _delete(self, lf_inst_list: List[Tuple[LabeledFrame, Instance]]):
for lf, inst in lf_inst_list:
self.context.labels.remove_instance(lf, inst, in_transaction=True)
if not lf.instances:
self.context.labels.remove(lf)
self.context.labels.remove_frame(lf=lf, update_cache=False)

# Update caches since we skipped doing this after each deletion
self.context.labels.update_cache()
Expand Down
25 changes: 23 additions & 2 deletions sleap/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ def _points_dict_to_array(
)
try:
parray[skeleton.node_to_index(node)] = point
# parray[skeleton.node_to_index(node.name)] = point
except:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using a bare except statement.

-            except:
+            except Exception as e:
+                logger.error(f"Error setting point for node {node} in {skeleton} with point {point}: {str(e)}")

Using a bare except can catch unexpected exceptions and make debugging difficult. Specify the exception type or handle the general Exception and log the error for better error management.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
except:
except Exception as e:
logger.error(f"Error setting point for node {node} in {skeleton} with point {point}: {str(e)}")

logger.debug(
f"Could not set point for node {node} in {skeleton} "
Expand Down Expand Up @@ -729,9 +728,31 @@ def update_points(self, points: np.ndarray, exclude_complete: bool = False):
for point_new, points_old, node_name in zip(
points, self._points, self.skeleton.node_names
):

# Skip if new point is nan or old point is complete
if np.isnan(point_new).any() or (exclude_complete and points_old.complete):
continue
points_dict[node_name] = Point(x=point_new[0], y=point_new[1])

# Grab the x, y from the new point and visible, complete from the old point
x, y = point_new
visible = points_old.visible
complete = points_old.complete

# Create a new point and add to the dict
if type(self._points) == PredictedPointArray:
# TODO(LM): The point score is meant to rate the confidence of the
# prediction, but this method updates from triangulation.
score = points_old.score
point_obj = PredictedPoint(
x=x, y=y, visible=visible, complete=complete, score=score
)
else:
point_obj = Point(x=x, y=y, visible=visible, complete=complete)

Comment on lines +742 to +751
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure consistent handling of point types in update_points.

The method differentiates between PredictedPointArray and PointArray when creating new point objects. This is a good practice as it maintains the distinction between predicted and manually labeled points. However, ensure that this differentiation is consistently applied throughout your codebase to avoid type mismatches.

# Update the points dict
points_dict[node_name] = point_obj

# Update the points
if len(points_dict) > 0:
Instance._points_dict_to_array(points_dict, self._points, self.skeleton)

Expand Down
Loading
Loading