MCPcopy Create free account
hub / github.com/OpenGVLab/UniFormerV2 / add_ndim_array

Function add_ndim_array

slowfast/visualization/tensorboard_vis.py:335–408  ·  view source on GitHub ↗

Visualize and add tensors of n-dimentionals to a Tensorboard SummaryWriter. Tensors will be visualized as a 2D grid image. Args: writer (SummaryWriter): Tensorboard SummaryWriter. array (tensor): tensor to visualize. name (str): name of the tensor. nrow (

(
    writer,
    array,
    name,
    nrow=None,
    normalize=False,
    global_step=None,
    heat_map=True,
)

Source from the content-addressed store, hash-verified

333
334
335def add_ndim_array(
336 writer,
337 array,
338 name,
339 nrow=None,
340 normalize=False,
341 global_step=None,
342 heat_map=True,
343):
344 """
345 Visualize and add tensors of n-dimentionals to a Tensorboard SummaryWriter. Tensors
346 will be visualized as a 2D grid image.
347 Args:
348 writer (SummaryWriter): Tensorboard SummaryWriter.
349 array (tensor): tensor to visualize.
350 name (str): name of the tensor.
351 nrow (Optional[int]): number of 2D filters in each row in the grid image.
352 normalize (bool): whether to normalize when we have multiple 2D filters.
353 Default to False.
354 global_step (Optional[int]): current step.
355 heat_map (bool): whether to add heat map to 2D each 2D filters in array.
356 """
357 if array is not None and array.ndim != 0:
358 if array.ndim == 1:
359 reshaped_array = array.unsqueeze(0)
360 if nrow is None:
361 nrow = int(math.sqrt(reshaped_array.size()[1]))
362 reshaped_array = reshaped_array.view(-1, nrow)
363 if heat_map:
364 reshaped_array = add_heatmap(reshaped_array)
365 writer.add_image(
366 name,
367 reshaped_array,
368 global_step=global_step,
369 dataformats="CHW",
370 )
371 else:
372 writer.add_image(
373 name,
374 reshaped_array,
375 global_step=global_step,
376 dataformats="HW",
377 )
378 elif array.ndim == 2:
379 reshaped_array = array
380 if heat_map:
381 heatmap = add_heatmap(reshaped_array)
382 writer.add_image(
383 name, heatmap, global_step=global_step, dataformats="CHW"
384 )
385 else:
386 writer.add_image(
387 name,
388 reshaped_array,
389 global_step=global_step,
390 dataformats="HW",
391 )
392 else:

Callers 1

Calls 2

add_heatmapFunction · 0.85
add_imageMethod · 0.80

Tested by

no test coverage detected