Skip to content

Instantly share code, notes, and snippets.

@aakarsh7599
Last active August 2, 2020 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakarsh7599/c4e65345b2c6ff911fa366f43115dcde to your computer and use it in GitHub Desktop.
Save aakarsh7599/c4e65345b2c6ff911fa366f43115dcde to your computer and use it in GitHub Desktop.
from detectron2.utils.visualizer import ColorMode
#Use the final weights generated after successful training for inference
cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.8 # set the testing threshold for this model
#Pass the validation dataset
cfg.DATASETS.TEST = ("boardetect_val", )
predictor = DefaultPredictor(cfg)
dataset_dicts = get_board_dicts("Text_Detection_Dataset_COCO_Format/val")
for d in random.sample(dataset_dicts, 3):
im = cv2.imread(d["file_name"])
outputs = predictor(im)
v = Visualizer(im[:, :, ::-1],
metadata=board_metadata,
scale=0.8,
instance_mode=ColorMode.IMAGE
)
v = v.draw_instance_predictions(outputs["instances"].to("cpu")) #Passing the predictions to CPU from the GPU
cv2_imshow(v.get_image()[:, :, ::-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment