@@ -433,7 +433,8 @@ def image(tag, tensor, rescale=1, dataformats="NCHW"):
433
433
channels]` where `channels` is 1, 3, or 4.
434
434
'tensor' can either have values in [0, 1] (float32) or [0, 255] (uint8).
435
435
The image() function will scale the image values to [0, 255] by applying
436
- a scale factor of either 1 (uint8) or 255 (float32).
436
+ a scale factor of either 1 (uint8) or 255 (float32). Out-of-range values
437
+ will be clipped.
437
438
Returns:
438
439
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
439
440
buffer.
@@ -443,7 +444,7 @@ def image(tag, tensor, rescale=1, dataformats="NCHW"):
443
444
# Do not assume that user passes in values in [0, 255], use data type to detect
444
445
scale_factor = _calc_scale_factor (tensor )
445
446
tensor = tensor .astype (np .float32 )
446
- tensor = (tensor * scale_factor ).astype (np .uint8 )
447
+ tensor = (tensor * scale_factor ).clip ( 0 , 255 ). astype (np .uint8 )
447
448
image = make_image (tensor , rescale = rescale )
448
449
return Summary (value = [Summary .Value (tag = tag , image = image )])
449
450
@@ -457,7 +458,7 @@ def image_boxes(
457
458
tensor_boxes = make_np (tensor_boxes )
458
459
tensor_image = tensor_image .astype (np .float32 ) * _calc_scale_factor (tensor_image )
459
460
image = make_image (
460
- tensor_image .astype (np .uint8 ), rescale = rescale , rois = tensor_boxes , labels = labels
461
+ tensor_image .clip ( 0 , 255 ). astype (np .uint8 ), rescale = rescale , rois = tensor_boxes , labels = labels
461
462
)
462
463
return Summary (value = [Summary .Value (tag = tag , image = image )])
463
464
@@ -513,7 +514,7 @@ def video(tag, tensor, fps=4):
513
514
# If user passes in uint8, then we don't need to rescale by 255
514
515
scale_factor = _calc_scale_factor (tensor )
515
516
tensor = tensor .astype (np .float32 )
516
- tensor = (tensor * scale_factor ).astype (np .uint8 )
517
+ tensor = (tensor * scale_factor ).clip ( 0 , 255 ). astype (np .uint8 )
517
518
video = make_video (tensor , fps )
518
519
return Summary (value = [Summary .Value (tag = tag , image = video )])
519
520
0 commit comments