Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

python - Best practice to create a live running model from a trained neural network

I'm planning to create a neural network for trading, I'm investigating on how to use the trained neural network in a language that is used in runtime by my system (ie C++ or C#).

Let's say I'm using tensorflow in python (or any other nn framework), I've successfully trained my neural network that has n hidden layers. I have at that point the values for weights and bias. At this point I would like to use the nn model in production.

In my understanding it is not best practice to run in production tensorflow to run the model, since it's practically too slow (python) and clunky to do so (correct me if I'm wrong).

So I'd like to recreate the nn model in C# or C++ (or any other language), do I need to recreate in code all the maths for each layer based on weight and bias for every neuron? enter image description here

Questions:

  • I've never done it, so this is me guessing the workflow/best practice, what is the best way to do it?
  • What are some online articles/websites I can read about this topic?
  • What is this topic called, so that I can look for it?
question from:https://stackoverflow.com/questions/65891503/best-practice-to-create-a-live-running-model-from-a-trained-neural-network

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Frameworks like tensorflow should also be used in production. Tensorflow is written in highly optimized C++ and/or Cuda and will thus easily outperform anything you will write yourself. There is also a large amount of inbuilt tools for monitoring, load balancing etc. that comes with tensorflow.

If you run your system on your machine you can use any language as a wrapper. If you really think you need a level of optimization for small tasks such as preprocessing etc. that can not be done in Python, just use the C++ API for tensorflow. Just let tensorflow (or torch or whatever production lvl framework you are using) do the heavy lifting of handling the neural network. For 99.99% percent of tasks Python(using numpy, tf, dask etc.) will be just fine.

For large scale applications you can host your model on aws/azure/google cloud etc. They offer optimized services for hosting tensorflow models (eg. as REST endpoints). Lambda fucntions/Azure Functions can be a great tool to do the preprocessing step in a costefficient and scaleable way.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...