Reputation: 73
I am trying to merge certain classes on the coco dataset for evaluation. My goal is to merge the categories "cars", "trucks", "bus" to a new category "vehicles". But I do not want to train a new model. The following code outputs an evaluation of all 80 Coco categories.
from detectron2.evaluation import COCOEvaluator, inference_on_dataset
from detectron2.data import build_detection_test_loader
from detectron2.modeling import build_model
from detectron2.checkpoint import DetectionCheckpointer
model = build_model(cfg)
DetectionCheckpointer(model).load(weights_path)
evaluator = COCOEvaluator("testsetPre_val", cfg, False, output_dir="./output/")
val_loader = build_detection_test_loader(cfg, "testsetPre_val")
inference_on_dataset(model, val_loader, evaluator)
Any suggestions?
Upvotes: 0
Views: 1984
Reputation: 2342
Well, the simple solution to this is, let the model predict "cars", "buses" and "trucks". But edit the label to "vehicles" before drawing bounding boxes.
Before you draw a bounding box around the detected objects by passing it to "visutil" functions of TensorFlow, just have a simple if-else statement:
if label in ["car", "buses", "trucks"]:
label="vehicles"
This is the only way to do it if you dont want to retrain the model.
If you want to retrain the model however, change the tagging of "buses", "trucks" and "cars" to just "vehicles".
Upvotes: 2