# Visual Artificial Intelligence (AI)での予測

> Visual Artificial Intelligence (AI)での予測 -
> DataRobotの画像モデルから予測を行う方法にはさまざまありますが、Base64エンコーディングとサンプルスクリプトを使用することで簡略化することができます。

This Markdown file sits beside the HTML page at the same path (with a `.md` suffix). It summarizes the topic and lists links for tools and LLM context.

Companion generated at `2026-07-15T05:55:44.970851+00:00` (UTC).

## Primary page

- [Visual Artificial Intelligence (AI)での予測](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/visual-ai/vai-predictions.html.md): Full documentation for this topic (Markdown sidecar).

## Sections on this page

- [Base64エンコーディング形式](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/visual-ai/vai-predictions.html.md#base64-encoding-format): In-page section heading.
- [サンプルスクリプト](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/visual-ai/vai-predictions.html.md#sample-scripts): In-page section heading.
- [一歩進んだ操作](https://docs.datarobot.com/ja/docs/classic-ui/modeling/special-workflows/visual-ai/vai-predictions.html.md#deep-dive): In-page section heading.

## Documentation content

画像モデルから予測を行うには、さまざまな方法があります。

| 方法 | 説明 | 参照... |
| --- | --- | --- |
| UIでの予測 | プロジェクトの作成に使用したものと同じデータセット形式を使用します（1つ以上の画像を含むZIPアーカイブをアップロードします）。 | 「予測を作成」タブ |
| モデルデプロイ：API （リアルタイム、小さなデータセット） | Base64形式を使用します（下記参照）。 | デプロイタブ（UI）予測API |
| モデルデプロイ：バッチ （大きなデータセット） | APIクライアントおよびHTTPインターフェイスのオプションについては、プロジェクトの作成に使用した元のデータセットと同じデータセット形式を使用します（つまり、1つ以上の画像を含むZIPアーカイブをアップロードしてください）。 CLIインターフェイスオプションの場合は、base64形式を使用します（以下で説明）。 | バッチ予測スクリプト |
| ポータブル予測サーバー | Base64形式を使用します（下記参照）。 | ポータブル予測サーバー |

## Base64エンコーディング形式

トレーニングデータセットが1つ以上の画像ファイルを含むZIPアーカイブで構成されている場合、予測データセットを別の形式に変換して、単一のCSVファイルに完全に格納する必要があります。

## サンプルスクリプト

画像データの変換については、以下のリンクを参照してください。

- チュートリアル： APIコール経由でVisual Artificial Intelligence (AI)プロジェクトの予測を取得する
- DataRobot Pythonパッケージ： DataRobotライブラリを使用した予測用データの準備
- スクリプト： 包括的なData Prepスクリプト

> [!NOTE] 備考
> GitHubにログインしてからこれらのGitHubリソースにアクセスしてください。

使用例を以下に示します。

`python visualai_data_prep.py pred_dataset.zip pred_dataset.csv image`

各パラメーターについて説明します。

- visualai_data_prep.py は、base64形式への変換に使用する包括的なデータ準備スクリプトです。
- pred_dataset.zip は入力データセット（画像のZIP）です。
- pred_dataset.csv は出力で、予測APIで使用できます。
- image は画像列名です。

## 一歩進んだ操作

画像ファイルのセットを単一のCSVファイルに変換するには、各画像を [base64テキスト](https://en.wikipedia.org/wiki/Base64) に変換する必要があります。 この形式によって、画像をCSVの通常のテキスト列として埋め込むことができます。 バイナリ画像データをBase64にエンコードするのは、どのプログラミング言語にもある簡単な作業です。

ここでは、Pythonでの例を示します。

```
import base64
import pandas as pd
from io import BytesIO
from PIL import Image


def image_to_base64(image: Image) -> str:
    img_bytes = BytesIO()
    image.save(img_bytes, 'jpeg', quality=90)
    image_base64 = base64.b64encode(img_bytes.getvalue()).decode('utf-8')
    return image_base64


# let's build a CSV with a single row that contains an image
# the same general approach works if you have multiple image rows or columns
image = Image.open('cat.jpg')
image_base64 = image_to_base64(image)

df = pd.DataFrame({'animal_image': [image_base64]})
df.to_csv('prediction_dataset.csv' index=False)
print(df) 
```

> [!NOTE] 備考
> バイナリ画像ファイル（デコードされたピクセルコンテンツではありません）をBase64にエンコードします。この例では `PIL.Image` を使ってファイルを開いていますが、画像ファイルを直接Base64にエンコードすることもできます。
