-
Couldn't load subscription status.
- Fork 119
Append Unique Suggestions #874
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
Conversation
There was a problem hiding this 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
| - 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 |
There was a problem hiding this comment.
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
sleap/gui/suggestions.py
Outdated
| ] | ||
| unique_idx = set(frame_idxs) - set(prev_idx) | ||
| suggestions = cls.idx_list_to_frame_list(unique_idx, video) | ||
| labels.suggestions.append(suggestions) |
There was a problem hiding this comment.
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
Lines 2414 to 2418 in ab63c9d
| new_suggestions = VideoFrameSuggestions.suggest( | |
| labels=context.labels, params=params | |
| ) | |
| context.labels.set_suggestions(new_suggestions) |
Lines 1475 to 1477 in ab63c9d
| def set_suggestions(self, suggestions: List[SuggestionFrame]): | |
| """Set the suggested frames.""" | |
| self.suggestions = suggestions |
sleap/gui/suggestions.py
Outdated
| # vid_suggestions = list(range(0, video.frames, frame_increment))[ | ||
| # :per_video | ||
| # ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
sleap/gui/suggestions.py
Outdated
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
sleap/gui/suggestions.py
Outdated
| cls.idx_list_to_frame_list(vid_suggestions, video, group) | ||
| ) | ||
|
|
||
| labels.suggestions.append(suggestions) |
There was a problem hiding this comment.
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
sleap/gui/suggestions.py
Outdated
|
|
||
| # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
environment.yml
Outdated
| - 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 |
There was a problem hiding this comment.
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
sleap/info/summary.py
Outdated
| # Shift back by 1 frame so offsets line up with frame index. | ||
| result[1:] = result[:-1] | ||
| # result[1:] = result[:-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
tests/fixtures/videos.py
Outdated
| 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" |
There was a problem hiding this comment.
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
tests/gui/test_suggestions.py
Outdated
| # track_b = Track(0, "b") | ||
| # track_c = Track(0, "c") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this 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.
environment_no_cuda.yml
Outdated
| @@ -1,4 +1,4 @@ | |||
| name: sleap | |||
| name: swe | |||
There was a problem hiding this comment.
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.
sleap/gui/suggestions.py
Outdated
| for video in videos: | ||
| vid_idx = list(range(video.frames)) | ||
| vid_sugg_idx = sugg_idx_dict[video] | ||
| print("vid_sugg_idx", vid_sugg_idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove before merging.
sleap/gui/suggestions.py
Outdated
| 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) |
There was a problem hiding this comment.
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?
| 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) |
There was a problem hiding this comment.
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.
sleap/gui/suggestions.py
Outdated
| 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) |
There was a problem hiding this comment.
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?
tests/gui/test_suggestions.py
Outdated
| 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) | ||
| ), | ||
| ) | ||
| ) |
There was a problem hiding this comment.
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>)
tests/io/test_dataset.py
Outdated
| print(labels.labeled_frames) | ||
| print(labels.videos) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
tests/io/test_dataset.py
Outdated
| labels=labels, params=dict(videos=labels.videos, method="sample", per_video=13) | ||
| ) | ||
| labels.set_suggestions(suggestions) | ||
| print(suggestions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
tests/gui/test_suggestions.py
Outdated
| # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these if finished
tests/gui/test_suggestions.py
Outdated
| 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 |
There was a problem hiding this comment.
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 Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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
Does this address any currently open issues?
Outside contributors checklist
Thank you for contributing to SLEAP!
❤️