sonnet
sonnet copied to clipboard
sonnet abstract module in tensorflow2
Hello friends
I want to use i3d model created by sonnet in tensorflow 2
these are my environment: ubuntu 20 tensorflow 2.12 python 3.8
this is my i3d code:
` from future import absolute_import
from future import division from future import print_function import sonnet as snt import tensorflow as tf class Unit3D(snt.AbstractModule):
`
but when I want to import it in tf2, I face the following error: AttributeError: module 'sonnet' has no attribute 'AbstractModule'
which is related to this line:
class Unit3D(snt.AbstractModule): >>> class MultiplyModule(snt.Module): ... def call(self, x): ... if not hasattr(self, 'w'): ... self.w = tf.Variable(2., name='w') ... return x * self.w
>>> mod = MultiplyModule()
>>> mod(1.)
<tf.Tensor: ... numpy=2.0>
how to fix it ?
Hi @creativesh , snt.AbstractModule
is part of Sonnet 1, it looks like the code you are wanting to run will only work with TF1 not TF2.
Hi @tomhennigan
Could I rewrite it to use tf2 ?
Thanks
How should I convert it to tf2 ? It is an i3d model. for action recognition I have some weights in .ckpt format which is in tf1 format and want to load them in a model and retrain the model
On Sat, Sep 30, 2023 at 3:37 PM Tom Hennigan @.***> wrote:
Hi @creativesh https://github.com/creativesh , snt.AbstractModule is part of Sonnet 1, it looks like the code you are wanting to run will only work with TF1 not TF2.
— Reply to this email directly, view it on GitHub https://github.com/google-deepmind/sonnet/issues/271#issuecomment-1741751704, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFOLMRPAVS434CME24IOEZDX5ADQNANCNFSM6AAAAAA5NNGEJ4 . You are receiving this because you were mentioned.Message ID: @.***>
Hi, it should be possible to implement this in TF2/Sonnet 2, but this will require learning and understanding Sonnet 2.
If you just want to make use of a pretrained I3D model then perhaps using Keras + TF2 would be simpler, they have an example that includes using I3D and some pretrained weights to make predictions for a video: https://www.tensorflow.org/hub/tutorials/action_recognition_with_tf_hub
@tomhennigan
Thanks for your response, exactly, I want to finetune the checkpoints you mentioned in your link : https://www.tensorflow.org/hub/tutorials/action_recognition_with_tf_hub
I have written the tf1 version of finetune code. now I want to write it in tf2. the limitation is that Ihad to use .ckpt checkpoints and save the fine-tuned model in .ckpt format. Can I do it with keras? Do you have any link or hint?
I am not very familiar with Keras, I would suggest asking for support on their issue tracker, hopefully someone will have a recipe for you.
There is a generic guide on migrating checkpoints here which you could try to follow https://www.tensorflow.org/guide/migrate/migrating_checkpoints
@tomhennigan
Do you have any sample code of developing networks with sonnet 2 and tensorflow 2 ?
There are a number of examples here: https://github.com/google-deepmind/sonnet/tree/v2/examples
@tomhennigan
In this post https://github.com/google-deepmind/sonnet/issues/128 you mentioned aome changes to convert a class in sonnet 1 to sonnet2
would you please tell me exactly what to do about i3d.py in this link: https://github.com/google-deepmind/kinetics-i3d
1- converting snt.AbstractModule to snt.Module 2- ?
Hi, the comment you linked to has information on how to port code from sonnet 1 -> 2 and what has changed between the libraries.
Good luck with porting the code for your project.