

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 디바이스에서 추론하기
<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로 컴파일된 모델을 추론하는 예제를 더 보려면 [neo-ai-dlr Github 리포지토리](https://github.com/neo-ai/neo-ai-dlr)를 참조하세요.