Skip to content

Commit 60c3d34

Browse files
committed
CLN: simpler way to calcualte new_shape
1 parent 27de34d commit 60c3d34

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tensorflow_addons/image/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ def _dynamic_to_4D_image(image):
5555
# 2D image => [1, H, W, 1]
5656
left_pad = tf.cast(tf.less_equal(original_rank, 3), dtype=tf.int32)
5757
right_pad = tf.cast(tf.equal(original_rank, 2), dtype=tf.int32)
58-
new_shape = tf.squeeze(
59-
tf.pad(
60-
tf.expand_dims(shape, axis=0), [[0, 0], [left_pad, right_pad]],
61-
constant_values=1),
58+
# yapf: disable
59+
new_shape = tf.concat(
60+
[tf.ones(shape=left_pad, dtype=tf.int32),
61+
shape,
62+
tf.ones(shape=right_pad, dtype=tf.int32)],
6263
axis=0)
64+
# yapf: enable
6365
return tf.reshape(image, new_shape)
6466

6567

0 commit comments

Comments
 (0)