Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jiayinghsu
Copy link
Contributor

@jiayinghsu jiayinghsu commented Jul 29, 2022

Description

This PR appends labeling suggestions instead of replacing them when the user clicks "Generate Suggestions". To ensure labeling suggestions are unique, we add a filter at the end of each suggestions method that gets rid of any non-unique suggestions. For the stride and random sampling, we create a unique sample space consisting of the frames not yet in the labeling suggestions. This will inevitably slow down suggestion generation (due to looping through already existing suggestions) - a good idea might be to create a cache for labeling suggestions similar to the LabelsDataCache.

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Copy link
Contributor

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

Some superficial changes requested for the first round

environment.yml Outdated
Comment on lines 14 to 16
- cudatoolkit=11.3.1
- cudnn=8.2.1
- nvidia::cuda-nvcc=11.3
# - cudatoolkit=11.3.1
# - cudnn=8.2.1
# - nvidia::cuda-nvcc=11.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this file from the commit, we do not want any changes made to environment.yml

]
unique_idx = set(frame_idxs) - set(prev_idx)
suggestions = cls.idx_list_to_frame_list(unique_idx, video)
labels.suggestions.append(suggestions)
Copy link
Contributor

Choose a reason for hiding this comment

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

We do not want to append the suggestions yet as this function only generates suggestions. We append suggestions later by calling Labels.set_suggestions

sleap/sleap/gui/commands.py

Lines 2414 to 2418 in ab63c9d

new_suggestions = VideoFrameSuggestions.suggest(
labels=context.labels, params=params
)
context.labels.set_suggestions(new_suggestions)

sleap/sleap/io/dataset.py

Lines 1475 to 1477 in ab63c9d

def set_suggestions(self, suggestions: List[SuggestionFrame]):
"""Set the suggested frames."""
self.suggestions = suggestions

Comment on lines 97 to 99
# vid_suggestions = list(range(0, video.frames, frame_increment))[
# :per_video
# ]
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

frames_num = per_video
frames_num = video.frames if (frames_num > video.frames) else frames_num
vid_suggestions = random.sample(range(video.frames), frames_num)
# vid_suggestions = random.sample(range(video.frames), frames_num)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

cls.idx_list_to_frame_list(vid_suggestions, video, group)
)

