How to deploy Deep Learning Model(Python) to web app(Node) - node.js

Hi I am very interested in machine learning.
familiar with keras and tensorflow and know how to train model and save it.
I want to build node.js(loopback) web application that provides machine learning API.
I'm quite new to web application and don't know how to utilize python code in the node app.
To be specific, I'm trying to make deep style application like this site for practice purpose.
For codes that is open to public in github. most starred implementation is in torch and
I am currently looking (TF).
It has script work as "main.py" that consists of
1) loading pretrained VGG model(about 500Mb) to memory.
2) and using each framework's function, it create output photo inside folder
So I want to run this with GPU instance in AWS
problem is, I don't know how to call "main.py" inside javascript.
Q1 How did many machine learning based services achieved this??
did they implement their server in python like django to load trained model and inference from it?
But I want to integrate in node.js especially loopback. how can I achieve this in a most efficient and common way??
Q2 Is calling "main.py" efficient whenever there's request to server?
I mean, If the script is called everytime request is made, It loads 500Mb object to memory all the time and that's so inefficient.
and as far as I know AWS GPU instance can utilize 4 GPU at a time. I wonder how can I utilize all of it with most efficient and common way...
Thank you for reading!
I'm too frustrated with myself... I really want to know method deploy my model to server
and thank you in advance

You can communicate between NodeJS and e.g. Django with a REST interface. Deploy a Django server with the REST framework and call an url from NodeJS. This way, you can trigger the python code. You can also let the python code call your NodeJS with another REST interface on the javascript side if that is needed.

Related

Nodejs + Express vs Django: Choosing the best suitable backend component for given requirements

I'm trying to build a software architecture for my web development. The main requirements of the website are as follows:
visualize real-time data
carry out machine learning analysis
Report visualization information via Email or SMS
The concept for such an web application consists of a database, a backend and a frontend component. I have already selected a time series database.
Despite my research, I cannot determine which backend component best meets the requirements: Nodejs + Expressjs or Django. My programming knowledge in Javascript and Python is on the same level.
Why Node:
its Single Threaded Event Loop Model for real-time web applications
same programming language for selecting a javascript framework on the frontend-side (but python for machine learning analysis)
More flexibility than Django due to its MTV pattern
(usually) less execution time than python-Code
Why Django:
Django Channels for real-time web applications
python language in backend, frontend and for data analysis
quicker development process because of the language simplicity
more secure due to its build-in security tools
Question:
Are there any other technical arguments why I should consider choosing Nodejs or Django or any arguments for not choosing one of them?
Well Django is also very flexible and powerful in the sense that you have to write less boilerplate code and gives you many solutions out of the box like admin panel, authentication and many more...
yes its true nodejs is fast as compared to django but tell me how fast? does it really matter?
Django also has concept like celery which are used for background tasks such as sending mails. A possible nodejs threading alternative.
In nodejs you have websockets while in django you have channels
You can do machine learning in both, nodejs also has tenserflow support and many other libs.
Conclusion: In my opinion you should go either with Django, laravel or Rails or something mature like that, Reason is nodejs web frameworks are pretty young in the market, where as django has been for more than 20 years now I guess, and same for laravel etc. Express is lot of boiler plate code, and as for nestjs, its also pretty young.
Hope my suggestion help you. Personally I also started with nodejs and now switched to Django. I am not saying nodejs is bad, its awesome but Time matters, if you want to develop stuff fast, then nodejs is not a good solution.

Is there a way of transporting a pickle file of machine learning written in python (scikit-learn) into node.js?

I would like to use python just for creating machine learning models and then transporting them onto the web using JS. I've done a simple project similar to this, but I used Flask for simple backend/API.
I'm also okay with creating APIs in Flask or Django, and then doing backend in Node.js, if that is possible. I've never done backend before, and my knowledge of frontend and ml is on beginner level.
I would like to build a good and scalable web application that uses ml for It's calculations.
I would like to use Bootstrap for looks, JS for both frontend (React) and backend (Node.js), and Python (Scikit-learn) for machine learning algorithms.
Any suggestions of file structure, organization and which libraries and programming languages I should use are welcome. You can checkout my code and app in links. It isn't anything special, but it works, and I want to build on it.
http://alumil-alloys.herokuapp.com/
https://github.com/nemanjaKostovski/MLmodel
PS what I especially don't like about my app is Flask affecting the frontend. I don't like my html markings for displaying answer.

How do I use Node.js to read server file within a Django application?

I have a django application that I use to visualize data. The data itself is in an Amazon S3 bucket, and the plotting of the data is done using bokeh. One of the applications however, uses d3 instead. And while I managed to configure the bokeh apps to work properly, I don't know how to do that with the d3 app. It has to read data either directly from S3 or locally (If I download it within django views before rendering the web page) and plot it. But whatever I try I get a 404 Not Found error.
I'm learning as I go, so I don't know what I'm doing wrong. Going through SO, I found this question which gives an example of downloading a file from S3 using Node.js, but I am already running a django server so I don't know if that works. I should also mention that the files to be read are quite large (several megabytes). So, to summarize, my question is:
Is using Node.js my only solution here and can it be done without having both Nodejs and django running at the same time? I'm worried that this might be too complex for me to set up. Or better yet, what would be a recommended solution in my case? I am almost done with the whole project but, unfortunately, I've gotten stuck pretty bad here.
Thank you to anyone willing to help or offer advice.

Can H2O be used with node.js (standalone/offline in Electron app)

Does h2o-3 have node.js bindings? I found https://github.com/h2oai/h2o.js but when I saw no updates in two years I realized it was for h2o v2.
I'm specifically asking about deploying a POJO/MOJO jar file, in the context of an Electron app. I.e. offline, not using the REST API to communicate back to a server. (Maybe my question is more: could I use the h2o.jar, and a pojo/mojo file, with something like https://github.com/joeferner/node-java and expect everything to work together, across each of Linux/Mac/Windows?)
FWIW, TensorFlow integration seems vapourware at the moment: https://github.com/node-tensorflow/node-tensorflow, but MxNet seems to have something working: https://github.com/dmlc/mxnet.js/ So, if H2O pojo/mojo can be used from within node.js apps, could Deep Water models also work?
H2O does not have node.js bindings, but H2O exposes a well documented REST API. From Electron, you can start H2O using the child_process module, then talk to H2O using the REST API. If you only care about embedding the model in your Electron app, you can self host the model in a java process using node-java (if you are building some kind of a desktop-only application), OR you can have the Electron app talk to a local or remote http server that hosts the model (see https://github.com/h2oai/app-consumer-loan)

Create a job that goes through H2O Flow automatically

I have created a flow to predict something with the distributed random forest model and now i want to predict every few days, without using the flow gui.
So is there a way to automate your H2O Flow or to translate the entire script into java/python to automatically run the flow?
You should be using RESTful API to work with H2O backend like the way FLOW works. Based on RESTful API you can create a fully automated solution in a RESTful supported language to get it working.
I found the answer myself there is a RestAPI I can use to do everything that i can do in the H2O Flow gui. FYI

Resources