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

Cannot initialise YAMNet using TF 2.16.1 #11212

Closed
hzhongresearch opened this issue May 23, 2024 · 4 comments · Fixed by #11261
Closed

Cannot initialise YAMNet using TF 2.16.1 #11212

hzhongresearch opened this issue May 23, 2024 · 4 comments · Fixed by #11261
Assignees
Labels
models:research models that come under research directory type:bug Bug in the code

Comments

@hzhongresearch
Copy link

hzhongresearch commented May 23, 2024

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
@hzhongresearch hzhongresearch added models:research models that come under research directory type:bug Bug in the code labels May 23, 2024
@russnes
Copy link

russnes commented Sep 23, 2024

Same issue here using tensorflow-cpu 2.17.0. Works using tensorflow 2.11, but had to downgrade to python 3.7

@plakal plakal assigned dpwe and plakal and unassigned laxmareddyp Sep 23, 2024
@plakal
Copy link
Collaborator

plakal commented Sep 23, 2024

Sorry for the late response. Neither me nor @dpwe were assigned this issue so we didn't notice until now. Looking into this.

@plakal
Copy link
Collaborator

plakal commented Sep 23, 2024

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.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
models:research models that come under research directory type:bug Bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants