Dump or visualize images of a :class:`DataFlow`. Args: df (DataFlow): the DataFlow. index (int): the index of the image component. batched (bool): whether the component contains batched images (NHW or NHWC) or not (HW or HWC). number (int): how m
(df, index=0, batched=True,
number=1000, output_dir=None,
scale=1, resize=None, viz=None,
flipRGB=False)
| 263 | |
| 264 | |
| 265 | def dump_dataflow_images(df, index=0, batched=True, |
| 266 | number=1000, output_dir=None, |
| 267 | scale=1, resize=None, viz=None, |
| 268 | flipRGB=False): |
| 269 | """ |
| 270 | Dump or visualize images of a :class:`DataFlow`. |
| 271 | |
| 272 | Args: |
| 273 | df (DataFlow): the DataFlow. |
| 274 | index (int): the index of the image component. |
| 275 | batched (bool): whether the component contains batched images (NHW or |
| 276 | NHWC) or not (HW or HWC). |
| 277 | number (int): how many datapoint to take from the DataFlow. |
| 278 | output_dir (str): output directory to save images, default to not save. |
| 279 | scale (float): scale the value, usually either 1 or 255. |
| 280 | resize (tuple or None): tuple of (h, w) to resize the images to. |
| 281 | viz (tuple or None): tuple of (h, w) determining the grid size to use |
| 282 | with :func:`gen_stack_patches` for visualization. No visualization will happen by |
| 283 | default. |
| 284 | flipRGB (bool): apply a RGB<->BGR conversion or not. |
| 285 | """ |
| 286 | if output_dir: |
| 287 | mkdir_p(output_dir) |
| 288 | if viz is not None: |
| 289 | viz = shape2d(viz) |
| 290 | vizsize = viz[0] * viz[1] |
| 291 | if resize is not None: |
| 292 | resize = tuple(shape2d(resize)) |
| 293 | vizlist = [] |
| 294 | |
| 295 | df.reset_state() |
| 296 | cnt = 0 |
| 297 | while True: |
| 298 | for dp in df: |
| 299 | if not batched: |
| 300 | imgbatch = [dp[index]] |
| 301 | else: |
| 302 | imgbatch = dp[index] |
| 303 | for img in imgbatch: |
| 304 | cnt += 1 |
| 305 | if cnt == number: |
| 306 | return |
| 307 | if scale != 1: |
| 308 | img = img * scale |
| 309 | if resize is not None: |
| 310 | img = cv2.resize(img, resize) |
| 311 | if flipRGB: |
| 312 | img = img[:, :, ::-1] |
| 313 | if output_dir: |
| 314 | fname = os.path.join(output_dir, '{:03d}.jpg'.format(cnt)) |
| 315 | cv2.imwrite(fname, img) |
| 316 | if viz is not None: |
| 317 | vizlist.append(img) |
| 318 | if viz is not None and len(vizlist) >= vizsize: |
| 319 | stack_patches( |
| 320 | vizlist[:vizsize], |
| 321 | nr_row=viz[0], nr_col=viz[1], viz=True) |
| 322 | vizlist = vizlist[vizsize:] |
nothing calls this directly
no test coverage detected