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

How to add Tensorflow? #24

Open
ThorvaldAagaard opened this issue Oct 21, 2023 · 7 comments
Open

How to add Tensorflow? #24

ThorvaldAagaard opened this issue Oct 21, 2023 · 7 comments

Comments

@ThorvaldAagaard
Copy link

My game is using Tensorflow, and it runs fine locally, but when I deploy it as a pygbag-solution I get the following error

1234: want='tensorflow' found : False
PKG NOT FOUND : want='tensorflow', resume=<function <module> at 0x11a10e0>, ex=ModuleNotFoundError("No module named 'tensorflow'")

How can I fix that?

@pmp-p
Copy link
Member

pmp-p commented Oct 22, 2023

You should ask (not here it is completely out of scope for pygbag runtime) for a proper wasm port of Tensorflow to cpython-wasm or more likely pyodide.

From a quick search it is not impossible see https://blog.tensorflow.org/2020/03/introducing-webassembly-backend-for-tensorflow-js.html

Of course your game won't run of most of already deployed mobile devices because of wasm extensions used that are NOT implemented, or not available because lack of updates.

transerfing issue to porting section

@pmp-p pmp-p transferred this issue from pygame-web/pygbag Oct 22, 2023
@ThorvaldAagaard
Copy link
Author

That was a major setback.
I am mostly interested in getting it to work on the web, Mobile devices in the distant future,
I now have a plying application, but I have no idea how to port tensorflow for use in pygbag.
Are there any descriptions of how to make the port, or anyone that can perform the port. I will be happy to help testing it.

@pmp-p
Copy link
Member

pmp-p commented Oct 23, 2023

I don't know much about gpu computing and tensorflow but i guess most people will wait for webgpu+wasm2 to do that kind of - very - complicated stuff.

@ThorvaldAagaard
Copy link
Author

All my models are locally trained, and it is just the usage of the models in a web-context, that is interesting, so no gpu-computing needed.

Implementation is at: https://github.com/ThorvaldAagaard/bridge-with-ben and looking thru the code, there are not much tensorflow usage besides opening the models, and calling then.

@pmp-p
Copy link
Member

pmp-p commented Oct 23, 2023

so basically you only need a small part of tensorflow like a "runtime" only ?
if so cannot you call the existing wasm implementation via javascript window object from pygbag ?

@ThorvaldAagaard
Copy link
Author

Yes, a sort of runtime.

I am only accessing these classes:
tf.Graph()
tf.compat.v1.Session()
tf.compat.v1.train.import_meta_graph()
tf.nn.softmax()

I have been looking at how to use the generated models from javascript, but not found a solution (yet), as the input to calling the models are numpy arrays (and very complex). If I could get that to work the game would probably be implemented in javascript/typescript/flutter :-)

But where can I read more about how to use the javascript window object from pygbag?

@pmp-p
Copy link
Member

pmp-p commented Oct 23, 2023

sorry no doc about that but most objects are 1:1 mapping to python except promises, but the goal is not to "use" js it is more "you can pass pointers and do memcpy with js", it would only serve as a transport beetween wasm memories ( that if the above wasm implementation of runtime cannot be linked or dlopened directly : i don't have time to investigate now so idk)

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