stanford-futuredata / noscope

Accelerating network inference over video
http://dawn.cs.stanford.edu/2017/06/22/noscope/
437 stars 122 forks source link

Visualizer.py - TypeError: string indices must be integers, not str #20

Open Arsey opened 7 years ago

Arsey commented 7 years ago

When I run Visualizer.py for (jackson-town-square.mp4 + jackson-town-square.csv), the script throws an error:

Traceback (most recent call last):
  File "/opt/pycharm-2017.2.2/helpers/pydev/pydevd.py", line 1596, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/opt/pycharm-2017.2.2/helpers/pydev/pydevd.py", line 1023, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/user/noscope/noscope/Visualizer.py", line 81, in <module>
    main()
  File "/home/user/noscope/noscope/Visualizer.py", line 77, in main
    draw_video(args.input_csv, args.video_in, nb_frames, args.start_frame, objects)
  File "/home/user/noscope/noscope/Visualizer.py", line 56, in draw_video
    if label['object_name'] not in OBJECTS:
TypeError: string indices must be integers, not str

The code in that place looks strange as you're trying to enumerate the pandas dataframe instead of df.iterrows():

    for i, labels in enumerate(all_labels):
        if i % 500 == 0:
            print i
        for label in labels:
            if label['object_name'] not in OBJECTS:
                continue
            draw_label(label, frame, obj_to_color[label['object_name']])
        vout.write(frame)
        ret, frame = cap.read()

As a result in for loop the variable labels is a string and is equal to "object_name" and the further iteration over it iterates over the string.

pandas version: 0.20.3 python version: 2.7.6

Arsey commented 7 years ago

It looks like the function get_labels in DataUtils.py does not work as it was designed for and causes the error described above. df.set_index('frame') does not create groups it just uses frame as index

def get_labels(csv_fname, limit=None, interval=1, start=0, labels=['person', 'bus', 'car']):
    df = pd.read_csv(csv_fname)
    df = df[df['frame'] >= start]
    df = df[df['frame'] < start + limit]
    df['frame'] -= start
    df = df[df['object_name'].isin(labels)]
    groups = df.set_index('frame')
    return groups

I'm confused with this part.

ddkang commented 7 years ago

It takes all the labels for a given frame and groups it. Pandas is a bit funky, so this allows iteration over a given frame index.

Arsey commented 7 years ago

But in this case, it doesn't work

ddkang commented 7 years ago

https://github.com/stanford-futuredata/noscope/blob/master/analysis/visualize_yolo.py please try this script instead