项目简介
本项目借助Amazon Sagemaker平台达成快速人脸检测功能。运用Sagemaker的Notebook Instance、Ground Truth、Training jobs和Endpoint等特性,实现从数据标记、模型训练到模型部署的完整流程,为用户提供便捷的人脸检测服务。
项目的主要特性和功能
- 灵活的数据处理:支持将数据直接上传到S3,可通过代码或手动方式操作。利用Ground Truth进行数据标记,支持bounding box任务类型,AWS会提供人力协助标记。
- 多样的模型训练方式:提供多种训练选择,如使用内建演算法、自定义演算法、自己准备Container等。以Vision - Object Detection (MxNet)内建演算法为例,能根据不同业务情境和资料格式设置参数。
- 丰富的模型部署方案:支持即时同步推论、非同步推论和无伺服器推论三种Sagemaker Serving方式,可依据业务需求和流量特点选择合适方案,无伺服器端点可根据流量自动扩缩计算资源。
- 便捷的模型推论:建立端点后,使用Python进行API呼叫,输入格式统一为二进位的资料格式或序列数值化资料,便于人脸检测。
- 产品优势:支持多人脸检测,实时反馈结果,通过图形化界面展示,支持跨平台使用。采用云服务部署,具备良好的可扩展性和可维护性,能应对大量并发请求和用户量增长。
安装使用步骤
资料准备
- 代码方式:在可访问AWS的环境(如Sagemaker Notebook Instance)中,执行以下代码将资料下载到S3: ```python import sagemaker
sess = sagemaker.Session() bucket = sess.default_bucket()
!aws s3 sync s3://sagemaker-sample-files/datasets/image/caltech-101/inference/ s3://{bucket}/ground-truth-demo/images/
print('Copy and paste the below link into a web browser to confirm the ten images were successfully uploaded to your bucket:') print(f'https://s3.console.aws.amazon.com/s3/buckets/{bucket}/ground-truth-demo/images/')
print('\nWhen prompted by Sagemaker to enter the S3 location for input datasets, you can paste in the below S3 URL') print(f's3://{bucket}/ground-truth-demo/images/')
print('\nWhen prompted by Sagemaker to Specify a new location, you can paste in the below S3 URL') print(f's3://{bucket}/ground-truth-demo/labeled-data/') ``` 2. 手动方式:上网搜索5张包含人脸的照片,存于指定目录后,手动放入自己账号的S3 bucket。
资料标记
- 在Sagemaker的Ground Truth中选择Labeling jobs -> Create labeling jobs。
- 选择预先建立好的S3位置,任务类型选择bounding box,详细描述任务。
- 标记完成后,选择「输出资料及位置」,记录manifests/output/output.manifest的S3位置。
模型训练
- 在Sagemaker主控台左侧,选择「培訓」->「訓練任務」->「建立訓練任務」。
- 选择Sagemaker内建的演算法Vision - Object Detection (MxNet)。
- 设定「输入资料组态」,使用两个channel:「train」、「validation」,设置属性名称「AttributeNames」,S3位置为Ground Truth标记完的output.manifest位置,「纪录包装函式」RecordWrapperType选择「RecordIO」。
- 建立训练任务,等待训练完成。
模型部署
- 建立端点组态(configuration),选择「无伺服器端點」,变体选择训练好的模型,编辑(4 GB记忆体),建立端点组态。
- 选择建立端点,选择刚建立好的端点组态,建立端点(大约等待几分钟)。
模型推论
使用以下Python代码进行API呼叫: ```python import boto3 import json
runtime = boto3.client("sagemaker-runtime", region_name="your_region") endpoint_name = "your_name"
with open("./inference_data/face1.jpeg", "rb") as image: f = image.read() b = bytearray(f) endpoint_response = runtime.invoke_endpoint(EndpointName=endpoint_name, ContentType="image/jpeg", Body=b) results = endpoint_response["Body"].read() ```
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】