MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / visualize

Method visualize

bench/python/bench_utils.py:169–200  ·  view source on GitHub ↗

Attempts to visualize the output produced by the operator as an image by writing it down to the disk. May raise exceptions if visualization is not successful.

(self)

Source from the content-addressed store, hash-verified

167 return output_dir
168
169 def visualize(self):
170 """
171 Attempts to visualize the output produced by the operator as an image by writing it
172 down to the disk. May raise exceptions if visualization is not successful.
173 """
174 output_dir = self._setup_clear_output_dir(filename_ends_with="_op_out.jpg")
175 if self.op_output is None:
176 raise TypeError(
177 "Visualization Error: Operator did not return any value as output to visualize."
178 )
179
180 op_output_npy = (
181 torch.as_tensor(self.op_output.cuda(), device="cuda:%d" % self.device_id)
182 .cpu()
183 .numpy()
184 )
185 if op_output_npy.dtype == np.uint8:
186 for i, npy_img in enumerate(op_output_npy):
187 if npy_img.shape[-1] == 1:
188 # Need to drop the 1 from the channels dimension if dealing with
189 # grayscale in PIL
190 npy_img = npy_img[..., 0]
191 out_file_name = "img_%d_op_out.jpg" % i
192 # Visualize as image
193 pil_img = Image.fromarray(npy_img)
194 pil_img.save(os.path.join(output_dir, out_file_name))
195
196 else:
197 raise TypeError(
198 "Visualization Error: Unsupported dtype for visualization: %s"
199 % str(op_output_npy.dtype)
200 )
201
202
203def get_benchmark_eligible_ops_info():

Callers 1

__call__Method · 0.95

Calls 4

cpuMethod · 0.80
cudaMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected