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

similar functions for from_tensor to_tensor from ragged api #20731

Closed
innat opened this issue Jan 6, 2025 · 6 comments · Fixed by #20757
Closed

similar functions for from_tensor to_tensor from ragged api #20731

innat opened this issue Jan 6, 2025 · 6 comments · Fixed by #20757
Assignees
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@innat
Copy link

innat commented Jan 6, 2025

I think ragged doesn't support yet. But is there any way to handle such following cases?

tf.RaggedTensor.from_tensor
tf.RaggedTensor.to_tensor
...

def __init__(self, **kwargs):
    super(RaggedToDenseTensor, self).__init__(**kwargs)

def call(self, inputs):
     if isinstance(inputs, tf.RaggedTensor):
         inputs = inputs.to_tensor()
    return inputs
@dhantule dhantule added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Jan 7, 2025
@dhantule
Copy link
Contributor

dhantule commented Jan 7, 2025

Hi @innat, thanks for reporting this.

There is partial support for ragged tensors in Keras 3. The from_tensor and to_tensor functionalities seem to work with Keras 3 in this gist, operations for which Tensorflow supports ragged should also work.

Please refer this issue #20073 for more clarity.

@innat
Copy link
Author

innat commented Jan 7, 2025

Is there any temp support for other backend (jax, torch)?

@innat
Copy link
Author

innat commented Jan 7, 2025

I have the following setup (written in keras 3), works in tensorflow backend. Now, I'm thinking how to extend it to support torch and jax.

class XYZ(Layer):
    def __init__(
        self, **kwargs
    ):
        super().__init__(**kwargs)
        ...

    def call(self, inputs):

        if isinstance(inputs, tf.RaggedTensor):
            inputs = inputs.to_tensor()
        
        batch_size = ops.shape(inputs)[0]
        clips_list = []

        ...
        ...
        return <...>

  
model = VideoSwinT(
    ...
)
umodel = keras.Sequential(
    [
        keras.layers.InputLayer(shape=(32, 224, 224, 3)),
        XYZ
        model
    ]
)

@dhantule dhantule added the keras-team-review-pending Pending review by a Keras team member. label Jan 8, 2025
@hertschuh hertschuh removed the keras-team-review-pending Pending review by a Keras team member. label Jan 12, 2025
hertschuh added a commit to hertschuh/keras that referenced this issue Jan 13, 2025
Added `ragged` option to `KerasTensor`, `InputLayer` and `convert_to_tensor`. The logic is the same as for sparse tensors.

Fixes keras-team#20731
hertschuh added a commit to hertschuh/keras that referenced this issue Jan 13, 2025
Added `ragged` option to `KerasTensor`, `InputLayer` and `convert_to_tensor`. The logic is the same as for sparse tensors.

Fixes keras-team#20731
hertschuh added a commit to hertschuh/keras that referenced this issue Jan 14, 2025
Added `ragged` option to `KerasTensor`, `InputLayer` and `convert_to_tensor`. The logic is the same as for sparse tensors.

Fixes keras-team#20731
hertschuh added a commit to hertschuh/keras that referenced this issue Jan 14, 2025
Added `ragged` option to `KerasTensor`, `InputLayer` and `convert_to_tensor`. The logic is the same as for sparse tensors.

Fixes keras-team#20731
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

1 similar comment
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@hertschuh
Copy link
Collaborator

@innat ,

The feature has been added, you can use it tomorrow if you install keras-nightly.

It works like this:

x = keras.ops.convert_to_tensor(x, ragged=False)

This will densify any ragged tensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants