TensorFlow.js - Serve deep learning models with Node.js and Express

deeplizard · Intermediate ·🔧 Backend Engineering ·8y ago

Key Takeaways

This video demonstrates how to serve deep learning models with Node.js and Express using TensorFlow.js, covering the setup of a web server to host deep learning web applications and serve static files.

Full Transcript

what's up guys in this video we'll go through the process of getting a web server set up to host deep learning web applications and serve deep learning models with Express for nodejs so let's get to it to build deep learning applications that run in the browser we need a way to host these applications and a way to host the models so then really we just need a way to serve static files if you follow the series on deploying Kerris models then you know that we already have a relatively easy way of hosting static files and that's with flask blast though is written in Python and while it would work perfectly fine to host the tensorflow j/s applications will be developing it makes sense that we might want to use a JavaScript based technology to host our apps since we're kind of breaking away from Python and embracing JavaScript in this series so enter Express for nodejs express is a minimalist web framework very similar to flask but is for node.js not Python and if you're not already familiar with node.js then you're probably wondering what it is as well no js' which will refer to most of the time as just node is an open-source runtime environment that executes JavaScript on the server side C historically JavaScript has been used mainly for client-side applications like browser applications for example but node allows us to write server-side code using JavaScript will specifically be making use of express to host our web applications and serve our models so let's see how we can do that now first things first we need to install node.js I'm here on the downloads page of nodes website so you just need to navigate to this page choose the installation for your operating system and get it installed I've installed node on a Windows machine but you'll still be able to follow the demos we'll see in a few moments even if you're running another operating system all right after we've got node installed we need to create a directory that will hold all of our project files so we have this directory here I've called tensorflow j/s within this directory we'll create a sub directory called local server which is where the Express code that will run our web server will reside and will also create a static directory which is where our web pages and eventually our models will reside within this local server we create a package.json file which is going to allow us to specify the packages that our project depends on let's go ahead and open this file I've opened this with Visual Studio code which is a free open source code editor developed by Microsoft that can run on Windows Linux and Mac OS this is what we'll be using to write our code so you can download it and use it yourself as well or you can use any other editor that you'd like all right back to the package.json file within package.json we're going to specify a name for our project which we're calling in tensorflow j s all lowercase per the requirements of this file will also specify the version of our project there are some specs that the format of this version has to meet but most simplistically it has to be in an xxx format so we're just going to go with the default of 1.0.0 all right name and version are the only two requirements for this file but there are several other optional items we can add like a description the author and a few others we're not going to worry about this stuff but we are going to add one more thing the dependencies this specifies the dependencies that our project needs to run we're specifying Express here since that's what we'll be using to host our web apps and we're also specifying the version now we're going to open PowerShell and we have the ability to open it from right within this editor by navigating to view and then integrated terminal and you should have the ability to open the terminal of your choice that's appropriate for your operating system if you're running on Linux for example and don't have PowerShell otherwise you can just open a terminal outside of the editor if you'd like all right so from within PowerShell we make sure we're inside of the local server directory where the package.json file is and we're going to run NPM install NPM stands for node package manager and by running NPM install NPM will download and install the dependencies listed in our package JSON file so let's run NPM install we'll see it installs Express and when this is finished you can see that we now have an added node modules directory that contains the downloaded packages and we additionally have this package law JSON file that we didn't have before it contains information about the downloaded dependencies don't delete these things all right so at this point we have node we have Express now we need to write a node program that will start the Express server and will host the files that we specify let's see that makes sense to do this we'll create this file called server jeaious inside a server j/s we first import Express using require Express using require like this will import the Express module and give our program access to it you can think of a module and node as being analogous to a library in JavaScript or Python just a group of functions that we want to have access to from within our program and then we create an Express application using the Express module which we assign to app an Express app is essentially a series of calls to functions that we call middleware functions middleware functions have access to the HTTP request and response objects as well as the next function in the applications request response cycle which just passes control to the next handler so within this app when a request comes in we're doing two things we're first logging information about the request to the terminal where the Express server is running and we then pass control to the next handler which will respond by serving any static files that we've placed in this directory called static that's right within the root directory of our tensorflow j/s project so in our case the middleware functions I mentioned are here and here note that the calls to app dot use are only called once and that's when the server is started the app dot used calls specify the middleware functions and calls to those middleware functions will be executed each time a request comes into the server lastly we call app dot listen to specify what pour Express should listen on i've specified port 81 here but you can specify whichever unused port you'd like when the server starts up and starts listening on this port this function will be called which will log this message letting us know that the server is up and running alright we're all set up let's drop a sample HTML file into our static directory then start up the Express server and see if we can browse to the page we're going to actually just place the web application called predicta HTML that we created in the Charis deployment series into this directory as a proof-of-concept so we place that here you can use any HTML file you'd like though to test this now to start express we use PowerShell let's make sure we're inside of the local server directory and we run a node server j/s we get our output message letting us know that Express is serving files from our static directory on port 81 so now let's browse to localhost or whatever the IP address is that you're running Express on port 81 slash predict HTML which is the name of the file we put into the static directory and here we go this is indeed the webpage we wanted to be served also check out the output from this request in PowerShell to view the logging that we specified so good we now have node and Express setup to be able to serve our models and host our tensorflow j/s apps that will be developing coming up give me a signal in the comments if you were able to get everything up and running and I'll see you in the next video [Music]

