MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / resize_images

Function resize_images

tensorflow/python/keras/backend.py:2658–2717  ·  view source on GitHub ↗

Resizes the images contained in a 4D tensor. Arguments: x: Tensor or variable to resize. height_factor: Positive integer. width_factor: Positive integer. data_format: One of `"channels_first"`, `"channels_last"`. interpolation: A string, one of `nearest` or `bilinear

(x, height_factor, width_factor, data_format,
                  interpolation='nearest')

Source from the content-addressed store, hash-verified

2656
2657@keras_export('keras.backend.resize_images')
2658def resize_images(x, height_factor, width_factor, data_format,
2659 interpolation='nearest'):
2660 """Resizes the images contained in a 4D tensor.
2661
2662 Arguments:
2663 x: Tensor or variable to resize.
2664 height_factor: Positive integer.
2665 width_factor: Positive integer.
2666 data_format: One of `"channels_first"`, `"channels_last"`.
2667 interpolation: A string, one of `nearest` or `bilinear`.
2668
2669 Returns:
2670 A tensor.
2671
2672 Raises:
2673 ValueError: in case of incorrect value for
2674 `data_format` or `interpolation`.
2675 """
2676 if data_format == 'channels_first':
2677 rows, cols = 2, 3
2678 elif data_format == 'channels_last':
2679 rows, cols = 1, 2
2680 else:
2681 raise ValueError('Invalid `data_format` argument: %s' % (data_format,))
2682
2683 original_shape = int_shape(x)
2684 new_shape = array_ops.shape(x)[rows:cols + 1]
2685 new_shape *= constant_op.constant(
2686 np.array([height_factor, width_factor], dtype='int32'))
2687
2688 if data_format == 'channels_first':
2689 x = permute_dimensions(x, [0, 2, 3, 1])
2690 if interpolation == 'nearest':
2691 x = image_ops.resize_images_v2(
2692 x, new_shape, method=image_ops.ResizeMethod.NEAREST_NEIGHBOR)
2693 elif interpolation == 'bilinear':
2694 x = image_ops.resize_images_v2(x, new_shape,
2695 method=image_ops.ResizeMethod.BILINEAR)
2696 else:
2697 raise ValueError('interpolation should be one '
2698 'of "nearest" or "bilinear".')
2699 if data_format == 'channels_first':
2700 x = permute_dimensions(x, [0, 3, 1, 2])
2701
2702 if original_shape[rows] is None:
2703 new_height = None
2704 else:
2705 new_height = original_shape[rows] * height_factor
2706
2707 if original_shape[cols] is None:
2708 new_width = None
2709 else:
2710 new_width = original_shape[cols] * width_factor
2711
2712 if data_format == 'channels_first':
2713 output_shape = (None, None, new_height, new_width)
2714 else:
2715 output_shape = (None, new_height, new_width, None)

Callers

nothing calls this directly

Calls 5

int_shapeFunction · 0.85
permute_dimensionsFunction · 0.85
shapeMethod · 0.45
constantMethod · 0.45
set_shapeMethod · 0.45

Tested by

no test coverage detected