-
Notifications
You must be signed in to change notification settings - Fork 278
Convert TF and Numpy ops in whisper_audio_convert.py to Keras Ops #2225
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
base: master
Are you sure you want to change the base?
Convert TF and Numpy ops in whisper_audio_convert.py to Keras Ops #2225
Conversation
outputs = WhisperAudioConverter(**self.init_kwargs)(audio_tensor) | ||
|
||
# Verify shape. | ||
self.assertEqual(outputs.shape, (5, 80)) | ||
# Verify output. | ||
expected = [1.1656, 1.0151, -0.8343, -0.8343, -0.8343] | ||
self.assertAllClose(outputs[:, 0], expected, atol=0.01, rtol=0.01) | ||
self.assertAllClose(outputs[:, 0], expected, atol=0.01, rtol=0.01) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep newlines at end of files.
|
||
# Convert the tensor to a Ragged Tensor. | ||
if isinstance(audio, tf.Tensor): | ||
audio = tf.RaggedTensor.from_tensor(audio) | ||
|
||
# Pad audio. | ||
audio_shape = audio.shape.as_list() | ||
audio_shape = list(audio.shape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe tf.shape cannot always be listified like this. Maybe call ops.shape
?
@abheesht17 if you have time can you review this? You probably have the most insight here. |
@@ -1,14 +1,10 @@ | |||
import numpy as np | |||
import keras.ops as ops | |||
import tensorflow as tf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can never do a bare import of tf like this. Check other files in the library.
@@ -214,21 +219,21 @@ def call(self, audio): | |||
|
|||
rank_1_input = audio.shape.rank == 1 | |||
if rank_1_input: | |||
audio = tf.expand_dims(audio, 0) | |||
audio = ops.expand_dims(audio, 0) | |||
|
|||
# Convert the tensor to a Ragged Tensor. | |||
if isinstance(audio, tf.Tensor): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably switch to a @preprocessing_function
annotation and remove this? Something to try at least.
This PR is in continuation to the draft PR .
Converted Numpy and TF ops into Keras ops in whisper_audio_converter.py and in whisper_audio_converter_test.py