

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# デバイスで推論を実行する
<a name="neo-getting-started-edge-step3"></a>

この例では、Boto3 を使って、エッジデバイスにコンパイルジョブの出力をダウンロードします。次に、DLR をインポートし、データセットからサンプルイメージをダウンロードし、このイメージのサイズをモデルの元の入力に合わせて変更し、予測を行います。

1. **コンパイル済みモデルを Amazon S3 からデバイスにダウンロードし、圧縮された tar ファイルから抽出する。**

   ```
   # 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)を参照してください。