Skip to content

Video_sampling scripts added - #16

Merged
ximihoque merged 28 commits into
Labellerr:mainfrom
yashsuman15:feature/LABIMP-7672
Oct 14, 2025
Merged

Video_sampling scripts added#16
ximihoque merged 28 commits into
Labellerr:mainfrom
yashsuman15:feature/LABIMP-7672

Conversation

@yashsuman15

Copy link
Copy Markdown
Collaborator
  • created SDKPython subdir in labellerr
  • added utils/client_utils
  • added video_sampling/pyscene_detect.py

yashsuman15 and others added 6 commits September 14, 2025 19:43
test: Add integration tests for Labellerr SDK

This commit introduces integration tests for core SDK functionalities:

Features tested:
- Project creation with multiple annotation types:
  * Polygon annotations
  * Bounding box detection
  * Classification (select, dropdown, radio)
  * Text input fields
  * Combined annotation types
- Project export functionality
- Pre-annotation upload support (COCO JSON format)

Test structure:
/tests
  /integration
    - Create_Project.py    # Project creation test cases
    - Export_project.py    # Export functionality tests
    - Pre_annotation.py    # Pre-annotation upload tests
    - main.py             # Test runner
    - cred.py            # Credentials config (gitignored)

Requirements:
- Valid API credentials in cred.py
- Test image dataset in test_img/
- Sample annotations in annotations.json

Note: Remember to update cred.py with valid credentials before running tests
-removed __pychace__
-added .gitignore
- added utils/client_utils
- added video_sampling/pyscene_detect.py
- add videointelligence module in requirements
import os
import cv2
from PIL import Image
from dataclasses import dataclass, asdict

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use pydantic instead

Comment on lines +215 to +220
mapping = {
"file_id": result.file_id,
"output_folder": result.output_folder,
"total_frames": result.total_frames,
"total_selected_frames": len(result.selected_frames),
"detection_method": "Google Cloud Video Intelligence API - Shot Change Detection",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use pydantic's model dump

selected_frames: List[SceneFrame]


class GeminiSceneDetect:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

create all singleton classes

# video_path=video_path,
# file_id="video_001",
# credentials_path=cred_json_path # Uses GOOGLE_APPLICATION_CREDENTIALS env var
# )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

detector should know the attrs of the labellerr_file, so that if it requires, video_path, file_id, or frames etc whatever, it can access from the labellerr_file instance itself

class GeminiSceneDetect:
"""Google Cloud Video Intelligence API scene detection and frame extraction."""

def __init__(self, video_path: str, file_id: str, gcs_uri: Optional[str] = None, credentials_path: Optional[str] = None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gcs_uri shouldn't be required in the constructor

"""
features = [videointelligence.Feature.SHOT_CHANGE_DETECTION]

if self.gcs_uri:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gcs uri will only be used if the user is using Labellerr's gemini model. For files > 10 mb, and if user is using his own svc account, then we raise an error.

Comment on lines +40 to +41
credentials_path: Path to service account JSON key file.
If None, uses GOOGLE_APPLICATION_CREDENTIALS environment variable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if any svc account file is provided then 10 mb limit is enforced, if not provided then copy the video file to gcs, then send the gcs_uri path to gemini (to be done, when we move this code to the DataOps repo)

success_count = 0
failed_frames = []

print(f"Downloading {len(frames_data)} frames to: {save_path}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use multithreading to download all the frames

# https://api.labellerr.com/data/file_data?file_id=c44f38f6-0186-436f-8c2d-ffb50a539c76&include_answers=false&project_id=gabrila_artificial_duck_74237&uuid=1d4c9b58-c6a4-4ca8-9583-b6b6cd25ef12


class FileMetadataService:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this to services/labellerr_files/init.py

import subprocess
import os

class FFMPEG:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

make it FFMPEGSceneDetect

@yashsuman15 yashsuman15 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Modify the scripts based on comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add versioninig to each requirement

Comment thread labellerr/services/video_sampling/pyscene_detect.py Outdated

@yashsuman15 yashsuman15 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can you help me how can i implement limit in scene detections file based on density (which you have me told earlier)

currently all the scene change are extracted and i need to select only specific numbers of that.

added the updated client.py
added the restructure files
Refactor video sampling services to include dataset ID in output folder structure

- Updated FFMPEGSceneDetect to derive dataset ID from video path and include it in the output folder.
- Modified PySceneDetect to incorporate dataset ID in the output folder structure.
- Adjusted SSIMSceneDetect to also use dataset ID for organizing output folders.
@ximihoque

Copy link
Copy Markdown
Contributor

Comments on the notebook -

  1. It should be dataset = LabellerrDataset(client, dataset_id, project_id)
  2. results = dataset.download()

Where is the boilerplate code for using the frames to create ImageDataset from the frames ?

  1. Write docstrings and pseudo code to create ImageDataset with all the sampled frames.
  2. Use that dataset to create a Project. Ensure the file names are file_id/frame_idx in the dataset for backtracking.
  3. Create an export of this project
  4. Using the export, upload pre-annotations to the VideoProject [ this feature will be available today ].

yashsuman15 and others added 2 commits October 14, 2025 16:58
…ataset and update related methods in SDK notebook

- Updated import statements in __init__.py and SDK.ipynb to reflect the new class name.
- Renamed method process_all_videos() to download() in LabellerrDataset class.
- Adjusted SDK notebook to use the new download() method for processing videos.
- Corrected dataset directory path in SDK notebook.
- Added sections for project creation and image dataset handling in the SDK notebook.
@ximihoque
ximihoque merged commit 551e304 into Labellerr:main Oct 14, 2025
1 of 2 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