Original Description

To build deep learning applications that run in the browser, we need a way to host these applications and a way to host the models. So then, really, we just a way to serve static files. Let's go through the process of getting a web server set up to host deep learning web applications and serve TensorFlow.js models with Express for Node.js. Enter Express for Node.js. Express is a minimalist web framework, very similar to Flask, but is for Node.js, not Python. If you're not already familiar with Node.js, it is an open-source run-time environment that executes Javascript code on the server-side. We'll be making use of Node.js and Express to deploy our TensorFlow.js deep learning applications. 🕒🦎 VIDEO SECTIONS 🦎🕒 00:00 Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources 00:30 Help deeplizard add video timestamps - See example in the description 07:57 Collective Intelligence and the DEEPLIZARD HIVEMIND 💥🦎 DEEPLIZARD COMMUNITY RESOURCES 🦎💥 👋 Hey, we're Chris and Mandy, the creators of deeplizard! 👉 Check out the website for more learning material: 🔗 https://deeplizard.com 💻 ENROLL TO GET DOWNLOAD ACCESS TO CODE FILES 🔗 https://deeplizard.com/resources 🧠 Support collective intelligence, join the deeplizard hivemind: 🔗 https://deeplizard.com/hivemind 🧠 Use code DEEPLIZARD at checkout to receive 15% off your first Neurohacker order 👉 Use your receipt from Neurohacker to get a discount on deeplizard courses 🔗 https://neurohacker.com/shop?rfsn=6488344.d171c6 👀 CHECK OUT OUR VLOG: 🔗 https://youtube.com/deeplizardvlog ❤️🦎 Special thanks to the following polymaths of the deeplizard hivemind: Tammy Mano Prime Ling Li 🚀 Boost collective intelligence by sharing this video on social media! 👀 Follow deeplizard: Our vlog: https://youtube.com/deeplizardvlog Facebook: https://facebook.com/deeplizard Instagram: https://instagram.com/deeplizard Twitter: https://twitter.com/deeplizard Patreon: https://patreon.com/deeplizard YouTube:
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from deeplizard · deeplizard · 0 of 60

