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)
| 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 | |
| 203 | def get_benchmark_eligible_ops_info(): |
no test coverage detected