
Security News
The Nightmare Before Deployment
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.
transnetv2-pytorch
Advanced tools
This repository contains a PyTorch implementation of TransNet V2: An effective deep network architecture for fast shot transition detection.
This is a PyTorch reimplementation of the TransNetV2 model that produces identical results as the original TensorFlow version. The code is for inference only.
Our reevaluation of other publicly available state-of-the-art shot boundary methods (F1 scores):
| Model | ClipShots | BBC Planet Earth | RAI |
|---|---|---|---|
| TransNet V2 | 77.9 | 96.2 | 93.9 |
| TransNet (github) | 73.5 | 92.9 | 94.3 |
| Hassanien et al. (github) | 75.9 | 92.6 | 93.9 |
| Tang et al., ResNet baseline (github) | 76.1 | 89.3 | 92.8 |
pip install transnetv2-pytorch
Or install from source:
git clone https://github.com/allenday/transnetv2_pytorch.git
cd transnetv2_pytorch
pip install -e .
The package provides both a direct command and Python module execution:
# Direct command
transnetv2_pytorch path/to/video.mp4
# Python module execution
python -m transnetv2_pytorch path/to/video.mp4
# Basic usage
transnetv2_pytorch path/to/video.mp4
# Specify output file
transnetv2_pytorch path/to/video.mp4 --output predictions.txt
# Use specific device
transnetv2_pytorch path/to/video.mp4 --device cuda
# Set detection threshold
transnetv2_pytorch path/to/video.mp4 --threshold 0.3
# Get help for all options
transnetv2_pytorch --help
Note: See Device Support section for detailed information about device selection and MPS considerations.
import torch
from transnetv2_pytorch import TransNetV2
# Initialize model
model = TransNetV2(device='auto')
model.eval()
# Load weights
state_dict = torch.load("transnetv2-pytorch-weights.pth", map_location=model.device)
model.load_state_dict(state_dict)
with torch.no_grad():
# Primary method: Scene detection
scenes = model.detect_scenes("video.mp4")
print(f"Found {len(scenes)} scenes")
for scene in scenes[:3]:
print(f"Scene {scene['shot_id']}: {scene['start_time']}s - {scene['end_time']}s")
# Convenience methods
scene_count = model.get_scene_count("video.mp4")
timestamps = model.get_scene_timestamps("video.mp4")
# Custom threshold
scenes = model.detect_scenes("video.mp4", threshold=0.3)
# Comprehensive analysis with raw predictions
results = model.analyze_video("video.mp4")
print(f"Video FPS: {results['fps']}")
print(f"Total scenes: {results['total_scenes']}")
raw_predictions = results['single_frame_predictions']
scenes = results['scenes']
# Raw video predictions only
video_frames, single_frame_pred, all_frame_pred = model.predict_video("video.mp4")
# Direct model inference
frames = load_frames_somehow() # Your frame loading logic
single_frame_pred, all_frame_pred = model.predict_raw(frames)
# Manual scene conversion
import numpy as np
predictions = single_frame_pred.cpu().detach().numpy()
scenes = model.predictions_to_scenes(predictions, threshold=0.5)
scenes_with_data = model.predictions_to_scenes_with_data(predictions, fps=25.0, threshold=0.5)
The CLI tool uses the same methods as the programmatic API:
transnetv2_pytorch video.mp4 --threshold 0.5model.detect_scenes("video.mp4", threshold=0.5)Both produce identical results.
This implementation supports multiple compute devices with intelligent auto-detection:
By default (--device auto), the model uses this priority order:
Priority: CUDA > CPU > MPS
# Auto-detection (recommended)
transnetv2_pytorch video.mp4 --device auto
When MPS is available but auto-detection chooses CPU instead, you'll see:
ℹ️ MPS device detected but not used due to numerical inconsistency issues.
Use --device mps to explicitly enable MPS (faster but inconsistent results).
⚠️ Important: MPS has numerical inconsistency issues with this neural network architecture.
If you prioritize speed over consistency, you can explicitly request MPS:
# Explicit MPS usage (faster but inconsistent)
transnetv2_pytorch video.mp4 --device mps
When explicitly using MPS, you'll see this warning:
⚠️ WARNING: MPS device has numerical inconsistency issues!
This neural network architecture has operations that fall back to CPU
inconsistently, causing different scene detection results vs. pure CPU.
# Auto-detection (chooses best reliable device)
transnetv2_pytorch video.mp4 --device auto
# Force CPU (most reliable, slower)
transnetv2_pytorch video.mp4 --device cpu
# Force MPS (fastest on Apple Silicon, less reliable)
transnetv2_pytorch video.mp4 --device mps
# Force CUDA (fastest + reliable on NVIDIA GPUs)
transnetv2_pytorch video.mp4 --device cuda
from transnetv2_pytorch import TransNetV2
# Auto-detection (recommended)
model = TransNetV2(device='auto')
# Explicit device selection
model = TransNetV2(device='cpu') # Most reliable
model = TransNetV2(device='mps') # Fast but inconsistent
model = TransNetV2(device='cuda') # Fast and reliable
--device auto or --device cpu for consistent, reproducible results--device mps on Apple Silicon if speed is more important than precision--device cuda for optimal performance and consistencyTransNetV2 includes transparent memory optimizations that work automatically without affecting the detection algorithm:
The model automatically:
# Memory optimization is automatic and transparent
model = TransNetV2(device='auto') # All optimizations work behind the scenes
The memory optimizations are built-in and transparent. For persistent memory issues with very large videos:
All optimizations preserve the original algorithm parameters and accuracy!
This PyTorch implementation is based on the original TensorFlow version. For:
Please visit the original repository: soCzech/TransNetV2
This PyTorch implementation is based on the original TensorFlow TransNet V2 by Tomáš Souček and Jakub Lokoč.
If found useful, please cite the original work:
@article{soucek2020transnetv2,
title={TransNet V2: An effective deep network architecture for fast shot transition detection},
author={Sou{\v{c}}ek, Tom{\'a}{\v{s}} and Loko{\v{c}}, Jakub},
year={2020},
journal={arXiv preprint arXiv:2008.04838},
}
This production-ready PyTorch package was developed by [Your Name] with significant improvements including:
MIT License
Original work Copyright (c) 2020 Tomáš Souček, Jakub Lokoč
PyTorch implementation Copyright (c) 2025 Allen Day
See the original TransNetV2 repository for the original license.
FAQs
TransNetV2 PyTorch implementation for video scene detection
We found that transnetv2-pytorch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Season’s greetings from Socket, and here’s to a calm end of year: clean dependencies, boring pipelines, no surprises.

Research
/Security News
Impostor NuGet package Tracer.Fody.NLog typosquats Tracer.Fody and its author, using homoglyph tricks, and exfiltrates Stratis wallet JSON/passwords to a Russian IP address.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.