Skip to content

[bugfix] Reject all-zero --weights instead of producing NaN frame scores - #613

Merged
Breakthrough merged 2 commits into
Breakthrough:mainfrom
EnesSoydan:fix/612-zero-weights
Nov 20, 2026
Merged

Breakthrough merged 2 commits into
Breakthrough:mainfrom
EnesSoydan:fix/612-zero-weights

Conversation

@EnesSoydan

Copy link
Copy Markdown
Contributor

Fixes #612

With all four weights set to 0, ContentDetector divides by the sum of the weights, so every frame score is NaN and detect-content / detect-adaptive finish without finding any scenes. The only sign of it is a numpy RuntimeWarning.

Changes:

  • ContentDetector.__init__ raises ValueError("At least one weight must be non-zero."), next to the existing kernel_size check. This also covers AdaptiveDetector. luma_only=True still works, since it replaces the weights before the check.
  • ScoreWeightsValue rejects all-zero weights, so a config file with weights = 0, 0, 0, 0 fails to load with the existing weights error message (now mentioning the non-zero requirement).
  • -w/--weights goes through ScoreWeightsValue via a _weights_value helper (same approach as _kernel_size_value from [bugfix] Reject invalid --kernel-size with a usage error instead of a traceback (#604) #605), so it gives a usage error:
Error: Invalid value for weights: At least one weight must be non-zero.

The old try/except ValueError around ContentDetector.Components(*weights) is replaced by the helper. Building the named tuple from four floats couldn't raise there, so behavior for valid weights is unchanged.

Tests: CLI and config file cases for both commands in tests/test_cli.py, and a constructor test for both detectors in tests/test_detectors.py. Changelog entry added.

All-zero weights made ContentDetector divide by zero for every frame, so
detect-content/detect-adaptive ran without finding any scenes. Reject them in
ContentDetector, and give a usage error for -w and a config file error.

Fixes Breakthrough#612

@Breakthrough Breakthrough left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR! Just a few minor comments.

Comment thread scenedetect/_cli/context.py Resolved
@Breakthrough Breakthrough added this to the 0.7.4 milestone Nov 18, 2026
Address review: weights must be finite and non-negative, documented on
ContentDetector and AdaptiveDetector. _weights_value returns the
ScoreWeightsValue and lets get_value unwrap it.
@Breakthrough
Breakthrough merged commit 503c3d4 into Breakthrough:main Nov 20, 2026
23 checks passed
@Breakthrough

Copy link
Copy Markdown
Owner

Thanks for the PR 😄

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.

detect-content / detect-adaptive with all weights set to 0 silently produce NaN scores and detect nothing

2 participants