# Buggy code
def filter_by_aoi(self, aoi_polygons):
    boxes = self.get_boxes()
    class_ids = self.get_class_ids()
    scores = self.get_scores()

    new_boxes = []
    new_class_ids = []
    new_scores = []
    for box, class_id, score in zip(boxes, class_ids, scores):
        box_poly = box.to_shapely()
        for aoi in aoi_polygons:
            if box_poly.within(aoi):
                new_boxes.append(box)
                new_class_ids.append(class_id)
                new_scores.append(score)
                break

    return ObjectDetectionLabels(
        np.array(new_boxes), np.array(new_class_ids), np.array(new_scores)
    )


# Traceback (ValueError)
Running evaluator: ObjectDetectionEvaluator...
2019-03-28 16:47:07:rastervision.evaluation.classification_evaluator: INFO - Computing evaluation for scene 01986917-30ea-4f7f-8e01-985d73b8aa2a...
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/src/rastervision/__main__.py", line 17, in <module>
rv.main()
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/opt/src/rastervision/cli/main.py", line 260, in run_command
rv.runner.CommandRunner.run(command_config_uri)
File "/opt/src/rastervision/runner/command_runner.py", line 11, in run
CommandRunner.run_from_proto(msg)
File "/opt/src/rastervision/runner/command_runner.py", line 17, in run_from_proto
command.run()
File "/opt/src/rastervision/command/eval_command.py", line 24, in run
evaluator.process(scenes, tmp_dir)
File "/opt/src/rastervision/evaluation/classification_evaluator.py", line 36, in process
scene.aoi_polygons)
File "/opt/src/rastervision/data/label/object_detection_labels.py", line 70, in filter_by_aoi
np.array(new_boxes), np.array(new_class_ids), np.array(new_scores))
File "/opt/src/rastervision/data/label/object_detection_labels.py", line 27, in __init__
self.boxlist = BoxList(npboxes)
File "/opt/tf-models/object_detection/utils/np_box_list.py", line 46, in __init__
raise ValueError('Invalid dimensions for box data.')
ValueError: Invalid dimensions for box data.
/tmp/tmpwie3_vrf/tmp41bj3kgh/Makefile:9: recipe for target '3' failed
make: *** [3] Error 1
make: *** Waiting for unfinished jobs....

# Fixed code
def filter_by_aoi(self, aoi_polygons):
    boxes = self.get_boxes()
    class_ids = self.get_class_ids()
    scores = self.get_scores()

    new_boxes = []
    new_class_ids = []
    new_scores = []
    for box, class_id, score in zip(boxes, class_ids, scores):
        box_poly = box.to_shapely()
        for aoi in aoi_polygons:
            if box_poly.within(aoi):
                new_boxes.append(box.npbox_format())
                new_class_ids.append(class_id)
                new_scores.append(score)
                break

    if len(new_boxes) == 0:
        return ObjectDetectionLabels.make_empty()

    return ObjectDetectionLabels(
        np.array(new_boxes), np.array(new_class_ids), np.array(new_scores)
    )