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!

Google Cloud: AI-Engine

After completing my DevPost project and hearing that Iowa has legalized sports betting I decided I should take my model out of Google Colab and into the magical cloud.

My plan was to follow a few web sites and upload my model. This didn’t go well. As listed in the GitHub issue at the bottom. There is an issue with TFv2 and the AI-Engine.

But, here are the steps I went through to get to a place where once a bug fix is in place I will be up and running.

First, I had to create a model that would work. My assumption that my original h5 file was good enough was wrong. I needed to use the ‘Saved_Model’ method. Well, in TFv2 this was moved from contrib to experimental. Once this was cleared up I created the model and exported it from my Colab notebook.

Second, I created a Cloud Bucket to host my model. This was straight forward.

Third, I needed to test my model. I had to create a text file that would host my input parameters so I could test locally. Then, using the gcloud command line I called ai-platform and got an error message. It turns out that the way the model was built wasn’t compatible with how AI-Engine expects.

Finally, I just created the GitHub issue and asked around in my Google slack channels. It turns out it is an open issue. The real problem is that since this is between the cloud and TF I am not sure who blinks first and has to change it.

Feel free to watch the issue to see if/when this gets figured out.

GitHub Issue:

Google Cloud: Static Web Site

Previously, I had my web site hosted on Azure with my DNS held at GoDaddy. These were fine UNTIL I lost my free credits. Once that happened I was getting charged ~$50/month for my site. Since I don’t really do anything with it (besides a place to host files for my mobile apps) I didn’t want to pay for it.

Fast forward a year and I was messing around with hosting a trained TFv2 model in the AI-Engine. I would then interface with that model for a gambling web site I am messing around with. I get into this in a later post but it didn’t go well.

While I was in the Google Cloud console I started to look at hosting my web site. I saw that I can deploy to a bucket and then have DNS redirect.

Following this page I went to work.

First, I created a bucket that is named after my site. I then downloaded the files from Azure and uploaded them to the bucket. I changed the permissions and we were off an running.

Second, I needed to get my DNS moved so that I could just type in and it would redirect. This was a few more steps but I had to go to GoDaddy and “unlock” my domain. After that was done I could set up a transfer. Finally, I was able to import it to Google.

Third, I needed to create the CNAME entries so that DNS would know how to direct it. This took a bit to refresh but in the end it worked just fine.

Finally, since I am a developer and I like to automate, I followed this page on how to set up a trigger so that every time I committed to GitHub it would deploy to Google.

Moving to Google Cloud

I have decided to move my lift to the Google Cloud. Before, my web site was hosted in Azure through GoDaddy. I have since moved my HTML to a Google Cloud bucket and my domain to their domain service.

Over the next few weeks I will discuss what I have done and why. Including trying to put my DevPost submission in the cloud before Iowa gets finished approving legalized gambling.

My first post will be moving my web site to the cloud. This includes updating my DNS, implementing deployments through GitHub, and setting permissions.

My second post will be trying to use the AI-Engine with TensorFlow v2

My third and final post will be about moving my DevPost project to the cloud and using TensorFlowJS.