Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__array_interface__ support? #56723

Closed
radarhere opened this issue Jul 10, 2022 · 3 comments
Closed

__array_interface__ support? #56723

radarhere opened this issue Jul 10, 2022 · 3 comments
Assignees
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.9 Issues found in the TF 2.9 release (or RCs) type:feature Feature requests

Comments

@radarhere
Copy link

radarhere commented Jul 10, 2022

Click to expand!

Issue Type

Feature Request

Source

source

Tensorflow Version

2.6.0

Custom Code

No

OS Platform and Distribution

No response

Mobile device

No response

Python version

3.8

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

Hi. Over at https://github.com/python-pillow/Pillow, our Image class has the __array_interface__ attribute, to support converting Pillow images to NumPy. See https://numpy.org/doc/stable/reference/arrays.interface.html#object.__array_interface__

A recent discussion has revealed that TensorFlow's reshape method (and I have to imagine other methods as well) accepts an object that provides an __array__ method, but not an object with an __array_interface__ attribute.

My question - is there any interest from TensorFlow in supporting objects with __array_interface__?

Standalone code to reproduce the issue

Here is code that fails with the latest version of Pillow.

from PIL import Image
import tensorflow as tf

im = Image.new("L", (1, 1))
tf.reshape(im, (1, 1))

However, if my assertion that TensorFlow doesn't accept __array_interface__ is at all in doubt, let me know and I'll put together a better example.



### Relevant log output

_No response_</details>
@chunduriv
Copy link
Contributor

The issue is replicated in TF 2.9

from PIL import Image
import tensorflow as tf

im = Image.new("L", (1, 1))
tf.reshape(im, (1, 1))

Output:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-1-807613033b71>](https://localhost:8080/#) in <module>()
      3 
      4 im = Image.new("L", (1, 1))
----> 5 tf.reshape(im, (1, 1))

1 frames
[/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py](https://localhost:8080/#) in convert_to_eager_tensor(value, ctx, dtype)
    100       dtype = dtypes.as_dtype(dtype).as_datatype_enum
    101   ctx.ensure_initialized()
--> 102   return ops.EagerTensor(value, ctx.device_name, dtype)
    103 
    104 

ValueError: Attempt to convert a value (<PIL.Image.Image image mode=L size=1x1 at 0x7F4CA06B7090>) with an unsupported type (<class 'PIL.Image.Image'>) to a Tensor.


@chunduriv chunduriv added TF 2.9 Issues found in the TF 2.9 release (or RCs) stat:awaiting tensorflower Status - Awaiting response from tensorflower and removed 2.6.0 labels Jul 13, 2022
@radarhere
Copy link
Author

Thanks very much @cantonios!

@cantonios
Copy link
Contributor

@radarhere no problem. At Google we oddly have a patched version of Pillow that replaces __array_interface__ back with __array__, so we weren't reproducing this issue internally. Maybe this was why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.9 Issues found in the TF 2.9 release (or RCs) type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

4 participants