Fix detect.py CSV output crashing on undefined NUM_OUTPUT and wrong df key#7105
Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Open
Conversation
…f key The CSV branch in detect.py's main() cannot run because it references two names that were never introduced in the file: - NUM_OUTPUT is used to build 'classN' column names, but is never defined anywhere in the module. The first time the branch executes, Python raises NameError: name 'NUM_OUTPUT' is not defined. - df['feat'] is used to stack the per-window prediction vectors, but Detector.detect_windows only stores the prediction under the key 'prediction' in each row's dict; there is no 'feat' column. Even if NUM_OUTPUT were defined, df['feat'] would raise KeyError. Stack df['prediction'] once, derive the number of output classes from its shape, and reuse that array for the DataFrame. The h5 branch is unchanged.
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.
Bug
The CSV-output branch of
python/detect.py'smain()cannot run end-to-end: it raisesNameErroronNUM_OUTPUTand, even if that were defined,KeyErrorondf['feat'].https://github.com/BVLC/caffe/blob/9b89154/python/detect.py#L157-L163
Root cause
NUM_OUTPUTis referenced but never defined in the module (no import, no assignment).Detector.detect_windowsbuilds each detection row with the key'prediction'(see detector.py:93-97), so the resulting DataFrame has apredictioncolumn — there is nofeatcolumn.Fix
Stack
df['prediction']once, derive the number of output classes from its shape, and feed the already-stacked array into the per-class DataFrame. No moreNUM_OUTPUT, no moredf['feat'], and the number of columns now reflects the actual prediction vector. The h5 branch is untouched.