new_shorter_edge = 400
height_smaller_than_width = tf.less_equal(height, width)
new_shorter_edge = tf.constant(400)
new_height, new_width = tf.cond(height_smaller_than_width, lambda :
    new_shorter_edge, width / height * new_shorter_edge, lambda :
    new_shorter_edge, height / width * new_shorter_edge)
TensorFlow Resize image tensor to dynamic shape