Keras vggish

827 views
Skip to first unread message

Antoine Mercier

unread,
Sep 21, 2017, 3:46:49 PM9/21/17
to audioset-users
Hello @plakal and @dpwe,
I have converted the vggish model and its weights into a Keras model.
It passes the smoke test.
Are you interested in the code ?

Regards,

Antoine.

Manoj Plakal

unread,
Sep 21, 2017, 4:03:12 PM9/21/17
to Antoine Mercier, audioset-users

Antoine,

That's awesome! Thank you for doing this.

Yes, we would love to have the Keras version of VGGish. Can you make a pull request with the code, and put the checkpoint file somewhere publicly accessible?

Before you do that, you might want to wait until this PR lands, https://github.com/tensorflow/models/pull/2430, because it moves our model into 'research' subdirectory of tensorflow/models, and then build your change on top of that, and then submit a PR.

In the meantime, do you have the code in Github or elsewhere for us to take a look?

Manoj



--
You received this message because you are subscribed to the Google Groups "audioset-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to audioset-users+unsubscribe@googlegroups.com.
To post to this group, send email to audioset-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/audioset-users/cc79f4d7-d16b-4a9d-9e91-45e0fe0b1434%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antoine Mercier

unread,
Sep 21, 2017, 4:28:07 PM9/21/17
to audioset-users
Manoj,

You can find the code here :
It is a little bit quick and durty, especially the code to load the weights from tensorflow to Keras.
I hope yoou will be able to do something with it.
I will clean it later ( concerning the imports ).

I would be happy to get some feedbacks from you.

Antoine

Le jeudi 21 septembre 2017 22:03:12 UTC+2, Manoj Plakal a écrit :

Antoine,

That's awesome! Thank you for doing this.

Yes, we would love to have the Keras version of VGGish. Can you make a pull request with the code, and put the checkpoint file somewhere publicly accessible?

Before you do that, you might want to wait until this PR lands, https://github.com/tensorflow/models/pull/2430, because it moves our model into 'research' subdirectory of tensorflow/models, and then build your change on top of that, and then submit a PR.

In the meantime, do you have the code in Github or elsewhere for us to take a look?

Manoj


On Thu, Sep 21, 2017 at 3:46 PM, Antoine Mercier <antoi...@gmail.com> wrote:
Hello @plakal and @dpwe,
I have converted the vggish model and its weights into a Keras model.
It passes the smoke test.
Are you interested in the code ?

Regards,

Antoine.

--
You received this message because you are subscribed to the Google Groups "audioset-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to audioset-user...@googlegroups.com.
To post to this group, send email to audiose...@googlegroups.com.

Manoj Plakal

unread,
Sep 21, 2017, 5:24:11 PM9/21/17
to Antoine Mercier, audioset-users

The code looks mostly fine (although I don't really know Keras very well).


There are cleaner ways to handle the variable reading and renaming:

- Have an explicit map from Slim layer name to Keras layer name (e.g., { "vggish/conv1": "vggish_conv1", ..., "vggish/fc1/fc1_2": "vggish_fc1_2", ... etc }). 

- Instead of two loops through the list of operations, you could do one loop through the list of variables to find the weights and biases of each layer.

- There are a couple of ways to get the list of variables.
  * You could load a checkpoint in a TF Session (as  you're doing), and then iterate over tf.get_collection(tf.GraphKeys.VARIABLES)), where you will get Variable objects and you can pass var.name to session.run() to get the value, and parse the name to get the layer name (names will be of the form "vggish/conv1/weights:0").

 * You can read the checkpoint directly using NewCheckpointReader without having to define the model and load the checkpoint. The code will look something like this:
    with tf.Graph().as_default():
       reader = tf.train.NewCheckpointReader(path_to_slim_checkpoint)
       var_names = reader.get_variable_to_shape_map().keys()
       for var_name in var_names:
           # var_name will be of the form "vggish/conv1/weights"
           var_value = reader.get_tensor(var_name)


To unsubscribe from this group and stop receiving emails from it, send an email to audioset-users+unsubscribe@googlegroups.com.

To post to this group, send email to audiose...@googlegroups.com.

Akanksha Pathak

unread,
Mar 16, 2020, 5:39:31 AM3/16/20
to audioset-users
Dear Antoine

I am using Python 3.6 for executing your codes. But I am unable to execute code  'preprocess_sound.py' due to error raised by sound module. I can neither find this package on net. I will be glad if you help in this regard.
Reply all
Reply to author
Forward
0 new messages