Hi @ptrblck, just to let you know.
Detectron2 has a VideoVisualizer class that takes in all the logic of doing object detection in a video. In there that’s where the metadata like labels is included.
There is also a demo.py that has the template for the terminal inputs.
I have tried using these two files to make edits to my video inferencing, but it hasn’t worked. I went into the demo.py and added a new parser-argument called --vid_meta
that accepts the train metadata.
def get_parser():
parser.add_argument(
"--vid_meta",
default=['Crop', 'Weed'],
help='Adding Video metadata'
)
And further down, I fed that argument into the VideoVisualizer
class as metadata
if args.vid_meta:
VideoVisualizer(metadata=args.vid_meta)
I have also made some changes to labels in the VideoVisualizer so that it can access the labels from the train metadata. I changed the labels in the function;
draw_instance_predictions()
in the VideoVisualizer
class;
from;
labels = _create_text_labels(classes, scores, self.metadata."thing_classes", None)
to;
labels = _create_text_labels(classes, scores, self.metadata.things_classes)
After making those edits in both VideoVisualizer
and demo.py
, I re-ran the video detection command as;
%run /content/demo.py --config-file /content/drive/MyDrive/Real-Time-Object-Detection/Detectron2-models/config4.yaml \
--video-input /content/crop-weed.mp4 --confidence-threshold 0.6 --output output_colab6.mp4 --vid_meta train_metadata \
--opts MODEL.WEIGHTS /content/output/model_final.pth
whereby train_metadata is equivalent to;
namespace(name='my_dataset_train',
json_file='/content/Annotated-Images-Dataset-1/train/_annotations.coco.json',
image_root='/content/Annotated-Images-Dataset-1/train',
evaluator_type='coco',
thing_classes=['weed-crops', 'crop', 'weed'],
thing_dataset_id_to_contiguous_id={0: 0, 1: 1, 2: 2})
And then when I rerun it and downloaded the video, unfortunately it still doesn’t work
But I’m very confident the solution is in configuring the VideoVisualizer
class. I hope to get your help on this please.