facebookresearch / facebookresearch/detectron2
How to evaluate only one class from the pre trained model LVISv0.5-InstanceSegmentation
- Dominant language
- Python
- Stars
- 34.7k
- Forks
- 7.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I want to use the specific class (plastic bag) for getting the inference without training the model. I have the annotated dataset and want to evaluate the pre-trained model available in Detectron2. I can evaluate my model trained on a custom dataset but just wanted to know how to incorporate it for the pre-built model.
My code for training the model is as below. I just want to evaluate the pre-trained model on my custom dataset containing a specific class and ignore all other classes in the pre-trained model for evaluation (here in my dataset: evaluate for only 'plastic bag' which is present in LVIS as well)
In the code, I have registered the 'train' and 'val' datasets before running the cell.
```
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
from detectron2.evaluation import COCOEvaluator, inference_on_dataset
from detectron2.data import build_detection_test_loader
import os
cfg = get_cfg()
cfg.merge_from_file("./detectron2_repo/configs/LVISv0.5-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x.yaml")
cfg.DATASETS.TRAIN = ("train",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 4
cfg.MODEL.WEIGHTS = "detectron2://LVISv0.5-InstanceSegmentation/mask_rcnn_X_101_32x8d_FPN_1x/144219108/model_final_5e3439.pkl"
cfg.SOLVER.IMS_PER_BATCH = 4
cfg.SOLVER.BASE_LR = 0.02
cfg.SOLVER.MAX_ITER = 30000
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.DATASETS.TEST = ( )
predictor = DefaultPredictor(cfg)
evaluator = COCOEvaluator("val", output_dir= "./output")
val_loader = build_detection_test_loader(cfg, "val")
print(inference_on_dataset(predictor.model, val_loader, evaluator))
```
Contributor guide
Assessment
This issue has not been assessed yet.