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

Adding Random Seed for Frame Processing #3416

Merged

Conversation

Anthony-Tafoya
Copy link
Contributor

@Anthony-Tafoya Anthony-Tafoya commented Sep 7, 2024

This PR relates to the Issue #3048

Background: Currently, frame processing video logic works by sampling N frames from N evenly spaced intervals throughout the video. Although a worthy method, researchers should be allowed to choose frames from a random seed to produce more consistent results.

This PR implements optional --random_seed and --eval_random_seed flags for the ns-process-data video in case a specific seed is requested.

Verification Evidence: Placed a video and a random seed to produce a consistent result
Here is the result

  1. Showing that the same seed will process the same image frames
  2. Showing the 50-frame output of the set
  3. Showing that the original frame split works successfully


Screen Shot 2024-09-14 at 9 32 09 PM
Screen Shot 2024-09-14 at 9 32 32 PM
Screen Shot 2024-09-14 at 9 33 35 PM

Unit Tests: A function to test_misc that confirms that the random_seed processes the number of frames correctly.

Future Work: After this alternative, finding ways to choose frames based on blurriness and other forms of visual change is necessary. Create an integration test with ns-process-data video since there is only one for image currently.

@Anthony-Tafoya Anthony-Tafoya changed the title NERF-0000: Adding Random Seed Frame Processing Adding Random Seed for Frame Processing Sep 11, 2024
random.seed(random_seed)
frame_indices = sorted(random.sample(range(num_frames), num_frames_target))
select_cmd = "select='" + "+".join([f"eq(n\,{idx})" for idx in frame_indices]) + "',setpts=N/TB,"
CONSOLE.print(f"Extracting {num_frames_target} frames using seed-based random selection.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could u also print the random_seed here as well?

frame_indices = sorted(random.sample(range(num_frames), num_frames_target))
select_cmd = "select='" + "+".join([f"eq(n\,{idx})" for idx in frame_indices]) + "',setpts=N/TB,"
CONSOLE.print(f"Extracting {num_frames_target} frames using seed-based random selection.")
elif spacing > 1:
CONSOLE.print("Number of frames to extract:", math.ceil(num_frames / spacing))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also make the print log more clear that the extracted frame is evenly spacing?

@@ -41,6 +41,10 @@ class VideoToNerfstudioDataset(ColmapConverterToNerfstudioDataset):
"""Feature matching method to use. Vocab tree is recommended for a balance of speed
and accuracy. Exhaustive is slower but more accurate. Sequential is faster but
should only be used for videos."""
random_seed: Optional[int] = None
"""Random seed to select video frames"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this random seed for select training set? maybe make it more clear in the comments

@jb-ye jb-ye enabled auto-merge (squash) September 17, 2024 15:29
@jb-ye jb-ye merged commit 3e638da into nerfstudio-project:main Sep 17, 2024
3 checks passed
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.

2 participants