<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def resize(x, mode, factor=4):
 """Resize input tensor with unkown input-shape by a factor Args: x (tf.Tensor):
 tensor NCHW factor (int, optional):
 resize factor for H, W Note: Differences here against Caffe have huge impacts on the quality of the predictions. Returns: tf.Tensor: resized tensor NCHW """

    assert mode in ['bilinear', 'nearest'], mode
    shp = tf.shape(x)[2:] * factor
    # NCHW -> NHWC
    x = tf.transpose(x, [0, 2, 3, 1])
    if mode == 'bilinear':
        x = tf.image.resize_bilinear(x, shp, align_corners=True)
    else:
        # better approximation of what Caffe is doing
        x = tf.image.resize_nearest_neighbor(x, shp, align_corners=False)
    # NHWC -> NCHW
    return tf.transpose(x, [0, 3, 1, 2])