Skip to content

Fix detect.py CSV output crashing on undefined NUM_OUTPUT and wrong df key#7105

Open
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/detect-csv-output-undefined-num-output-and-wrong-key
Open

Fix detect.py CSV output crashing on undefined NUM_OUTPUT and wrong df key#7105
Chessing234 wants to merge 1 commit intoBVLC:masterfrom
Chessing234:fix/detect-csv-output-undefined-num-output-and-wrong-key

Conversation

@Chessing234
Copy link
Copy Markdown

Bug

The CSV-output branch of python/detect.py's main() cannot run end-to-end: it raises NameError on NUM_OUTPUT and, even if that were defined, KeyError on df['feat'].

https://github.com/BVLC/caffe/blob/9b89154/python/detect.py#L157-L163

if args.output_file.lower().endswith('csv'):
    # csv
    # Enumerate the class probabilities.
    class_cols = ['class{}'.format(x) for x in range(NUM_OUTPUT)]
    df[class_cols] = pd.DataFrame(
        data=np.vstack(df['feat']), index=df.index, columns=class_cols)
    df.to_csv(args.output_file, cols=COORD_COLS + class_cols)

Root cause

  • NUM_OUTPUT is referenced but never defined in the module (no import, no assignment).
  • Detector.detect_windows builds each detection row with the key 'prediction' (see detector.py:93-97), so the resulting DataFrame has a prediction column — there is no feat column.

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 more NUM_OUTPUT, no more df['feat'], and the number of columns now reflects the actual prediction vector. The h5 branch is untouched.

…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.
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