MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / run_on_image

Method run_on_image

demo_d2/predictor.py:37–66  ·  view source on GitHub ↗

Args: image (np.ndarray): an image of shape (H, W, C) (in BGR order). This is the format used by OpenCV. Returns: predictions (dict): the output of the model. vis_output (VisImage): the visualized image output.

(self, image)

Source from the content-addressed store, hash-verified

35 self.predictor = DefaultPredictor(cfg)
36
37 def run_on_image(self, image):
38 """
39 Args:
40 image (np.ndarray): an image of shape (H, W, C) (in BGR order).
41 This is the format used by OpenCV.
42
43 Returns:
44 predictions (dict): the output of the model.
45 vis_output (VisImage): the visualized image output.
46 """
47 vis_output = None
48 predictions = self.predictor(image)
49 # Convert image from OpenCV BGR format to Matplotlib RGB format.
50 image = image[:, :, ::-1]
51 visualizer = Visualizer(image, self.metadata, instance_mode=self.instance_mode)
52 if "panoptic_seg" in predictions:
53 panoptic_seg, segments_info = predictions["panoptic_seg"]
54 vis_output = visualizer.draw_panoptic_seg_predictions(
55 panoptic_seg.to(self.cpu_device), segments_info
56 )
57 else:
58 if "sem_seg" in predictions:
59 vis_output = visualizer.draw_sem_seg(
60 predictions["sem_seg"].argmax(dim=0).to(self.cpu_device)
61 )
62 if "instances" in predictions:
63 instances = predictions["instances"].to(self.cpu_device)
64 vis_output = visualizer.draw_instance_predictions(predictions=instances)
65
66 return predictions, vis_output
67
68 def _frame_from_video(self, video):
69 while video.isOpened():

Callers 1

demo.pyFile · 0.45

Calls 5

draw_sem_segMethod · 0.95
VisualizerClass · 0.90
toMethod · 0.45

Tested by

no test coverage detected