MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / show_result_pyplot

Function show_result_pyplot

segmentation/tools/onnx2tensorrt.py:76–104  ·  view source on GitHub ↗
(img: Union[str, np.ndarray],
                       result: np.ndarray,
                       palette: Optional[Iterable] = None,
                       fig_size: Iterable[int] = (15, 10),
                       opacity: float = 0.5,
                       title: str = '',
                       block: bool = True)

Source from the content-addressed store, hash-verified

74
75
76def show_result_pyplot(img: Union[str, np.ndarray],
77 result: np.ndarray,
78 palette: Optional[Iterable] = None,
79 fig_size: Iterable[int] = (15, 10),
80 opacity: float = 0.5,
81 title: str = '',
82 block: bool = True):
83 img = mmcv.imread(img)
84 img = img.copy()
85 seg = result[0]
86 seg = mmcv.imresize(seg, img.shape[:2][::-1])
87 palette = np.array(palette)
88 assert palette.shape[1] == 3
89 assert len(palette.shape) == 2
90 assert 0 < opacity <= 1.0
91 color_seg = np.zeros((seg.shape[0], seg.shape[1], 3), dtype=np.uint8)
92 for label, color in enumerate(palette):
93 color_seg[seg == label, :] = color
94 # convert to BGR
95 color_seg = color_seg[..., ::-1]
96
97 img = img * (1 - opacity) + color_seg * opacity
98 img = img.astype(np.uint8)
99
100 plt.figure(figsize=fig_size)
101 plt.imshow(mmcv.bgr2rgb(img))
102 plt.title(title)
103 plt.tight_layout()
104 plt.show(block=block)
105
106
107def onnx2tensorrt(onnx_file: str,

Callers 2

onnx2tensorrtFunction · 0.85
pytorch2onnxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected