Cannot initialise YAMNet using TF 2.16.1
hzhongresearch opened this issue · 4 comments
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [✔ ] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
- [✔ ] I am reporting the issue to the correct repository. (Model Garden official or research directory)
- [✔ ] I checked to make sure that this issue has not already been filed.
1. The entire URL of the file you are using
https://github.com/tensorflow/models/blob/8da4857396fcedb1abd19a08cd4de40d16c7bc50/research/audioset/yamnet/yamnet.py
https://github.com/tensorflow/models/blob/8da4857396fcedb1abd19a08cd4de40d16c7bc50/research/audioset/yamnet/params.py
2. Describe the bug
@plakal @dpwe
Cannot initialise YAMNet using TF 2.16.1.
3. Steps to reproduce
Steps to reproduce the behavior.
import yamnet
import params
mymodel = yamnet.yamnet_frames_model(params=params.Params)
4. Expected behavior
A clear and concise description of what you expected to happen.
The code should return a YAMNet model.
5. Additional context
Include any logs that would be helpful to diagnose the problem.
The following is the error message.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/henry/models/research/audioset/yamnet/yamnet.py", line 121, in yamnet_frames_model
waveform_padded = features_lib.pad_waveform(waveform, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/henry/models/research/audioset/yamnet/features.py", line 91, in pad_waveform
num_samples = tf.shape(waveform)[0]
^^^^^^^^^^^^^^^^^^
File "/home/henry/env_yamnet/lib/python3.11/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/henry/env_yamnet/lib/python3.11/site-packages/keras/src/backend/common/keras_tensor.py", line 91, in __tf_tensor__
raise ValueError(
ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like:
x = Input(...)
...
tf_fn(x) # Invalid.
What you should do instead is wrap `tf_fn` in a layer:
class MyLayer(Layer):
def call(self, x):
return tf_fn(x)
x = MyLayer()(x)
6. System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Debian 12 on WSL2
- TensorFlow installed from (source or binary): binary
- TensorFlow version (use command below): 2.16.1
- Python version: 3.11.2
Same issue here using tensorflow-cpu 2.17.0. Works using tensorflow 2.11, but had to downgrade to python 3.7
Sorry for the late response. Neither me nor @dpwe were assigned this issue so we didn't notice until now. Looking into this.
TF 2.16.0 included an upgrade to Keras 3 by default, which includes many breaking changes. I've confirmed that our code still works if we stick with Keras 2 (which requires also installing tf_keras). I'll send a PR to switch us to Keras 2.