labels.suggestions.append(suggestions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not append to labels.suggestions here, only return suggestions

Comment on lines 274 to 284

# frame_idxs = list(
# map(
# int,
# np.squeeze(
# np.argwhere(displacements - data_min > data_range * threshold)
# ),
# )
# )

# Take away np.squeeze to resolve the case of 0-d array.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

environment.yml Outdated
Comment on lines 14 to 16
- cudatoolkit=11.3.1
- cudnn=8.2.1
- nvidia::cuda-nvcc=11.3
# - cudatoolkit=11.3.1
# - cudnn=8.2.1
# - nvidia::cuda-nvcc=11.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove any changes made to environment.yml

Comment on lines 191 to 192
# Shift back by 1 frame so offsets line up with frame index.
result[1:] = result[:-1]
# result[1:] = result[:-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

TEST_SMALL_ROBOT_SIV_FILE1 = "tests/data/videos/robot1.jpg"
TEST_SMALL_ROBOT_SIV_FILE2 = "tests/data/videos/robot2.jpg"

TEST_SMALL_ROBOT_VID = "tests/data/videos/test.mp4"
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename test.mp4 to a more descriptive name describing the contents of the video

Comment on lines 201 to 202
# track_b = Track(0, "b")
# track_c = Track(0, "c")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

Copy link
Contributor

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

Should be using a set difference '-' instead of symmetric difference ^. Also, we need to account for different videos in image_feature_based_method.

@@ -1,4 +1,4 @@
name: sleap
name: swe
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these changes, we do not want any changes made to this file.

for video in videos:
vid_idx = list(range(video.frames))
vid_sugg_idx = sugg_idx_dict[video]
print("vid_sugg_idx", vid_sugg_idx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove before merging.

Comment on lines 88 to 96
sugg_idx = [
(sugg.video, sugg.frame_idx)
for suggestions in labels.suggestions
for sugg in suggestions
]

# Turn list of tuples into dict where first argument in tuple is dict key
for vid, frame in sugg_idx:
sugg_idx_dict[vid].append(frame)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we combine these two operations into a single loop?

Comment on lines 113 to 117
frames_num = video.frames if (frames_num > video.frames) else frames_num
vid_suggestions = random.sample(range(video.frames), frames_num)
if len(unique_idx) == 1:
vid_suggestions = list(unique_idx)
else:
vid_suggestions = random.sample(unique_idx, frames_num)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to ensure that frames_num <= len(unique_idx) for random.sample(unique_idx, frames_num) to work. Try changing L113 to frames_num = len(unique_idx) if (frames_num > len(unique_idx)) else frames_num.

Comment on lines 86 to 92
sugg_idx_dict = {video: [] for video in videos}

sugg_idx = [(sugg.video, sugg.frame_idx) for sugg in labels.suggestions]

# Turn list of tuples into dict where first argument in tuple is dict key
for vid, frame in sugg_idx:
sugg_idx_dict[vid].append(frame)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can do this in a single for loop?

Comment on lines 273 to 304
instances3.append(
PredictedInstance(
skeleton=skeleton,
score=1,
track=track_a,
points=dict(
a=PredictedPoint(8, 9, score=0.5), b=PredictedPoint(7, 9, score=0.5)
),
)
)

instances3.append(
PredictedInstance(
skeleton=skeleton,
score=5,
track=track_a,
points=dict(
a=PredictedPoint(2, 3, score=0.7), b=PredictedPoint(6, 5, score=0.7)
),
)
)

instances3.append(
PredictedInstance(
skeleton=skeleton,
score=5,
track=track_a,
points=dict(
a=PredictedPoint(5, 9, score=0.7), b=PredictedPoint(8, 10, score=0.7)
),
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could condense this with instances3.extend(<list of PredictedInstances>)

Comment on lines 791 to 793
print(labels.labeled_frames)
print(labels.videos)

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

labels=labels, params=dict(videos=labels.videos, method="sample", per_video=13)
)
labels.set_suggestions(suggestions)
print(suggestions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

Comment on lines 329 to 331
# TODO(JX): Double check whether returning one frame each time for image features is expected.
# TODO(JX): Double check whether returning no frame during new suggestions for prediction score
# is expected when given 3 frames and one low score instance in each frame.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these if finished

Comment on lines 332 to 345
if params["method"] == "image features":
assert len(suggestions) == 1
assert len(new_suggestions) == 1
elif params["method"] == "prediction_score":
assert len(suggestions) == (
(params["per_video"] + 1) * params["instance_limit"]
)
assert len(new_suggestions) == 0
elif params["method"] == "velocity":
assert len(suggestions) == 1
assert len(new_suggestions) == 0
else:
assert len(suggestions) == params["per_video"]
assert len(new_suggestions) == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some comments as to why we expect these results

@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #874 (c518e72) into develop (eec8a00) will increase coverage by 0.03%.
The diff coverage is 97.14%.

@@             Coverage Diff             @@
##           develop     #874      +/-   ##
===========================================
+ Coverage    67.59%   67.63%   +0.03%     
===========================================
  Files          130      130              
  Lines        22187    22209      +22     
===========================================
+ Hits         14997    15020      +23     
+ Misses        7190     7189       -1     
Impacted Files Coverage Δ
sleap/gui/commands.py 58.61% <0.00%> (ø)
sleap/gui/suggestions.py 82.67% <100.00%> (+4.17%) ⬆️
sleap/io/dataset.py 83.49% <100.00%> (+0.03%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

looks good to me

@roomrys roomrys requested a review from talmo September 6, 2022 16:39
Copy link
Collaborator

@talmo talmo left a comment

Choose a reason for hiding this comment

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

LGTM!

@roomrys roomrys merged commit 4de5213 into talmolab:develop Sep 6, 2022
@roomrys roomrys mentioned this pull request Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants