KevinHern / AI-Deployment-NodeJS

Small demo to deploy an AI in a NodeJS App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AI Deployment in Node.js

This is a repository that contains multiple examples on how to deploy different AI models in production using Node.js. Feel free to clone, use and modify the files according to your needs.

All of the examples are ready to be deployed on a heroku server. To do so, make sure to follow this tutorial. Additionally, all the package.json files cointained within the multiple directories already have the "engine" section added. Do not forget to modify the Node.js version to match the one you are currently using.

Requirements

Make sure you have Node.js and NPM installed in your computer. Follow this link to install both.

FAQ

How can I use my model trained in a Google Colab in a Node.js app?

It is very simple. First, to export your model, you need to install the tensorflowjs library to access the export functions

!pip install tensorflowjs

Then, save your trained model using the .save() method. Provide a directory.

# Example
temp_dir = './temp/'
model = tf.keras.models.Sequential()
.
.
.
model.save(temp_dir)

After that, execute the following command to export your saved model into a json file:

!tensorflowjs_converter --input_format=keras_saved_model ./temp/ ./prod/

NOTE: The second parameter is the directory that contains your saved model. The third parameter is the directory that your exported model's files are going to be located. You must find a model.json file and some binaries too.

And finally, download all the files contained within the ./prod/ directory and place them inside the assets directory of your Node.js app. Execute the following code in the colab to compress all the files into a zip and download said file.

!zip packed_model.zip ./prod/*

from google.colab import files
files.download("packed_model.zip")

Is it possible to export models with custom layers?

No. This issue states that there is no support for custom layers. As stated by rthadur, the workaround is to define the model with equivalent layers.

About

Small demo to deploy an AI in a NodeJS App


Languages

Language:JavaScript 95.3%Language:Python 4.7%