keras-team/keras-preprocessing

apply_affine_transform calls tensor.ndim

smedegaard opened this issue · 0 comments

I tried to apply random rotation on a tiff with shape (120,120,4) with the following function:

def augment_image(image, label):
    image = tf.keras.preprocessing.image.random_rotation(
        image,
        180, 
        row_axis=0,
        col_axis=1,
        channel_axis=2
    )
    image = tf.image.flip_left_right(image)
    image = tf.image.random_flip_up_down(image)
    
    return image, label

resulting in

AttributeError: in user code:

/home/jupyter/sentinel2model/trainer/util.py:37 augment_image  *
    image = tf.keras.preprocessing.image.random_rotation(
/opt/conda/lib/python3.7/site-packages/keras_preprocessing/image/affine_transformations.py:56 random_rotation  *
    x = apply_affine_transform(x, theta=theta, channel_axis=channel_axis,
/opt/conda/lib/python3.7/site-packages/keras_preprocessing/image/affine_transformations.py:323 apply_affine_transform  *
    x = np.rollaxis(x, channel_axis, 0)
<__array_function__ internals>:6 rollaxis  **
    
/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py:1259 rollaxis
    n = a.ndim

AttributeError: 'Tensor' object has no attribute 'ndim' 

As far as I can see apply_affine_transform() does not convert the tf.Tensor to a np.Array and thus lacks the ndim attribute.

I'm I misunderstanding something?

Kind regards,
Anders