Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

apply_affine_transform calls tensor.ndim #336

Open
smedegaard opened this issue Jan 29, 2021 · 0 comments
Open

apply_affine_transform calls tensor.ndim #336

smedegaard opened this issue Jan 29, 2021 · 0 comments

Comments

@smedegaard
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant