[英]Importing libraries in AWS Lambda function code from S3 bucket
I have to deploy a Deep Learning model on AWS Lambda which does object detection.我必须在执行对象检测的 AWS Lambda 上部署深度学习模型。 It is triggered on addition of image in the S3 bucket.它在 S3 存储桶中添加图像时触发。 The issue that I'm facing is that the Lambda function code uses a lot of libraries like Tensorflow, PIL, Numpy, Matplotlib, etc. and if I try adding all of them in the function code or as layers, it exceeds the 250 MB size limit.我面临的问题是 Lambda 函数代码使用了很多库,如 Tensorflow、PIL、Numpy、Matplotlib 等,如果我尝试将它们全部添加到函数代码中或作为层,它会超过 250 MB大小限制。 Is there any way I can deploy the libraries zip file on S3 bucket and use them from there in the function code (written in Python 3.6) instead of directly having them as a part of the code?有什么方法可以在 S3 存储桶上部署库 zip 文件,并从那里在函数代码(用 Python 3.6 编写)中使用它们,而不是直接将它们作为代码的一部分? I can also try some entirely different approach for this.我也可以为此尝试一些完全不同的方法。
It sounds to me like Amazon SageMaker would be a better choice for your task.在我看来,Amazon SageMaker 是您任务的更好选择。
You can create a model and host it on an endpoint all via SageMaker.您可以通过 SageMaker 创建模型并将其托管在端点上。 The use a lambda function triggered by your s3 upload to pass the image to your SageMaker endpoint and process the result.使用 s3 上传触发的 lambda 函数将图像传递到 SageMaker 端点并处理结果。
Amazon SageMaker is a fully managed service that provides every developer and data scientist with the ability to build, train, and deploy machine learning (ML) models quickly. Amazon SageMaker 是一项完全托管的服务,可为每位开发人员和数据科学家提供快速构建、训练和部署机器学习 (ML) 模型的能力。 SageMaker removes the heavy lifting from each step of the machine learning process to make it easier to develop high quality models. SageMaker 消除了机器学习过程中每一步的繁重工作,使开发高质量模型变得更加容易。
https://aws.amazon.com/sagemaker/ https://aws.amazon.com/sagemaker/
Try out pre-compiled packs for Tensorflow, they are about 50MB, you probably would have enough space for the rest of modules you need.试试 Tensorflow 的预编译包,它们大约 50MB,你可能有足够的空间来放置你需要的其余模块。 And in general, check the AWS recommendations on deep learning architecture approaches.一般来说,请查看AWS关于深度学习架构方法的建议。
Ultimately, I changed my approach from using Lambda to using EC2.最终,我将我的方法从使用 Lambda 改为使用 EC2。 I deployed the whole code with libraries on an EC2 instance and then triggered it using Lambda.我在 EC2 实例上使用库部署了整个代码,然后使用 Lambda 触发它。 On EC2, it can also be deployed on Apache server to change port mapping.在 EC2 上,它也可以部署在 Apache 服务器上以更改端口映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.