Google Cloud: TensorFlowJS

Check out my working site:!

After failing in my last blog to get my trained model in the cloud I started looking at TensorFlowJS. It is a JavaScript library that will let me interact with TensorFlow.

Good new: It works. Bad news: It doesn’t work on a mobile browser. I have a GitHub Ticket (1586) open hoping that it will be cleared up. The issue is wild though, using the same JS library and the same model in the same bucket in the same cloud returns different values if you use a phone.

Anyway, here is how I got everything up and running.

First, I installed TensorFlowJS in my Google Colab notebook. I was then able to use that to create a save
tfjs.converters.save_keras_model(restored_model, location).

Second, I created another bucket like I did in my previous post. In that bucket I uploaded my plain HTML file and then a folder for my scripts. In the scripts folder I added my model.

Third, in my HTML file I needed to call out to a different server to load TensorFlowJS :
<script src=”; />

Fourth, I needed to figure out how I was going to code this bad boy. I don’t do much JavaScript so this was a lot of searching. One of the main pages was a tutorial that helped.

Finally, I needed to figure out what in the world a Promise in JS is. Turns out, it is just an async return type similar to a Task in .NET. Once I got this loaded on start up and then called the model on a click I was good to go.

In the near future, I am going to clean up this site as well as allow the user to select 2 teams and see what the model things will happen. Stay tuned!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s