简体   繁体   English

在 AWS Lambda 上运行 Tensorflow 2 预测

[英]Run Tensorflow 2 prediction on AWS Lambda

I want to run a Tensorflow 2 LinearClassifier on AWS Lambda.我想在 AWS Lambda 上运行 Tensorflow 2 LinearClassifier。 I have a trained LinearClassifier tensorflow model.我有一个训练有素的线性分类器 tensorflow model。 I want to run only the prediction in AWS Lambda, because of cost efficeny.由于成本效益,我只想在 AWS Lambda 中运行预测。

Currently I'm not sure how to handle it.目前我不确定如何处理它。

  • I tried to use normal TF2, but it is too big for AWS Lambda Layers.我尝试使用普通的 TF2,但它对于 AWS Lambda 层来说太大了。 All descriptions you find are with older TF 1.1x versions and Python 2.x.您找到的所有描述都是针对较旧的 TF 1.1x 版本和 Python 2.x。
  • Then I tried TensorflowJS, but it looks like the LinearClassifier using functions which are not implemented in TFJS.然后我尝试了 TensorflowJS,但它看起来像使用 TFJS 中未实现的函数的 LinearClassifier。
  • Last I tried to user Tensorflow Lite, but there I currently have problems to convert my model to TFLite.最后我尝试使用 Tensorflow Lite,但我目前在将 model 转换为 TFLite 时遇到问题。

Do you have an idea, how I can get TF 2 Estimation of LinearClassifier running on AWS Lambda?你有什么想法,我怎样才能在 AWS Lambda 上运行 TF 2 Estimation of LinearClassifier?

Normally I think not all of the 1.5 GB Tensorflow modules are used for the simple prediction of an existing model.通常我认为并非所有 1.5 GB Tensorflow 模块都用于对现有 model 进行简单预测。 So is there a possibility to only get the files which are used for running the script?那么是否有可能只获取用于运行脚本的文件?

I have found possible answers for your question:我为您的问题找到了可能的答案:

  1. To transform in TFlite model:要在 TFlite model 中转换:
  1. To use with AWS Lambda, there are a lot of blogs but none of them is perfect.要与 AWS Lambda 一起使用,有很多博客,但没有一个是完美的。 For my case, I used tensorflow 2.3.0 to create my keras model.对于我的情况,我使用 tensorflow 2.3.0 来创建我的 keras model。 So I have to modified a little this very good tutorial:所以我不得不稍微修改一下这个非常好的教程:

For the part: "Clone TensorFlow from the official GitHub repository", we need to force a version of tensorflow because sometimes latest version is not compiling well.对于部分:“从官方 GitHub 存储库中克隆 TensorFlow”,我们需要强制使用 tensorflow 的版本,因为有时最新版本编译不好。

For my case, I want tensorflow v2.3.0, so i modified this line:对于我的情况,我想要 tensorflow v2.3.0,所以我修改了这一行:

git clone https://github.com/tensorflow/tensorflow.git

by经过

git clone --branch v.2.3.0 https://github.com/tensorflow/tensorflow.git

I have modified also at the end, to invoke lambda on AWS:最后我也进行了修改,以在 AWS 上调用 lambda:

sls invoke local -f predict

by经过

sls invoke -f predict

I recommend you to do all the tutorial with the sample model provided to be sure everything is working.我建议您使用提供的示例 model 完成所有教程,以确保一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM