microsoft / scene_graph_benchmark

image scene graph generation benchmark
MIT License
382 stars 86 forks source link

KeyError: 'box_features' --- extracting features from own image tsv files #39

Open sangwoo0123 opened 3 years ago

sangwoo0123 commented 3 years ago

Hi - I am getting a KeyError box features message when trying to extract features from my own image. I've played around with the code, but can't seem to figure it out. If I set the TEST.OUTPUT_FEATURE to False, then the code runs fine, but just outputting the detected objects. Can someone please help out?

For reference, the demo extraction on single image works fine - both object detection and box features.

Traceback (most recent call last): File "tools/test_sg_net.py", line 197, in main() File "tools/test_sg_net.py", line 193, in main run_test(cfg, model, args.distributed, model_name) File "tools/test_sg_net.py", line 72, in run_test save_predictions=cfg.TEST.SAVE_PREDICTIONS, File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 297, in inference relation_on=cfg.MODEL.RELATION_ON, File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 211, in convert_predictions_to_tsv tsv_writer(gen_rows(), os.path.join(output_folder, output_tsv_name)) File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/structures/tsv_file_ops.py", line 42, in tsv_writer for value in values: File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 139, in gen_rows features = prediction.get_field('box_features').numpy() File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 43, in get_field return self.extra_fields[field] KeyError: 'box_features'

cwkeam commented 2 years ago

Same problem. Even with TEST.OUTPUT_FEATURE set to True in the yaml file and in the script call, we have:


prediction: BoxList(num_boxes=28, image_width=640, image_height=480, mode=xyxy)
prediction.fields() == ['labels', 'scores', 'attr_labels', 'attr_scores']
cwkeam commented 2 years ago

Oh wow I've found the solution:

This inference code has a cacehing logic, where if you ran the model pass in the past with OUTPUT_FEATURES not set to True and have the saved .tmp outputs in your output directory, these will be the outputs that will be loaded the next time you call the inference code, even if you've changed it to OUTPUT_FEATURES=True.

So what I recommend is deleting the ./output folder and run again with OUTPUT_FEATURES=True then it should work.

via815via commented 2 years ago

Hi - I am getting a KeyError box features message when trying to extract features from my own image. I've played around with the code, but can't seem to figure it out. If I set the TEST.OUTPUT_FEATURE to False, then the code runs fine, but just outputting the detected objects. Can someone please help out?

For reference, the demo extraction on single image works fine - both object detection and box features.

Traceback (most recent call last): File "tools/test_sg_net.py", line 197, in main() File "tools/test_sg_net.py", line 193, in main run_test(cfg, model, args.distributed, model_name) File "tools/test_sg_net.py", line 72, in run_test save_predictions=cfg.TEST.SAVE_PREDICTIONS, File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 297, in inference relation_on=cfg.MODEL.RELATION_ON, File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 211, in convert_predictions_to_tsv tsv_writer(gen_rows(), os.path.join(output_folder, output_tsv_name)) File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/structures/tsv_file_ops.py", line 42, in tsv_writer for value in values: File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/engine/inference.py", line 139, in gen_rows features = prediction.get_field('box_features').numpy() File "/content/drive/MyDrive/scene_graph_benchmark/maskrcnn_benchmark/structures/bounding_box.py", line 43, in get_field return self.extra_fields[field] KeyError: 'box_features'

How do you extract features from your own image? I have some problems with this? Can you tell me? Thank you very much!