Repository navigation
[bugfix] Reject all-zero --weights instead of producing NaN frame scores - #613
Merged
Merged
Conversation
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
force-pushed
the
fix/612-zero-weights
branch
from
November 18, 2026 01:05
8bd5806 to
8c7184c
Compare
Breakthrough
requested changes
Nov 18, 2026
Breakthrough
left a comment
Owner
There was a problem hiding this comment.
Thanks for the PR! Just a few minor comments.
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
approved these changes
Nov 20, 2026
Breakthrough
approved these changes
Nov 20, 2026
Owner
|
Thanks for the PR 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #612
With all four weights set to 0,
ContentDetectordivides by the sum of the weights, so every frame score is NaN anddetect-content/detect-adaptivefinish without finding any scenes. The only sign of it is a numpyRuntimeWarning.Changes:
ContentDetector.__init__raisesValueError("At least one weight must be non-zero."), next to the existingkernel_sizecheck. This also coversAdaptiveDetector.luma_only=Truestill works, since it replaces the weights before the check.ScoreWeightsValuerejects all-zero weights, so a config file withweights = 0, 0, 0, 0fails to load with the existing weights error message (now mentioning the non-zero requirement).-w/--weightsgoes throughScoreWeightsValuevia a_weights_valuehelper (same approach as_kernel_size_valuefrom [bugfix] Reject invalid --kernel-size with a usage error instead of a traceback (#604) #605), so it gives a usage error:The old
try/except ValueErroraroundContentDetector.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 intests/test_detectors.py. Changelog entry added.