Is TensorFlow.js integration possible?

Is there a way to import the Tensorflow.js library to do machine learning with Snap? Was thinking of making some interesting projects involving maze navigation and simple game playing.

No problem importing TensorFlow.js but I've seen with heavy use occasionally Snap!'s display become very broken (much too small - parts stay black). Since both Snap! and Tensorflow.js rely upon WebGL I think Tensorflow.js can take GPU memory that Snap! needs.

Instead of tracking this problem down and addressing it directly, I chose to run Tensorflow.js in an invisible iframe. Snap! and this iframe can communicate via postMessage. This way they are separate pages and at least in Chrome protected from each other. And that opens up the possibility to show the iframe to, for example, visualise training progress.

Using this I've implemented dozens of Tensorflow.js commands and models in Sna!. See https://ecraft2learn.github.io/ai/ to learn more. Perhaps you can just use some of the blocks described in https://ecraft2learn.github.io/ai/AI-Teacher-Guide/chapter-6.html

I tried to use some of the blocks but they give me errors like "loaded_model is not defined"

Thank you for reporting this. Fixed now. Very sorry about that.

thanks for the cool API though. how do i go about importing the newest blocks into an empty snap project?

Hi on https://ecraft2learn.github.io/ai/ there are these links:

Enabling your projects to create, train, and use deep learning neural networks. Project or library.

Just import the library.

The Project link is the library with sample usage and some documentation.

Training loss has become 'not-a-number'.
Not sure what I did wrong..?

It appears to be the train model function that is having some problems

This is a problem that occurs for various reasons. Here's a Google search with many hits discussing this.

The JavaScript underlying my Snap! blocks tries to catch this and then inform the user. Did you see something like the following?

"Training failed because some numbers became too large for the system. " +
 "This can be caused by many different things. " +
 "Try different optimization methods, loss functions, or convert the input data to numbers between -1 and 1. " +
"Often the problem is due to <a href='https://en.wikipedia.org/wiki/Vanishing_gradient_problem' target='_blank'>vanishing gradients</a>."

My experience has been that I see this a few percent of the time and choosing a different option and it goes away.

If there wasn't such a message let me know where the error occurred and I'll improve the error handling.

I only got that very first part in the developer console and in the first message box it showed.

I also had tried this and it worked but it gave me some insanely low answers when its supposed to just compute the bAND of both operands

Nevermind, go it to work fairly well and i tried it with signed numbers as well