← Previous Next →
1 Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
Install Jaxx cryptocurrency wallet on Windows 10 and verify file hash
deeplizard
2 Jaxx cryptocurrency wallet overview - A Blockchain Interface
Jaxx cryptocurrency wallet overview - A Blockchain Interface
deeplizard
3 Remove Jaxx cryptocurrency wallet from Windows 10
Remove Jaxx cryptocurrency wallet from Windows 10
deeplizard
4 Install Jaxx cryptocurrency wallet Chrome extension
Install Jaxx cryptocurrency wallet Chrome extension
deeplizard
5 Send Litecoin from GDAX to Jaxx wallet
Send Litecoin from GDAX to Jaxx wallet
deeplizard
6 Send Litecoin from Jaxx wallet to GDAX
Send Litecoin from Jaxx wallet to GDAX
deeplizard
7 Backup and restore Jaxx wallet with passphrase
Backup and restore Jaxx wallet with passphrase
deeplizard
8 Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
Send Litecoin to Bittrex using Jaxx and monitor confirmations with BlockCypher
deeplizard
9 Join a mining pool on Waves platform and lease Waves
Join a mining pool on Waves platform and lease Waves
deeplizard
10 ZCASH Explained | An introduction to a privacy based cryptocurrency
ZCASH Explained | An introduction to a privacy based cryptocurrency
deeplizard
11 ZCash t address creation with Jaxx wallet and private key blockchain discussion
ZCash t address creation with Jaxx wallet and private key blockchain discussion
deeplizard
12 Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
Buy ZCash with Litecoin using the Shifty button in the Jaxx wallet
deeplizard
13 Buy ZCash with Litecoin using ShapeShift - FAILURE
Buy ZCash with Litecoin using ShapeShift - FAILURE
deeplizard
14 Litecoin | Jaxx | Shapeshift | zcash | failed
Litecoin | Jaxx | Shapeshift | zcash | failed
deeplizard
15 Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
Buy ZCash with Litecoin using ShapeShift - SUCCESS even with Jaxx issues
deeplizard
16 Explore ZCash blockchain with Zchain block explorer
Explore ZCash blockchain with Zchain block explorer
deeplizard
17 Zchain ZCash block explorer API - PowerShell Code
Zchain ZCash block explorer API - PowerShell Code
deeplizard
18 Zchain ZCash block explorer API - Introduction
Zchain ZCash block explorer API - Introduction
deeplizard
19 Zchain ZCash block explorer API - Application
Zchain ZCash block explorer API - Application
deeplizard
20 Coinbase's Trading Platform | Previously known as GDAX
Coinbase's Trading Platform | Previously known as GDAX
deeplizard
21 Coinbase Social Security Number (SSN) Requirement Explained
Coinbase Social Security Number (SSN) Requirement Explained
deeplizard
22 Who owns Coinbase? Here are some KEY people
Who owns Coinbase? Here are some KEY people
deeplizard
23 How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
How does Coinbase/GDAX secure Bitcoin, Litecoin, Ether?
deeplizard
24 Coinbase | HackerOne bug bounty program
Coinbase | HackerOne bug bounty program
deeplizard
25 Is Bitcoin safe at Coinbase/GDAX?
Is Bitcoin safe at Coinbase/GDAX?
deeplizard
26 Coinbase Login Demo Using Google Authenticator (2FA)
Coinbase Login Demo Using Google Authenticator (2FA)
deeplizard
27 Coinbase Pro - GDAX | Trading Interface Overview
Coinbase Pro - GDAX | Trading Interface Overview
deeplizard
28 Coinbase gives $10 in Bitcoin | Watch this before signing up
Coinbase gives $10 in Bitcoin | Watch this before signing up
deeplizard
29 Coinbase around the globe | What countries are supported?
Coinbase around the globe | What countries are supported?
deeplizard
30 Order book explained | Trading concept to know
Order book explained | Trading concept to know
deeplizard
31 Bid/Ask spread explained | Trading concept to know
Bid/Ask spread explained | Trading concept to know
deeplizard
32 Maker vs Taker | Trading concept to know
Maker vs Taker | Trading concept to know
deeplizard
33 Market Orders are Always TAKERS (HIGHER FEES)!
Market Orders are Always TAKERS (HIGHER FEES)!
deeplizard
34 Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 1
deeplizard
35 Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
Buy as a MAKER (LOWER FEE) on Coinbase Pro - GDAX | Limit Order - Part 2
deeplizard
36 Time-in-force explained | Trading concept to know
Time-in-force explained | Trading concept to know
deeplizard
37 Stop order explained | How to stop a loss | Coinbase Pro - GDAX
Stop order explained | How to stop a loss | Coinbase Pro - GDAX
deeplizard
38 Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
Stop Order on Coinbase Pro - GDAX | What the WARNINGS Mean
deeplizard
39 Market price vs Last price | Trading concept to know
Market price vs Last price | Trading concept to know
deeplizard
40 Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
Stop Order on Coinbase Pro - GDAX | How it is ACTIVATED
deeplizard
41 Stop-limit order | How to set the limit | Coinbase Pro - GDAX
Stop-limit order | How to set the limit | Coinbase Pro - GDAX
deeplizard
42 Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
Flash CRASH Part 1 | ETH/USD currency pair traded at $0.10
deeplizard
43 Slippage explained | Trading concept to know
Slippage explained | Trading concept to know
deeplizard
44 Flash CRASH Part 2 | How did Coinbase Respond?
Flash CRASH Part 2 | How did Coinbase Respond?
deeplizard
45 Buy side stop-limit order | Crypto trading strategy for buying a breakout
Buy side stop-limit order | Crypto trading strategy for buying a breakout
deeplizard
46 Buy side stop-limit order | Triggering under the market price
Buy side stop-limit order | Triggering under the market price
deeplizard
47 What is an order book?
What is an order book?
deeplizard
48 What is a market?
What is a market?
deeplizard
49 What is an exchange?
What is an exchange?
deeplizard
50 What is a broker-dealer?
What is a broker-dealer?
deeplizard
51 Keras prerequisites
Keras prerequisites
deeplizard
52 Change Keras backend to Theano
Change Keras backend to Theano
deeplizard
53 #1 Order types and parameters | Trading on Coinbase Pro - GDAX
#1 Order types and parameters | Trading on Coinbase Pro - GDAX
deeplizard
54 Trading strategy for stopping a loss | Don't trade all at once!
Trading strategy for stopping a loss | Don't trade all at once!
deeplizard
55 #2 Order matching engine | Trading on Coinbase Pro - GDAX
#2 Order matching engine | Trading on Coinbase Pro - GDAX
deeplizard
56 Batch Size in a Neural Network explained
Batch Size in a Neural Network explained
deeplizard
57 Deep Learning playlist overview & Machine Learning intro
Deep Learning playlist overview & Machine Learning intro
deeplizard
58 Artificial Neural Networks explained
Artificial Neural Networks explained
deeplizard
59 Regularization in a Neural Network explained
Regularization in a Neural Network explained
deeplizard
60 Create confusion matrix for predictions from Keras model
Create confusion matrix for predictions from Keras model
deeplizard

This video teaches how to deploy deep learning models using TensorFlow.js and serve them with a web server using Node.js and Express. It covers the basics of setting up a web server and serving static files.

Key Takeaways
  1. Install Node.js and Express
  2. Setup a new Express project
  3. Create a web server to serve static files
  4. Deploy a deep learning model using TensorFlow.js
  5. Test the web application
💡 Using Node.js and Express provides a flexible and efficient way to serve deep learning models and web applications.

Related AI Lessons

Chapters (3)

Welcome to DEEPLIZARD - Go to deeplizard.com for learning resources
0:30 Help deeplizard add video timestamps - See example in the description
7:57 Collective Intelligence and the DEEPLIZARD HIVEMIND
Up next
This Cop Was Held Accountable For His Brutality! #police #lawyer
Hampton Law
Watch →