-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cris
committed
Apr 1, 2021
1 parent
706720e
commit d92a5eb
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import torch | ||
import cv2 | ||
|
||
# import some common detectron2 utilities | ||
from detectron2 import model_zoo | ||
from detectron2.engine import DefaultPredictor | ||
from detectron2.config import get_cfg | ||
from detectron2.utils.visualizer import Visualizer | ||
from detectron2.data import MetadataCatalog, DatasetCatalog | ||
|
||
if __name__ == '__main__': | ||
print(torch.__version__, torch.cuda.is_available()) | ||
|
||
video = cv2.VideoCapture("resources/Short4Mosaicing.mp4") | ||
|
||
while video.isOpened(): | ||
ok, frame = video.read() | ||
if ok: | ||
frame = frame[320:, :] | ||
|
||
# Inference with a keypoint detection model | ||
cfg = get_cfg() # get a fresh new config | ||
cfg.merge_from_file(model_zoo.get_config_file("COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml")) | ||
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7 # set threshold for this model | ||
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Keypoints/keypoint_rcnn_R_50_FPN_3x.yaml") | ||
predictor = DefaultPredictor(cfg) | ||
outputs = predictor(frame) | ||
v = Visualizer(frame[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2) | ||
out = v.draw_instance_predictions(outputs["instances"].to("cpu")) | ||
cv2.imshow("image", out.get_image()[:, :, ::-1]) | ||
|
||
k = cv2.waitKey(5) & 0xff | ||
if k == 27: break |