

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 边缘设备
<a name="neo-edge-devices"></a>

Amazon SageMaker Neo 为常用机器学习框架提供编译支持。您可以部署 Neo 编译的边缘设备，例如 Raspberry Pi 3、Texas Instruments Sitara、Jetson TX1 等。有关支持的框架和边缘设备的完整列表，请参阅[支持的框架、设备、系统和架构](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-supported-devices-edge.html)。

您必须对边缘设备进行配置，使其能够使用 AWS 服务。一种方法是将 DLR 和 Boto3 安装到您的设备上。为此，您必须设置身份验证凭证。有关更多信息，请参阅 [Boto3 AWS 配置](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration)。编译模型并配置好边缘设备后，您可以将模型从 Amazon S3 下载到您的边缘设备。然后，您可以使用[深度学习运行时系统 (DLR)](https://neo-ai-dlr.readthedocs.io/en/latest/index.html) 来读取编译后的模型并进行推理。

对于首次使用的用户，我们建议您查看[入门](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-getting-started-edge.html)指南。本指南将向您介绍如何设置凭证、编译模型、将模型部署到 Raspberry Pi 3 以及如何对图像进行推理。

**Topics**
+ [支持的框架、设备、系统和架构](neo-supported-devices-edge.md)
+ [部署模型](neo-deployment-edge.md)
+ [在边缘设备上设置 Neo](neo-getting-started-edge.md)

# 支持的框架、设备、系统和架构
<a name="neo-supported-devices-edge"></a>

Amazon SageMaker Neo 支持常见的机器学习框架、边缘设备、操作系统和芯片架构。选择以下主题之一，了解 Neo 是否支持您的框架、边缘设备、操作系统和芯片架构。

您可以在 [经过测试的模型](neo-supported-edge-tested-models.md)部分中找到经 Amazon SageMaker Neo 团队测试过的型号列表。

**注意**  
Ambarella 设备需要在压缩的 TAR 文件中包含其他文件，然后才能将其发送出去以进行编译。有关更多信息，请参阅 [排查 Ambarella 错误](neo-troubleshooting-target-devices-ambarella.md)。
i.MX 8M Plus 需要 TIM-VX (libtim-vx.so)。有关如何构建 TIM-VX 的信息，请参阅 [TIM-VX GitHub 存储库](https://github.com/VeriSilicon/TIM-VX)。

**Topics**
+ [支持的框架](neo-supported-devices-edge-frameworks.md)
+ [支持的设备、芯片架构和系统](neo-supported-devices-edge-devices.md)
+ [经过测试的模型](neo-supported-edge-tested-models.md)

# 支持的框架
<a name="neo-supported-devices-edge-frameworks"></a>

Amazon SageMaker Neo 支持以下框架。


| 框架 | 框架版本 | 模型版本 |   模型 | 模型格式（打包为 \$1.tar.gz） | 工具包 | 
| --- | --- | --- | --- | --- | --- | 
| MXNet | 1.8 | 支持 1.8 或更早版本 | 图像分类、对象检测、语义分割、姿态估算、活动识别 | 一个符号文件 (.json) 和一个参数文件 (.params) | GluonCV v0.8.0 | 
| ONNX | 1.7 | 支持 1.7 或更早版本 | 图像分类、SVM | 一个模型文件 (.onnx) |  | 
| Keras | 2.2 | 支持 2.2 或更早版本 | 图像分类 | 一个模型定义文件 (.h5) |  | 
| PyTorch | 1.7、1.8 | 支持 1.7、1.8 或更早版本 | 图像分类、对象检测 | 一个模型定义文件 (.pth) |  | 
| TensorFlow | 1.15、2.4、2.5（仅适用于 ml.inf1.\$1 实例） | 支持 1.15、2.4、2.5（仅适用于 ml.inf1.\$1 实例）或更早版本 | 图像分类、对象检测 | \$1对于保存的模型，需要一个.pb 或一个.pbtxt 文件以及一个包含变量的变量目录 \$1对于冻结的模型，只需要一个.pb 或.pbtxt 文件 |  | 
| TensorFlow-Lite | 1.15 | 支持 1.15 或更早版本 | 图像分类、对象检测 | 一个模型定义 flatbuffer 文件 (.tflite) |  | 
| XGBoost | 1.3 | 支持 1.3 或更早版本 | 决策树 | 一个 XGBoost 模型文件 (.model)，其中树的节点数小于 2^31 |  | 
| DARKNET |  |  | 图像分类、对象检测（不支持 Yolo 模型） | 一个配置 (.cfg) 文件和一个权重 (.weights) 文件 |  | 

# 支持的设备、芯片架构和系统
<a name="neo-supported-devices-edge-devices"></a>

Amazon SageMaker Neo 支持以下设备、芯片架构和操作系统。

## 设备
<a name="neo-supported-edge-devices"></a>

您可以使用 [Amazon SageMaker AI 控制台](https://console.aws.amazon.com/sagemaker)中的下拉列表选择设备，或者在 [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateCompilationJob.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateCompilationJob.html) API 的输出配置中指定 `TargetDevice`。

您可以选择下列边缘设备之一：


| 设备列表 | 片上系统 (SoC) | 操作系统 | 架构 | Accelerator | 编译器选项示例 | 
| --- | --- | --- | --- | --- | --- | 
| aisage | 无 | Linux | ARM64 | Mali | 无 | 
| amba\$1cv2 | CV2 | Arch Linux | ARM64 | cvflow | 无 | 
| amba\$1cv22 | CV22 | Arch Linux | ARM64 | cvflow | 无 | 
| amba\$1cv25 | CV25 | Arch Linux | ARM64 | cvflow | 无 | 
| coreml | 无 | iOS、macOS | 无 | 无 | \$1"class\$1labels": "imagenet\$1labels\$11000.txt"\$1 | 
| imx8qm | NXP imx8 | Linux | ARM64 | 无 | 无 | 
| imx8mplus | i.MX 8M Plus | Linux | ARM64 | NPU | 无 | 
| jacinto\$1tda4vm | TDA4VM | Linux | ARM | TDA4VM | 无 | 
| jetson\$1nano | 无 | Linux | ARM64 | NVIDIA | \$1'gpu-code': 'sm\$153', 'trt-ver': '5.0.6', 'cuda-ver': '10.0'\$1适用于 `TensorFlow2`、`{'JETPACK_VERSION': '4.6', 'gpu_code': 'sm_72'}` | 
| jetson\$1tx1 | 无 | Linux | ARM64 | NVIDIA | \$1'gpu-code': 'sm\$153', 'trt-ver': '6.0.1', 'cuda-ver': '10.0'\$1 | 
| jetson\$1tx2 | 无 | Linux | ARM64 | NVIDIA | \$1'gpu-code': 'sm\$162', 'trt-ver': '6.0.1', 'cuda-ver': '10.0'\$1 | 
| jetson\$1xavier | 无 | Linux | ARM64 | NVIDIA | \$1'gpu-code': 'sm\$172', 'trt-ver': '5.1.6', 'cuda-ver': '10.0'\$1 | 
| qcs605 | 无 | Android | ARM64 | Mali | \$1'ANDROID\$1PLATFORM': 27\$1 | 
| qcs603 | 无 | Android | ARM64 | Mali | \$1'ANDROID\$1PLATFORM': 27\$1 | 
| rasp3b | ARM A56 | Linux | ARM\$1EABIHF | 无 | \$1'mattr': ['\$1neon']\$1 | 
| rasp4b | ARM A72 | 无 | 无 | 无 | 无 | 
| rk3288 | 无 | Linux | ARM\$1EABIHF | Mali | 无 | 
| rk3399 | 无 | Linux | ARM64 | Mali | 无 | 
| sbe\$1c | 无 | Linux | x86\$164 | 无 | \$1'mcpu': 'core-avx2'\$1 | 
| sitara\$1am57x | AM57X | Linux | ARM64 | EVE 和/或 C66x DSP | 无 | 
| x86\$1win32 | 无 | Windows 10 | X86\$132 | 无 | 无 | 
| x86\$1win64 | 无 | Windows 10 | X86\$132 | 无 | 无 | 

有关每台目标设备的 JSON 键值编译器选项的更多信息，请参阅 [`OutputConfig`API](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_OutputConfig.html) 数据类型中的 `CompilerOptions` 字段。

## 系统和芯片架构
<a name="neo-supported-edge-granular"></a>

以下查找表提供有关 Neo 模型编译作业的可用操作系统和架构的信息。

------
#### [ Linux ]


| Accelerator | X86\$164 | X86 | ARM64 | ARM\$1EABIHF | ARM\$1EABI | 
| --- | --- | --- | --- | --- | --- | 
| 没有加速器 (CPU) | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | 
| Nvidia GPU | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | 
| Intel\$1Graphics | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | 
| ARM Mali | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | 

------
#### [ Android ]


| Accelerator | X86\$164 | X86 | ARM64 | ARM\$1EABIHF | ARM\$1EABI | 
| --- | --- | --- | --- | --- | --- | 
| 没有加速器 (CPU) | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | 
| Nvidia GPU | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | 
| Intel\$1Graphics | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | 
| ARM Mali | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | 

------
#### [ Windows ]


| Accelerator | X86\$164 | X86 | ARM64 | ARM\$1EABIHF | ARM\$1EABI | 
| --- | --- | --- | --- | --- | --- | 
| 没有加速器 (CPU) | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/success_icon.svg) 是 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | ![\[alt text not found\]](http://docs.aws.amazon.com/zh_cn/sagemaker/latest/dg/images/negative_icon.svg) 否 | 

------

# 经过测试的模型
<a name="neo-supported-edge-tested-models"></a>

以下可折叠部分提供了有关经过 Amazon SageMaker Neo 团队测试的机器学习模型的信息。展开可折叠部分，根据您的框架去查看模型是否经过测试。

**注意**  
这不是可以使用 Neo 编译的模型的完整列表。

查看 [支持的框架](neo-supported-devices-edge-frameworks.md)和 [SageMaker Neo AI 支持的运算符](https://aws.amazon.com/releasenotes/sagemaker-neo-supported-frameworks-and-operators/)，了解您是否可以使用 SageMaker Neo 编译模型。

## DarkNet
<a name="collapsible-section-01"></a>


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| Alexnet |  |  |  |  |  |  |  |  |  | 
| Resnet50 | X | X |  | X | X | X |  | X | X | 
| YOLOv2 |  |  |  | X | X | X |  | X | X | 
| YOLOv2\$1tiny | X | X |  | X | X | X |  | X | X | 
| YOLOv3\$1416 |  |  |  | X | X | X |  | X | X | 
| YOLOv3\$1tiny | X | X |  | X | X | X |  | X | X | 

## MXNet
<a name="collapsible-section-02"></a>


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| Alexnet |  |  | X |  |  |  |  |  |  | 
| Densenet121 |  |  | X |  |  |  |  |  |  | 
| DenseNet201 | X | X | X | X | X | X |  | X | X | 
| GoogLeNet | X | X |  | X | X | X |  | X | X | 
| InceptionV3 |  |  |  | X | X | X |  | X | X | 
| MobileNet0.75 | X | X |  | X | X | X |  |  | X | 
| MobileNet1.0 | X | X | X | X | X | X |  |  | X | 
| MobileNetV2\$10.5 | X | X |  | X | X | X |  |  | X | 
| MobileNetV2\$11.0 | X | X | X | X | X | X | X | X | X | 
| MobileNetV3\$1Large | X | X | X | X | X | X | X | X | X | 
| MobileNetV3\$1Small | X | X | X | X | X | X | X | X | X | 
| ResNeSt50 |  |  |  | X | X |  |  | X | X | 
| ResNet18\$1v1 | X | X | X | X | X | X |  |  | X | 
| ResNet18\$1v2 | X | X |  | X | X | X |  |  | X | 
| ResNet50\$1v1 | X | X | X | X | X | X |  | X | X | 
| ResNet50\$1v2 | X | X | X | X | X | X |  | X | X | 
| ResNext101\$132x4d |  |  |  |  |  |  |  |  |  | 
| ResNext50\$132x4d | X |  | X | X | X |  |  | X | X | 
| SENet\$1154 |  |  |  | X | X | X |  | X | X | 
| SE\$1ResNext50\$132x4d | X | X |  | X | X | X |  | X | X | 
| SqueezeNet1.0 | X | X | X | X | X | X |  |  | X | 
| SqueezeNet1.1 | X | X | X | X | X | X |  | X | X | 
| VGG11 | X | X | X | X | X |  |  | X | X | 
| Xception | X | X | X | X | X | X |  | X | X | 
| darknet53 | X | X |  | X | X | X |  | X | X | 
| resnet18\$1v1b\$10.89 | X | X |  | X | X | X |  |  | X | 
| resnet50\$1v1d\$10.11 | X | X |  | X | X | X |  |  | X | 
| resnet50\$1v1d\$10.86 | X | X | X | X | X | X |  | X | X | 
| ssd\$1512\$1mobilenet1.0\$1coco | X |  | X | X | X | X |  | X | X | 
| ssd\$1512\$1mobilenet1.0\$1voc | X |  | X | X | X | X |  | X | X | 
| ssd\$1resnet50\$1v1 | X |  | X | X | X |  |  | X | X | 
| yolo3\$1darknet53\$1coco | X |  |  | X | X |  |  | X | X | 
| yolo3\$1mobilenet1.0\$1coco | X | X |  | X | X | X |  | X | X | 
| deeplab\$1resnet50 |  |  | X |  |  |  |  |  |  | 

## Keras
<a name="collapsible-section-03"></a>


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| densenet121 | X | X | X | X | X | X |  | X | X | 
| densenet201 | X | X | X | X | X | X |  |  | X | 
| inception\$1v3 | X | X |  | X | X | X |  | X | X | 
| mobilenet\$1v1 | X | X | X | X | X | X |  | X | X | 
| mobilenet\$1v2 | X | X | X | X | X | X |  | X | X | 
| resnet152\$1v1 |  |  |  | X | X |  |  |  | X | 
| resnet152\$1v2 |  |  |  | X | X |  |  |  | X | 
| resnet50\$1v1 | X | X | X | X | X |  |  | X | X | 
| resnet50\$1v2 | X | X | X | X | X | X |  | X | X | 
| vgg16 |  |  | X | X | X |  |  | X | X | 

## ONNX
<a name="collapsible-section-04"></a>


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| alexnet |  |  | X |  |  |  |  |  |  | 
| mobilenetv2-1.0 | X | X | X | X | X | X |  | X | X | 
| resnet18v1 | X |  |  | X | X |  |  |  | X | 
| resnet18v2 | X |  |  | X | X |  |  |  | X | 
| resnet50v1 | X |  | X | X | X |  |  | X | X | 
| resnet50v2 | X |  | X | X | X |  |  | X | X | 
| resnet152v1 |  |  |  | X | X | X |  |  | X | 
| resnet152v2 |  |  |  | X | X | X |  |  | X | 
| squeezenet1.1 | X |  | X | X | X | X |  | X | X | 
| vgg19 |  |  | X |  |  |  |  |  | X | 

## PyTorch (FP32)
<a name="collapsible-section-05"></a>


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Ambarella CV25 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| densenet121 | X | X | X | X | X | X | X |  | X | X | 
| inception\$1v3 |  | X |  |  | X | X | X |  | X | X | 
| resnet152 |  |  |  |  | X | X | X |  |  | X | 
| resnet18 | X | X |  |  | X | X | X |  |  | X | 
| resnet50 | X | X | X | X | X | X |  |  | X | X | 
| squeezenet1.0 | X | X |  |  | X | X | X |  |  | X | 
| squeezenet1.1 | X | X | X | X | X | X | X |  | X | X | 
| yolov4 |  |  |  |  | X | X |  |  |  |  | 
| yolov5 |  |  |  | X | X | X |  |  |  |  | 
| fasterrcnn\$1resnet50\$1fpn |  |  |  |  | X | X |  |  |  |  | 
| maskrcnn\$1resnet50\$1fpn |  |  |  |  | X | X |  |  |  |  | 

## TensorFlow
<a name="collapsible-section-06"></a>

------
#### [ TensorFlow ]


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Ambarella CV25 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| densenet201 | X | X | X | X | X | X | X |  | X | X | 
| inception\$1v3 | X | X | X |  | X | X | X |  | X | X | 
| mobilenet100\$1v1 | X | X | X |  | X | X | X |  |  | X | 
| mobilenet100\$1v2.0 | X | X | X |  | X | X | X |  | X | X | 
| mobilenet130\$1v2 | X | X |  |  | X | X | X |  |  | X | 
| mobilenet140\$1v2 | X | X | X |  | X | X | X |  | X | X | 
| resnet50\$1v1.5 | X | X |  |  | X | X | X |  | X | X | 
| resnet50\$1v2 | X | X | X | X | X | X | X |  | X | X | 
| squeezenet | X | X | X | X | X | X | X |  | X | X | 
| mask\$1rcnn\$1inception\$1resnet\$1v2 |  |  |  |  | X |  |  |  |  |  | 
| ssd\$1mobilenet\$1v2 |  |  |  |  | X | X |  |  |  |  | 
| faster\$1rcnn\$1resnet50\$1lowproposals |  |  |  |  | X |  |  |  |  |  | 
| rfcn\$1resnet101 |  |  |  |  | X |  |  |  |  |  | 

------
#### [ TensorFlow.Keras ]


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| DenseNet121  | X | X |  | X | X | X |  | X | X | 
| DenseNet201 | X | X |  | X | X | X |  |  | X | 
| InceptionV3 | X | X |  | X | X | X |  | X | X | 
| MobileNet | X | X |  | X | X | X |  | X | X | 
| MobileNetv2 | X | X |  | X | X | X |  | X | X | 
| NASNetLarge |  |  |  | X | X |  |  | X | X | 
| NASNetMobile | X | X |  | X | X | X |  | X | X | 
| ResNet101 |  |  |  | X | X | X |  |  | X | 
| ResNet101V2 |  |  |  | X | X | X |  |  | X | 
| ResNet152 |  |  |  | X | X |  |  |  | X | 
| ResNet152v2 |  |  |  | X | X |  |  |  | X | 
| ResNet50 | X | X |  | X | X |  |  | X | X | 
| ResNet50V2 | X | X |  | X | X | X |  | X | X | 
| VGG16 |  |  |  | X | X |  |  | X | X | 
| Xception | X | X |  | X | X | X |  | X | X | 

------

## TensorFlow-Lite
<a name="collapsible-section-07"></a>

------
#### [ TensorFlow-Lite (FP32) ]


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | i.MX 8M Plus | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| densenet\$12018\$104\$127 | X |  |  | X | X | X |  |  | X |  | 
| inception\$1resnet\$1v2\$12018\$104\$127 |  |  |  | X | X | X |  |  | X |  | 
| inception\$1v3\$12018\$104\$127 |  |  |  | X | X | X |  |  | X | X | 
| inception\$1v4\$12018\$104\$127 |  |  |  | X | X | X |  |  | X | X | 
| mnasnet\$10.5\$1224\$109\$107\$12018 | X |  |  | X | X | X |  |  | X |  | 
| mnasnet\$11.0\$1224\$109\$107\$12018 | X |  |  | X | X | X |  |  | X |  | 
| mnasnet\$11.3\$1224\$109\$107\$12018 | X |  |  | X | X | X |  |  | X |  | 
| mobilenet\$1v1\$10.25\$1128 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$10.25\$1224 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$10.5\$1128 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$10.5\$1224 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$10.75\$1128 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$10.75\$1224 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$11.0\$1128 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v1\$11.0\$1192 | X |  |  | X | X | X |  |  | X | X | 
| mobilenet\$1v2\$11.0\$1224 | X |  |  | X | X | X |  |  | X | X | 
| resnet\$1v2\$1101 |  |  |  | X | X | X |  |  | X |  | 
| squeezenet\$12018\$104\$127 | X |  |  | X | X | X |  |  | X |  | 

------
#### [ TensorFlow-Lite (INT8) ]


|   模型 | ARM V8 | ARM Mali | Ambarella CV22 | Nvidia | Panorama | TI TDA4VM | Qualcomm QCS603 | X86\$1Linux | X86\$1Windows | i.MX 8M Plus | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| inception\$1v1 |  |  |  |  |  |  | X |  |  | X | 
| inception\$1v2 |  |  |  |  |  |  | X |  |  | X | 
| inception\$1v3 | X |  |  |  |  | X | X |  | X | X | 
| inception\$1v4\$1299 | X |  |  |  |  | X | X |  | X | X | 
| mobilenet\$1v1\$10.25\$1128 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$10.25\$1224 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$10.5\$1128 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$10.5\$1224 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$10.75\$1128 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$10.75\$1224 | X |  |  |  |  | X | X |  | X | X | 
| mobilenet\$1v1\$11.0\$1128 | X |  |  |  |  | X |  |  | X | X | 
| mobilenet\$1v1\$11.0\$1224 | X |  |  |  |  | X | X |  | X | X | 
| mobilenet\$1v2\$11.0\$1224 | X |  |  |  |  | X | X |  | X | X | 
| deeplab-v3\$1513 |  |  |  |  |  |  | X |  |  |  | 

------

# 部署模型
<a name="neo-deployment-edge"></a>

您可以通过以下方式将计算模块部署到资源受限的边缘设备上：将编译后的模型从 Amazon S3 下载到设备并使用 [DLR](https://github.com/neo-ai/neo-ai-dlr)，也可以使用 [AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/latest/developerguide/what-is-gg.html)。

在继续操作之前，请确保 SageMaker Neo 必须支持您的边缘设备。请参阅[支持的框架、设备、系统和架构](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-supported-devices-edge.html)，以了解支持哪些边缘设备。确保您在提交编译作业时指定了目标边缘设备，请参阅[使用 Neo 编译模型](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-job-compilation.html)。

## 部署编译的模型 (DLR)
<a name="neo-deployment-dlr"></a>

[DLR](https://github.com/neo-ai/neo-ai-dlr) 是用于深度学习模型和决策树模型的紧凑型通用运行时系统。DLR 使用 [TVM](https://github.com/neo-ai/tvm) 运行时系统、[Treelite](https://treelite.readthedocs.io/en/latest/install.html) 运行时系统、NVIDIA TensorRT™，并且可以包括其他特定于硬件的运行时系统。DLR 提供了统一的 Python/C\$1\$1， APIs 用于在各种设备上加载和运行编译后的模型。

您可以使用以下 pip 命令安装最新版本的 DLR 软件包：

```
pip install dlr
```

要在 GPU 目标或非 x86 边缘设备上安装 DLR，请参阅[版本](https://github.com/neo-ai/neo-ai-dlr/releases)以获取预构建的二进制文件，或参阅[安装 DLR](https://neo-ai-dlr.readthedocs.io/en/latest/install.html) 以根据源代码构建 DLR。例如，要为 Raspberry Pi 3 安装 DLR，可以使用：

```
pip install https://neo-ai-dlr-release.s3-us-west-2.amazonaws.com/v1.3.0/pi-armv7l-raspbian4.14.71-glibc2_24-libstdcpp3_4/dlr-1.3.0-py3-none-any.whl
```

## 部署模型 (AWS IoT Greengrass)
<a name="neo-deployment-greengrass"></a>

[AWS 物联网 Greengrass](https://docs.aws.amazon.com/greengrass/latest/developerguide/what-is-gg.html) 将云功能扩展到本地设备。它使得设备可以更靠近信息源来收集和分析数据，自主响应本地事件，同时在本地网络上彼此安全地通信。借助 AWS IoT Greengrass，您可以使用云训练模型在边缘对本地生成的数据进行机器学习推理。目前，你可以在所有基于 ARM Cortex-A、英特尔凌动和 Nvidia Jetson 系列处理器的 AWS 物联网 Greengrass 设备上部署模型。有关部署 Lambda 推理应用程序以通过 Io AWS T Greengrass 执行机器学习推理的更多信息，[请参阅如何](https://docs.aws.amazon.com/greengrass/latest/developerguide/ml-dlc-console.html)使用管理控制台配置优化的机器学习推理。 AWS 

# 在边缘设备上设置 Neo
<a name="neo-getting-started-edge"></a>

这份 Amazon SageMaker Neo 入门指南向您展示了如何在设备上编译模型、设置设备和进行推断。大多数代码示例都使用 Boto3。我们在适用的 AWS CLI 情况下提供命令，以及有关如何满足 Neo 先决条件的说明。

**注意**  
您可以在本地计算机、 SageMaker 笔记本电脑、Amazon SageMaker Studio 或（视您的边缘设备而定）边缘设备上运行以下代码片段。设置类似；但是，如果您在 SageMaker 笔记本实例或 SageMaker Studio 会话中运行本指南，则有两个主要的例外情况：  
您不需要安装 Boto3。
您不需要添加 `‘AmazonSageMakerFullAccess’` IAM 策略

 本指南假设您在边缘设备上运行以下指令。

# 先决条件
<a name="neo-getting-started-edge-step0"></a>

SageMaker Neo 是一项功能，它允许您训练一次机器学习模型，然后在云端和边缘的任何位置运行它们。在使用 Neo 对模型进行编译和优化之前，需要设置一些先决条件。您必须安装必要的 Python 库，配置 AWS 证书，创建具有所需权限的 IAM 角色，并设置用于存储模型工件的 S3 存储桶。您还必须准备好经过训练的机器学习模型。以下步骤将指导您完成设置：

1. **安装 Boto3**

   如果您在边缘设备上运行这些命令，则必须安装 适用于 Python (Boto3) 的 AWS SDK。在 Python 环境（最好是虚拟环境）中，在边缘设备的终端本地或 Jupyter 笔记本实例中运行以下命令：

------
#### [ Terminal ]

   ```
   pip install boto3
   ```

------
#### [ Jupyter Notebook ]

   ```
   !pip install boto3
   ```

------

1.  **设置 AWS 凭证** 

   您需要在设备上设置 Amazon Web Services 凭证才能运行 SDK for Python (Boto3)。默认情况下， AWS 凭证应存储在边缘设备`~/.aws/credentials`上的文件中。在凭证文件中，您应该看到两个环境变量：`aws_access_key_id` 和 `aws_secret_access_key`。

   在终端中运行：

   ```
   $ more ~/.aws/credentials
   
   [default]
   aws_access_key_id = YOUR_ACCESS_KEY
   aws_secret_access_key = YOUR_SECRET_KEY
   ```

   [《AWS 通用参考指南》](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)提供有关如何获取必需的 `aws_access_key_id` 和 `aws_secret_access_key` 的说明。有关如何在设备上设置凭证的更多信息，请参阅 [Boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration) 文档。

1.  **设置 IAM 角色并附加策略。**

   Neo 需要访问您的 S3 存储桶 URI。创建可以运行 A SageMaker I 并有权访问 S3 URI 的 IAM 角色。您可以使用 SDK for Python (Boto3)、控制台或 AWS CLI创建 IAM 角色。以下示例说明如何使用 SDK for Python (Boto3) 创建 IAM 角色：

   ```
   import boto3
   
   AWS_REGION = 'aws-region'
   
   # Create an IAM client to interact with IAM
   iam_client = boto3.client('iam', region_name=AWS_REGION)
   role_name = 'role-name'
   ```

   有关如何使用控制台或通过 AWS API 创建 IAM 角色的更多信息 AWS CLI，请参阅[在您的 AWS 账户中创建 IAM 用户](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_api)。

    创建字典，用于描述您要附加的 IAM 策略。该策略用于创建新的 IAM 角色。

   ```
   policy = {
       'Statement': [
           {
               'Action': 'sts:AssumeRole',
               'Effect': 'Allow',
               'Principal': {'Service': 'sagemaker.amazonaws.com'},
           }],  
        'Version': '2012-10-17		 	 	 '
   }
   ```

   使用您在上面定义的策略创建新的 IAM 角色：

   ```
   import json 
   
   new_role = iam_client.create_role(
       AssumeRolePolicyDocument=json.dumps(policy),
       Path='/',
       RoleName=role_name
   )
   ```

   当您在后续步骤中创建编译作业时，需要知道您的 Amazon 资源名称 (ARN) 是什么，因此也将其存储在变量中。

   ```
   role_arn = new_role['Role']['Arn']
   ```

    现在，您已经创建了一个新角色，请附加该角色与 Amazon A SageMaker I 和 Amazon S3 交互所需的权限：

   ```
   iam_client.attach_role_policy(
       RoleName=role_name,
       PolicyArn='arn:aws:iam::aws:policy/AmazonSageMakerFullAccess'
   )
   
   iam_client.attach_role_policy(
       RoleName=role_name,
       PolicyArn='arn:aws:iam::aws:policy/AmazonS3FullAccess'
   );
   ```

1. **创建 Amazon S3 存储桶以存储您的模型构件**

   SageMaker Neo 将从 Amazon S3 访问你的模型工件

------
#### [ Boto3 ]

   ```
   # Create an S3 client
   s3_client = boto3.client('s3', region_name=AWS_REGION)
   
   # Name buckets
   bucket='name-of-your-bucket'
   
   # Check if bucket exists
   if boto3.resource('s3').Bucket(bucket) not in boto3.resource('s3').buckets.all():
       s3_client.create_bucket(
           Bucket=bucket,
           CreateBucketConfiguration={
               'LocationConstraint': AWS_REGION
           }
       )
   else:
       print(f'Bucket {bucket} already exists. No action needed.')
   ```

------
#### [ CLI ]

   ```
   aws s3 mb s3://'name-of-your-bucket' --region specify-your-region 
   
   # Check your bucket exists
   aws s3 ls s3://'name-of-your-bucket'/
   ```

------

1. **训练机器学习模型**

   有关如何[使用 Amazon SageMaker AI 训练机器学习模型](https://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works-training.html)的更多信息，请参阅使用 Amazon A SageMaker I 训练模型。您可以选择将在本地训练的模型直接上传到 Amazon S3 URI 存储桶中。
**注意**  
 确保模型的格式正确，具体取决于您使用的框架。请参阅 [ SageMaker Neo 期望什么输入数据形状？](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-job-compilation.html#neo-job-compilation-expected-inputs) 

   如果您还没有模型，请使用`curl`命令从 TensorFlow的网站上获取`coco_ssd_mobilenet`模型的本地副本。您刚刚复制的模型是根据 [COCO 数据集](https://cocodataset.org/#home)训练的对象检测模型。在 Jupyter 笔记本中键入以下内容：

   ```
   model_zip_filename = './coco_ssd_mobilenet_v1_1.0.zip'
   !curl http://storage.googleapis.com/download.tensorflow.org/models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip \
       --output {model_zip_filename}
   ```

   请注意，此特定示例打包在 .zip 文件中。解压缩此文件并将其重新打包为压缩的 tarfile (`.tar.gz`)，然后在后续步骤中使用。在 Jupyter 笔记本中键入以下内容：

   ```
   # Extract model from zip file
   !unzip -u {model_zip_filename}
   
   model_filename = 'detect.tflite'
   model_name = model_filename.split('.')[0]
   
   # Compress model into .tar.gz so SageMaker Neo can use it
   model_tar = model_name + '.tar.gz'
   !tar -czf {model_tar} {model_filename}
   ```

1. **将训练过的模型上传到 S3 存储桶**

   完成机器学习模式的训练后，将其存储在 S3 存储桶中。

------
#### [ Boto3 ]

   ```
   # Upload model        
   s3_client.upload_file(Filename=model_filename, Bucket=bucket, Key=model_filename)
   ```

------
#### [ CLI ]

   将 `your-model-filename` 和 `amzn-s3-demo-bucket` 替换为您的 S3 存储桶的名称。

   ```
   aws s3 cp your-model-filename s3://amzn-s3-demo-bucket
   ```

------

# 编译模型
<a name="neo-getting-started-edge-step1"></a>

满足[先决条件](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-getting-started-edge.html#neo-getting-started-edge-step0)后，即可使用 Amazon A SageMaker I Neo 编译模型。你可以使用 AWS CLI、控制台或适用于 [Python 的 Amazon Web Services SDK (Boto3)](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) 来编译模型，请参阅[使用](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-job-compilation.html) Neo 编译模型。在此示例中，您将使用 Boto3 编译模型。

要编译模型， SageMaker Neo 需要以下信息：

1.  **用于存储训练过的模型的 Amazon S3 存储桶 URI。**

   如果您符合先决条件，则存储桶的名称将存储在名为 `bucket` 的变量中。以下代码段显示如何使用 AWS CLI列出所有存储桶：

   ```
   aws s3 ls
   ```

   例如：

   ```
   $ aws s3 ls
   2020-11-02 17:08:50 bucket
   ```

1.  **要用于保存编译过的模型的 Amazon S3 存储桶 URI。**

   以下代码段将您的 Amazon S3 存储桶 URI 与名为 `output` 的输出目录的名称连在一起：

   ```
   s3_output_location = f's3://{bucket}/output'
   ```

1.  **用于训练模型的机器学习框架。**

   定义用于训练模型的框架。

   ```
   framework = 'framework-name'
   ```

   例如，如果要编译使用训练过的模型 TensorFlow，则可以使用`tflite`或`tensorflow`。`tflite`如果您想使用占用较少存储内存的较轻版本 TensorFlow ，请使用。

   ```
   framework = 'tflite'
   ```

   有关 NEO 所支持框架的完整列表，请参阅[支持的框架、设备、系统和架构](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-supported-devices-edge.html)。

1.  **模型输入的形状。**

    Neo 需要输入张量的名称和形状。名称和形状以键值对的形式传入。`value` 是输入张量的整数维度的列表，`key` 是模型中输入张量的确切名称。

   ```
   data_shape = '{"name": [tensor-shape]}'
   ```

   例如：

   ```
   data_shape = '{"normalized_input_image_tensor":[1, 300, 300, 3]}'
   ```
**注意**  
确保模型的格式正确，具体取决于您使用的框架。请参阅 [ SageMaker Neo 期望什么输入数据形状？](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-job-compilation.html#neo-job-compilation-expected-inputs) 此字典中的键必须更改为新输入张量的名称。

1.  **要编译的目标设备的名称或硬件平台的一般详细信息** 

   ```
   target_device = 'target-device-name'
   ```

   例如，如果要部署到 Raspberry Pi 3，请使用：

   ```
   target_device = 'rasp3b'
   ```

   您可以在[支持的框架、设备、系统和架构](https://docs.aws.amazon.com/sagemaker/latest/dg/neo-supported-devices-edge.html)中找到支持的边缘设备的完整列表。

 现在您已完成前面的步骤，可以向 Neo 提交编译作业。

```
# Create a SageMaker client so you can submit a compilation job
sagemaker_client = boto3.client('sagemaker', region_name=AWS_REGION)

# Give your compilation job a name
compilation_job_name = 'getting-started-demo'
print(f'Compilation job for {compilation_job_name} started')

response = sagemaker_client.create_compilation_job(
    CompilationJobName=compilation_job_name,
    RoleArn=role_arn,
    InputConfig={
        'S3Uri': s3_input_location,
        'DataInputConfig': data_shape,
        'Framework': framework.upper()
    },
    OutputConfig={
        'S3OutputLocation': s3_output_location,
        'TargetDevice': target_device 
    },
    StoppingCondition={
        'MaxRuntimeInSeconds': 900
    }
)

# Optional - Poll every 30 sec to check completion status
import time

while True:
    response = sagemaker_client.describe_compilation_job(CompilationJobName=compilation_job_name)
    if response['CompilationJobStatus'] == 'COMPLETED':
        break
    elif response['CompilationJobStatus'] == 'FAILED':
        raise RuntimeError('Compilation failed')
    print('Compiling ...')
    time.sleep(30)
print('Done!')
```

如果需要更多信息以进行调试，请包括以下打印语句：

```
print(response)
```

如果编译作业成功，则编译过的模型存储在您之前指定的输出 Amazon S3 存储桶中 (`s3_output_location`)。将编译过的模型下载到本地：

```
object_path = f'output/{model}-{target_device}.tar.gz'
neo_compiled_model = f'compiled-{model}.tar.gz'
s3_client.download_file(bucket, object_path, neo_compiled_model)
```

# 设置您的 设备
<a name="neo-getting-started-edge-step2"></a>

您需要在边缘设备上安装软件包，使设备可以进行推理。还需要安装 [AWS IoT Greengrass](https://docs.aws.amazon.com/greengrass/latest/developerguide/what-is-gg.html) 核心或[深度学习运行时系统 (DLR)](https://github.com/neo-ai/neo-ai-dlr)。在本示例中，您将安装对 `coco_ssd_mobilenet` 对象检测算法进行推理所需的软件包，并将使用 DLR。

1. **安装其他软件包**

   除 Boto3 之外，您还必须在边缘设备上安装某些库。安装哪些库因使用案例而定。

   例如，对于之前下载的`coco_ssd_mobilenet`物体检测算法，需要安装 PIL 来[NumPy](https://numpy.org/)进行数据操作和统计，需要安装 [PIL](https://pillow.readthedocs.io/en/stable/) 来加载图像，需要安装 [Matplotlib 来生成绘图](https://matplotlib.org/)。 TensorFlow 如果您想衡量使用 Neo 进行编译对比基准的影响，则还需要一份副本。

   ```
   !pip3 install numpy pillow tensorflow matplotlib 
   ```

1. **在设备上安装推理引擎**

   要运行 Neo 编译的模型，请在设备上安装[深度学习运行时系统 (DLR)](https://github.com/neo-ai/neo-ai-dlr)。DLR 是用于深度学习模型和决策树模型的紧凑型通用运行时系统。在运行 Linux 的 x86\$164 CPU 目标上，您可以使用以下 `pip` 命令安装最新版本的 DLR 软件包：

   ```
   !pip install dlr
   ```

   要在 GPU 目标或非 x86 边缘设备上安装 DLR，请参阅[版本](https://github.com/neo-ai/neo-ai-dlr/releases)以获取预构建的二进制文件，或参阅[安装 DLR](https://neo-ai-dlr.readthedocs.io/en/latest/install.html) 以根据源代码构建 DLR。例如，要为 Raspberry Pi 3 安装 DLR，可以使用：

   ```
   !pip install https://neo-ai-dlr-release.s3-us-west-2.amazonaws.com/v1.3.0/pi-armv7l-raspbian4.14.71-glibc2_24-libstdcpp3_4/dlr-1.3.0-py3-none-any.whl
   ```

# 在设备上进行推理
<a name="neo-getting-started-edge-step3"></a>

在此示例中，您将使用 Boto3 将编译作业的输出下载到边缘设备上。然后，您将导入 DLR、从数据集中下载示例映像、调整此映像的大小以匹配模型的原始输入，然后进行预测。

1. **将编译过的模型从 Amazon S3 下载到您的设备上，然后将其从压缩的 tarfile 中提取它。**

   ```
   # Download compiled model locally to edge device
   object_path = f'output/{model_name}-{target_device}.tar.gz'
   neo_compiled_model = f'compiled-{model_name}.tar.gz'
   s3_client.download_file(bucket_name, object_path, neo_compiled_model)
   
   # Extract model from .tar.gz so DLR can use it
   !mkdir ./dlr_model # make a directory to store your model (optional)
   !tar -xzvf ./compiled-detect.tar.gz --directory ./dlr_model
   ```

1. **导入 DLR 和初始化的 `DLRModel` 对象。**

   ```
   import dlr
   
   device = 'cpu'
   model = dlr.DLRModel('./dlr_model', device)
   ```

1. **下载用于推理的映像，并根据模型的训练方式确定其格式**。

   在 `coco_ssd_mobilenet` 示例中，您可以从 [COCO 数据集](https://cocodataset.org/#home)下载映像，然后将该映像改造为 `300x300`：

   ```
   from PIL import Image
   
   # Download an image for model to make a prediction
   input_image_filename = './input_image.jpg'
   !curl https://farm9.staticflickr.com/8325/8077197378_79efb4805e_z.jpg --output {input_image_filename}
   
   # Format image so model can make predictions
   resized_image = image.resize((300, 300))
   
   # Model is quantized, so convert the image to uint8
   x = np.array(resized_image).astype('uint8')
   ```

1. **使用 DLR 进行推理**。

   最后，您可以使用 DLR 对刚刚下载的映像进行预测：

   ```
   out = model.run(x)
   ```

[有关使用 DLR 从边缘设备上的 Neo 编译模型进行推断的更多示例，请参阅 Github 存储库。neo-ai-dlr ](https://github.com/neo-ai/neo-ai-dlr)