Created
April 9, 2021 05:49
-
-
Save trongan93/bf3df496108804109e8f7e76dce243fb 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 | |
json_file_test = "/mnt/d/RarePlanes/datasets/synthetic/metadata_annotations/instances_test_aircraft.json" | |
coco_test=COCO(json_file_test) | |
catIds = coco_test.getCatIds(catNms=['aircraft']); | |
imgIds = coco_test.getImgIds(catIds=catIds); | |
img = coco_test.loadImgs(imgIds[np.random.randint(0,len(imgIds))])[0] | |
im = cv2.imread("/mnt/d/RarePlanes/datasets/synthetic/test/images/" + img['file_name']) | |
plt.axis('off') | |
# plt.imshow(im) | |
# plt.show() | |
plt.imsave('input.png',im) | |
outputs = predictor(im) # format is documented at https://detectron2.readthedocs.io/tutorials/models.html#model-output-format | |
v = Visualizer(im[:, :, ::-1], | |
metadata=MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), | |
scale=0.5, | |
instance_mode=ColorMode.IMAGE_BW # remove the colors of unsegmented pixels. This option is only available for segmentation models | |
) | |
out = v.draw_instance_predictions(outputs["instances"].to("cpu")) | |
# plt.imshow(out.get_image()[:, :, ::-1]) | |
# plt.show() | |
plt.imsave('out_put.png',out.get_image()[:, :, ::-1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment