def image(tag, tensor, rescale=1, dataformats="CHW"): """Outputs a `Summary` protocol buffer with images. The summary has up to `max_images` summary values containing images. The images are built from `tensor` which must be 3-D with shape `[height, width, channels]` and where `channels` can be: * 1: `tensor` is interpreted as Grayscale. * 3: `tensor` is interpreted as RGB. * 4: `tensor` is interpreted as RGBA. Args: tag: A name for the generated node. Will also serve as a series name in TensorBoard. tensor: A 3-D `uint8` or `float32` `Tensor` of shape `[height, width, channels]` where `channels` is 1, 3, or 4. 'tensor' can either have values in [0, 1] (float32) or [0, 255] (uint8). The image() function will scale the image values to [0, 255] by applying a scale factor of either 1 (uint8) or 255 (float32). Returns: A scalar `Tensor` of type `string`. The serialized `Summary` protocol buffer. """ tag = tbxsummary._clean_tag(tag) tensor = tbxmake_np(tensor) tensor = convert_to_HWC(tensor, dataformats) # Do not assume that user passes in values in [0, 255], use data type to detect if tensor.dtype != np.uint8: tensor = (tensor * 255.0).astype(np.uint8) image = tbxsummary.make_image(tensor, rescale=rescale) return TBXSummary(value=[TBXSummary.Value(tag=tag, image=image)])
def tensor_to_video(tensor, fps=4): tensor = tbxmake_np(tensor) tensor = tbx_prepare_video(tensor) # If user passes in uint8, then we don't need to rescale by 255 if tensor.dtype != np.uint8: tensor = (tensor * 255.0).astype(np.uint8) return tbxsummary.make_video(tensor, fps)
def tensor_to_clip(tensor, fps=4): tensor = tbxmake_np(tensor) tensor = tbx_prepare_video(tensor) # If user passes in uint8, then we don't need to rescale by 255 if tensor.dtype != np.uint8: tensor = (tensor * 255.0).astype(np.uint8) t, h, w, c = tensor.shape clip = mpy.ImageSequenceClip(list(tensor), fps=fps) return clip, (h, w, c)