TensorFlow is one of the most well-known libraries for machine learning. The most significant advantage of TensorFlow versus other libraries is designed to simplify the development of cross-platform projects.
These days, TensorFlow.js (Javascript) is a sub-project of Tensorflow that support three environments: Node.js, Web browser, and Mobile (via React Native). Unfortunately, Javascript is not a good programming language for data science projects because it is easy to make mistakes with little experience. There is another choice, and very familiar with the javascript ecosystem. TypeScript is a programming language with a strong type system that compiles to javascript. The development with Typescript is quick and less error-prone.
This tutorial will set up a development environment with Tensorflow.JS and TypeScript.
Github: https://github.com/quangtiencs/tensorflowjs_typescript_tutorials
Create project directory
Initialize a new project. Follow the prompts of npm (nodejs package manager)
Install typescript compiler and more!
TSC (Typescript Compiler) init
Edit tsconfig.json
and add these lines:
Install Tensorflow.js backend
Add build
and start
command in package.json
file:
Write our first tensorflowjs typescript program src/index.ts
:
Hello World
Create project directory
Initialize a new project. Follow the prompts of npm (nodejs package manager)
Install typescript compiler and more!
TSC (Typescript Compiler) init
Edit tsconfig.json and add these lines:
Install Tensorflow.js
Install http-server and webpack
Write index.html
Write webpack.config.js
Add build
and start
command in package.json
file:
Write our first tensorflowjs typescript program src/index.ts
:
Then start that program :D
Go to localhost:8888
and see the result:
Requirements: Setting up the development environment
First, init react-native and go to the root directory of project:
Then install all requirement packages:
Change App.tsx
to:
Then start the app (android or ios) by command: