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

sonnet abstract module in tensorflow2 #271

Open
creativesh opened this issue Sep 30, 2023 · 10 comments
Open

sonnet abstract module in tensorflow2 #271

creativesh opened this issue Sep 30, 2023 · 10 comments

Comments

@creativesh
Copy link

creativesh commented Sep 30, 2023

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 ?

@creativesh creativesh changed the title sonnet abstracy module in tensorflow2 sonnet abstract module in tensorflow2 Sep 30, 2023
@tomhennigan
Copy link
Collaborator

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.

@creativesh
Copy link
Author

Hi @tomhennigan

Could I rewrite it to use tf2 ?

@creativesh
Copy link
Author

creativesh commented Sep 30, 2023 via email

@tomhennigan
Copy link
Collaborator

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

@creativesh
Copy link
Author

creativesh commented Sep 30, 2023

@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?

@tomhennigan
Copy link
Collaborator

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

@creativesh
Copy link
Author

@tomhennigan

Do you have any sample code of developing networks with sonnet 2 and tensorflow 2 ?

@tomhennigan
Copy link
Collaborator

There are a number of examples here: https://github.com/google-deepmind/sonnet/tree/v2/examples

@creativesh
Copy link
Author

creativesh commented Oct 1, 2023

@tomhennigan

In this post #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- ?

@tomhennigan
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants