Detectron2: How to save metadata ?

Created on 15 Mar 2020  路  2Comments  路  Source: facebookresearch/detectron2

I'm using my model like this:

Step 1: Loading weights

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 
cfg.MODEL.WEIGHTS = "data/my_model_final.pth"
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 42
predictor = DefaultPredictor(cfg)
outputs = predictor(im)

Step 2: Get metadata

from detectron2.data.datasets import register_coco_instances
register_coco_instances("my_dataset", {}, "data/drive/train_coco/annotations.json", "data/drive/train_coco")
my_metadata = MetadataCatalog.get("my_dataset")

Step 3: Predict

from detectron2.utils.visualizer import ColorMode
v = Visualizer(im[:, :, ::-1], metadata=my_metadata, scale=1.2, instance_mode=ColorMode.IMAGE_BW)
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
plt.imshow(v.get_image())
plt.show()

But in step 2, I have to register the entire dataset only to get the metadata. Is there anyway I can save metadata after training similar to saving 'model.pth'

Thank you

Most helpful comment

For anyone having same problems, I have found a way to specify metadata without registering dataset:

from detectron2.data.catalog import Metadata

my_metadata = Metadata()
my_metadata.set(thing_classes = ['dog', 'cat'])

All 2 comments

You can specify the metadata without registering the dataset, see https://detectron2.readthedocs.io/tutorials/datasets.html#metadata-for-datasets

For anyone having same problems, I have found a way to specify metadata without registering dataset:

from detectron2.data.catalog import Metadata

my_metadata = Metadata()
my_metadata.set(thing_classes = ['dog', 'cat'])
Was this page helpful?
0 / 5 - 0 ratings

Related issues

aminekechaou picture aminekechaou  路  3Comments

marcoippolito picture marcoippolito  路  4Comments

DeepLakhani99 picture DeepLakhani99  路  4Comments

limsijie93 picture limsijie93  路  3Comments

danielgordon10 picture danielgordon10  路  3Comments