Skip to content

Modernize codebase: auto-detect GPU/CPU, replace print with logging, update deps - #78

Merged
joonson merged 3 commits into
masterfrom
modernize-code
Apr 17, 2026
Merged

Modernize codebase: auto-detect GPU/CPU, replace print with logging, update deps#78
joonson merged 3 commits into
masterfrom
modernize-code

Conversation

@joonson

@joonson joonson commented Apr 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • GPU/CPU auto-detection: SyncNetInstance and S3FD now auto-detect CUDA availability and fall back to CPU. All .cuda() calls replaced with .to(device).
  • Logging: Replaced all print() calls with Python logging module across every script.
  • Subprocess safety: Replaced subprocess.call(str, shell=True) with subprocess.run(list) to prevent command injection. Replaced pdb.set_trace() error handling with proper exceptions.
  • Deprecated API fixes: Removed torch.autograd.Variable, added weights_only=True to torch.load(), fixed np.intnp.intp, modernized NMS tensor operations in S3FD to remove deprecated out= resize pattern.
  • Scenedetect 0.6 migration: Updated from pinned scenedetect==0.5.1 to 0.6.7.1, rewrote scene_detect() to use the modern open_video / SceneManager API.
  • General cleanup: super() without args, removed trailing semicolons, #!/usr/bin/env python3 shebangs, mkdir -p in download script, removed unused imports, os.makedirs(exist_ok=True).
  • README: Clarified expected output is approximate, separated model download step, added pipeline stage descriptions.

Test plan

  • Run sh download_model.sh — verify model and weights download without errors
  • Run python demo_syncnet.py --videofile data/example.avi --tmp_dir data/work/pytmp — verify AV offset ~3, confidence ~10
  • Run full pipeline (run_pipeline.pyrun_syncnet.pyrun_visualise.py) on a test video
  • Test on a CPU-only machine (or with CUDA_VISIBLE_DEVICES="") to verify fallback works
  • Test on a CUDA machine to verify GPU path still works

@joonson
joonson marked this pull request as ready for review April 11, 2026 13:16
@joonson
joonson marked this pull request as draft April 11, 2026 13:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes the repository by updating to Python 3, replacing print statements with a structured logging configuration, and transitioning from requirements.txt to Conda environment files. Key improvements include updating ffmpeg subprocess calls for better error handling, removing deprecated torch.autograd.Variable usage, and refactoring the scenedetect integration to support newer API versions. Review feedback highlights a potential TypeError when logging PyTorch tensors without converting them to scalars and identifies compatibility issues with weights_only=True in torch.load when handling full model pickles.

Comment thread SyncNetInstance.py Outdated
Comment thread SyncNetModel.py Outdated
Comment thread SyncNetInstance.py
@joonson

joonson commented Apr 11, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes the repository by migrating to Python 3, replacing print statements with the logging module, and introducing conda environment files for dependency management. Significant changes include updating PySceneDetect API usage, improving FFmpeg command execution via subprocess.run, and enhancing security by using weights_only=True in torch.load. Review feedback identifies a missed logger conversion in SyncNetModel.py and a redundant file-opening operation in run_pipeline.py.

Comment thread SyncNetModel.py Outdated
Comment thread run_pipeline.py Outdated
@joonson

joonson commented Apr 11, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request modernizes the codebase by upgrading to Python 3, introducing structured logging, and improving environment management via Conda. Key technical improvements include the removal of deprecated PyTorch features like Variable, the use of weights_only=True for secure model loading, and the transition to subprocess.run for more robust external command execution. The review feedback highlights two important reliability issues: the need for math.isclose when comparing floating-point durations to avoid precision errors, and the requirement to explicitly release video resources in run_pipeline.py to prevent potential file handle leaks.

Comment thread SyncNetInstance.py
Comment thread run_pipeline.py
@joonson
joonson marked this pull request as ready for review April 16, 2026 12:45
@joonson
joonson merged commit 907c0b5 into master Apr 17, 2026
@joonson
joonson deleted the modernize-code branch April 17, 2026 06:41
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.

1 participant