Addons: tfa.image.rotate crashing jupyter notebook kernel

Created on 13 May 2019  路  10Comments  路  Source: tensorflow/addons

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • TensorFlow installed from (source or binary): Binary
  • TensorFlow version (use command below): tf-nightly-gpu-2.0-preview
  • TensorFlow Addons installed from (source, PyPi): source
  • TensorFlow Addons version: 0.3.0a
  • Python version and type (eg. Anaconda Python, Stock Python as in Mac, or homebrew installed Python etc): Anaconda Python Linux
  • Bazel version (if compiling from source): 0.25.2
  • GCC/Compiler version (if compiling from source): not sure
  • Is GPU used? (yes/no): yes
  • GPU model (if used): Nvidia Titan X (Pascal)

Describe the bug

I'm trying to use tfa.image.rotate with tf.data for training time data augmentations, but it is crashing my kernel when used.

Describe the expected behavior

rotate the tensor image

Code to reproduce the issue

```sample code
from random import randint
import matplotlib.pyplot as plt

def preprocess_image(image):
# decode PNG
image = tf.image.decode_image(image, channels=3)

# data augmentation
# rotate random
angle = random.randint(-1,1)
image = tfa.image.rotate(image,angle) #,interpolation='BILINEAR')

# resize
image = tf.image.resize(image, [224, 224])

# normalize = convert to [-1:1]    
offset = 127.5
image = (image-offset)/offset
return image

def load_and_preprocess_image(path):
image = tf.io.read_file(path)
return preprocess_image(image)

# load image and return a transformed and normalized image
img_tensor = load_and_preprocess_image(all_image_paths[1])
plt.imshow(img_tensor)
```

Other info / logs

The kernel doesn't log any errors, just crashes. If I remove the tf.image.resize from the code, it works fine. Also, the source code says to use scalar angles (I wasn't sure if these are radian or degrees). Is there any documentations on how to use the tfa.image functions?

bug image

All 10 comments

Hi @alew3 ! Sorry about this we have a mismatch between our released package on pypi and the tf2-nightly. Could you try running against tensorflow==2.0.0.a0 ?

If you want to run addons against tf2-nightly you'll need to compile from source. See https://github.com/tensorflow/addons/issues/193

This should go away very soon once we get a TF2 release candidate.

Also, will work on getting some examples up for tfa image

@seanpmorgan , I'm using the compiled version from sources.

Also, will work on getting some examples up for tfa image

That would be awesome, I'm especially interested in Rotate / Warping / Zoom / Crop. I'm not an expert in using matrix transforms, so some samples would be very much appreciated! Or in the future, if some helper functions could be created.

Ah, I see. Thanks. I created a quick example using TF2-alpha and it looks like it's working correctly:
https://colab.research.google.com/drive/1ZDhnGrorvSf04wzS-0utztZ6Nnzusvl7

I will test out whats going on with the nightly later. Kernel crashing though usually means a mismatch in ABI or something along those lines, so my first guess would be to edit https://github.com/tensorflow/addons/blob/master/tensorflow_addons/addons_bazel_macros.bzl

so the flag is 1 before building the package. This should be fixed with #240

Ah, I see. Thanks. I created a quick example using TF2-alpha and it looks like it's working correctly:
https://colab.research.google.com/drive/1ZDhnGrorvSf04wzS-0utztZ6Nnzusvl7

I will test out whats going on with the nightly later. Kernel crashing though usually means a mismatch in ABI or something along those lines, so my first guess would be to edit https://github.com/tensorflow/addons/blob/master/tensorflow_addons/addons_bazel_macros.bzl

so the flag is 1 before building the package. This should be fixed with #240

wow! thanks for your help! Already switched back here to alpha and can confirm it works with tensorflow-gpu alpha.

The example above is working fine with the alpha tensorflow, but when I try to use it dynamically with a map function for tf.data.Dataset I get the error: "TypeError: image_or_images rank must be statically known"

the following was added to the example above
path_ds = tf.data.Dataset.from_tensor_slices(all_image_paths) # list of images
image_ds = path_ds.map(load_and_preprocess_image ,num_parallel_calls = AUTOTUNE)

I tested compiled against nightly and it seems its working okay. For now could you use TF2-alpha + PyPi or change that ABI flag otherwise.

I've created a new issue for the dataset issue... thanks for pointing that out! Please continue to submit issues as you see them.

@seanpmorgan tested this with your colab notebook without downloading the alpha , just using the 2.2 default with colab now ... still causes the session to crash with the infamous "Your session crashed for an unknown reason."

EDIT:
After googling for more info I found out it's the Seg-fault you worked on in other issues.
For anyone who lands here the fix for me was:
pip install tfa-nightly
As per Colab issue 1229

@seanpmorgan tested this with your colab notebook without downloading the alpha , just using the 2.2 default with colab now ... still causes the session to crash with the infamous "Your session crashed for an unknown reason."

EDIT:
After googling for more info I found out it's the Seg-fault you worked on in other issues.
For anyone who lands here the fix for me was:
pip install tfa-nightly
As per Colab issue 1229

Yes thanks @mjsML ! I've made an issue on Colab to see if they can upgrade the package:
https://github.com/googlecolab/colabtools/issues/1243

Was this page helpful?
0 / 5 - 0 ratings