Last active
August 2, 2020 15:23
-
-
Save aakarsh7599/c4e65345b2c6ff911fa366f43115dcde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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