😽

自動運転のための大規模なVisual QAデータセット・AutoScenesQAの作成

2023/10/23に公開

本記事では、Turing のサマーインターンでの成果を紹介します。2 週間のサマーインターンで、自動運転のための Visual Question Answering データセット・AutoScenesQA の作成を行いました。

AutoScenesQA は、手作業によるアノテーションではなく、LLM(GPT 3.5)とルールベースのロジックを活用し、完全に自動で作成されています.

今回作成した AutoScenesQA は、nuScenesという自動運転用のデータセットをベースとしており、「車載カメラから撮影した 6 方向の画像(1 フレーム)」と「その画像に対応した QA のペア」で構成されています。自動生成した QA の総数は全部で約 280 万件です。

本記事では、AutoScenesQA とその作成方法に関して詳しく紹介します。

自動運転と Visual Question Answering

取り組んだ内容について説明する前に、ここでは前提知識として、作成した AutoScenesQA が対象としているタスクである Visual Question Answering とその自動運転への応用について簡単に紹介します。

近年、ChatGPT の登場を皮切りに、Large Language Model や Vision and Language といった基盤モデルの社会実装が急速に進んでいます。

Turing では、完全自動運転実現のための LLM に関する研究開発を進めています。また、今年 7 月には日英両対応の Vision and Language 用のライブラリHeronをリリースしました。

今回構築したデータセット AutoScenesQA は Vision and Language の中でもVisual Question Answering (VQA)への応用を想定しています。VQA は、「ある画像」と「その画像に関する質問(Question)」に対して、「正しい答え」を出力するタスクです。

例えば、車の前左部(front left)に搭載されたカメラから撮影された以下のような画像を想定します。

VQA では、この画像に対し「Are there any pedestrians to the front left of the car ?(車の前左部には歩行者がいますか?)」のような自然文の質問を入力し、「Yes, there are 2 pedestrians in the front left of the car.(はい、車の前左部には 2 人の歩行者がいます。)」のような自然文での正しい回答を出力が得られるように、機械学習モデルの学習を行います。

ここで自動運転 x VQA に関する研究を 2 つほど紹介します

まず、NuScenes-QAです。NuScenes-QA 論文は、後述する nuScenes というデータセットをベースとして、VQA 用のデータセット NuScenes-QA を作成し、MCANという VQA モデルを用いてベースライン検証を行いました。

この研究では、事前に定義したテンプレートに、もとのデータセットである nuScenes に格納された車の周辺物体(車両、人、信号機…etc)の 3D BoundingBox 情報や物体の個数を埋め込んでいくルールベースなロジックを実装し、QA を作成しています。nuScenes に含まれる 34,149 件の 6 方向画像(1 フレーム)に対して、459,941 件の Question Answering のペアを作成しました。

次にDriveLMです。DriveLM も NuScenes-QA 同様, nuScenes を用いて、VQA のデータセットを作成しました。 NuScenes-QA がルールベースのロジックを実装し完全自動で生成していたのに対し、DriveLM は人手で、nuScenes の 34,149 件の 6 方向画像に対しアノテーションを行い、約 36 万件程度の QA ペアを作成しました。

DriveLM では、

  • 周辺の重要物体の現在の状況に関する質問をするPerception
  • 主に周辺の重要物体がどの方向に進むか、などの将来的な状況に関する質問をするPrediction
  • 周辺物体の状況等から次にどのような行動をとるべきかを計画するPlanning

の 3 つに分類を定義し、それぞれの種類に対して、人手で作成を行なっています。

Perception < Prediction < Planning の順に、正しい回答をするために、より人間的な思考が求められます。

DriveLM

なお、DriveLM は、データセットの一部である QA のデモデータが公開されているのみで、論文・データセットいずれも 10 月 23 日時点で未公開です。

以上が先行研究の紹介です。今回のインターンでは、これらの先行研究を参考にしつつ、nuScenes をベースとした 新たな VQA データセットの構築および自動でデータセットを構築する仕組みの実装に取り組みました。

AutoScenesQA

早速ですが、成果物の紹介です。インターンを通して、自動運転のための Visual Question Answering データセット・AutoScenesQA を作成しました

すでに述べたとおり、AutoScenesQA は、自動運転における非常にポピュラーなデータセットの一つである nuScenes をベースにしています。 nuScenes は、6 方向に取り付けられたカメラから撮影された車周辺の画像と周辺に存在する物体の 3D Bounding Box が保存されています。

AutoScenesQA は、「nuScenes の 1 フレームにおける 6 方向の画像」と「画像に対応する Question Answer 形式の状況説明文」がペアになったデータセットです。 DriveLM 同様、QA を Perception, Prediction, Planning の 3 分類とし、データセットは、Perception の QA が格納されたperception.jsonと Prediction & Planning の QA が格納されたprediction_and_plan.jsonの 2 つのファイルから構成されます。

AutoScenesQA には Question-Answering のペアが約 280 万件格納されています。より詳細には

  • Perception(perception.json): 2,842,088 件
  • Prediction & Planning(prediction_and_plan.json): 7,000 件

から構成されています。なお、既に述べたとおり、これらの QA は、LLM とルールベースのロジックを駆使して、全て自動で生成しました。

以降の章では、この AutoScenesQA の作成過程に関して、詳しく説明していきます。

GPT-4 による Visual Question Answering の自動生成

Question Answering を、完全に自動で生成するにあたって、まず最初に検討したのは、Open AI の GPT-4 により全ての QA を自動生成することでした。API から GPT-4 を呼び出すことで、ゼロショットの Question Answering の自動生成を試みました。

ここで、GPT-4 をはじめとする Open AI が提供するサービスには、OpenAI が提供するモデルからの出力を競合するモデルの開発に利用してはならない、という規約があります。そのため利用には慎重になる必要がありますが、今回はあくまで研究用途であることと 自動運転のための VQA タスクは OpenAI が提供するモデルと直接的な競合にはならないと判断し、使用することにしました。

入力したプロンプト

GPT に入力したプロンプトを説明します。

Question-Answering の生成には、画像情報等は一旦用いず、nuScenes に元から格納されていた周辺物体の BoundingBox 情報とそれらを事前に加工した値を入力としました。

nuScenes に格納された車周辺の Bounding Box 情報を元に「撮影者からの相対座標・絶対距離」「カメラが搭載された 6 方向(front, front right, back right, back, back left, front left)のそれぞれにどんな物体が存在するか」と言った情報を事前に計算して、GPT-4 に入力しています。

具体的には以下のフォーマットでそれらの情報を入力しました。

1. Ego-car states:
- Coordinates: (0, 0)

2. List of important objects around the ego-car:

- <adult pedestrian> at (38.122637509683614, 50.66899505384981), moving to (38.122637509683614, 50.66899505384981). Distance from the car: 42.72m
- ...

3. Important objects and its count on six directions:

**front of the ego car**

- '<adult pedestrian>': 17, '<car>': 7, '<bicycle>': 1, '<barrier>': 19, '<truck>': 2, '<construction vehicle>': 1, '<pushable or pullable object>': 1

**front right of the ego car**

ユーザの入力プロンプトは 3 セクションに分かれており、それぞれ以下の情報が記載されています.

  1. Ego-car states: Ego-car(運転車)の xy 座標
  2. List of important objects around the ego-car: Ego-car(運転車)周辺の重要物体の xy 座標(Ego-car 基準)と ego-car との絶対距離(m)
  3. Important objects and its count on six directions: 6 方向それぞれに対して、どの物体が何個存在するか、を'{物体名}':{個数}の形式で記載

また、GPT-4 の全体的な振る舞いを決定づけるシステムプロンプトは、以下になります。

**Overall Role**

- You are a very attentive car drive, always looking around your surroundings.
- Please output a detailed situation description to the "handle_drive" function based on the information provided.
- The car is operated based on the information you input into "handle_drive".

**Input Format**
User input can be divided into the following three sections:

1. "Ego-car states": Information about the state of car you are driving.
2. "List of important objects around the ego-car": A list of the 'coordinates' and 'intended movement coordinates' of objects around the car you are driving, as well as the 'absolute distance' from the car you are riding in.
3. "Important objects and its count on six directions"

**Output Format**

- Describe the situation in the format of a "question" and an "answer".
- Provide a json format object list of "question" and "answer" pairs to "question_answer_list" that describe the situation.

**Rules and Precautions**

- Make the questions general in content and do not include information specific to the situation the user has entered. For example, "What is the important object behind the ego car?", "Is there any pedestrian?".
- Output various questions and answers for all directions
- **Provide 50 QA pairs at least.**
- Please answer politely.

こちらは 4 つのセクションから分かれており、それぞれ以下の情報が記載されています.

  • Overall Role: GPT に「あなたは注意深いドライバーで周囲に常に注意を払っている」という役割を認識させる。その上で、後述する Function Calling のhandle_driveに周辺状況の説明を QA 形式で出力するように伝える。
  • Input Format: 前述したユーザの入力プロンプトのフォーマットとそれぞれのセクションに何が書かれているか、を伝える
  • Output Format: questionanswerというキーを持つ json の配列形式で出力するように伝える
  • Rules and Precautions: 「50 程度の QA を生成すること」や「answerを丁寧に記述すること」等を伝える。

Function Calling の利用

繰り返し述べているように、今回生成するのは Question Answering 形式のデータセットです。単なる状況説明文ではなく、このように、形式を確実に指定したいときに便利なのが、OpenAI の Function Calling です。

Function Calling で出力スキーマを指定することで、確実に Question-Answering 形式のデータセットを出力するようにしました。以下のhandle_driveという Function を定義し、必ずこの Function を呼び出すように設定しました。

functions_schema = [
    {
        "name": "handle_drive",
        "description": "operate car based on input 'question' and 'answer'",
        "parameters": {
            "type": "object",
            "properties": {
                "question": {
                    "type": "string",
                    "description": "Question that asks about the surrounding situation.",
                },
                "answer": {
                    "type": "string",
                    "description": "Answer for question that describe surrounding situation.",
                },
            },
            "required": ["question", "answer"],
        },
    }
]

出力結果

以上の入力・設定を行い、GPT-4 から得られた出力が以下になります。

GPT-4 による Question-Answering の生成結果
{
  "question_answer_list": [
    {
      "question": "What is the important object in front left of the ego car?",
      "answer": "There is 1 adult pedestrian and 1 truck in front left of the ego car."
    },
    {
      "question": "How many important objects are there in front of the ego car?",
      "answer": "In front of the ego car, there are 17 adult pedestrians, 7 cars, 1 bicycle, 19 barriers, 2 trucks, 1 construction vehicle and 1 pushable or pullable object."
    },
    {
      "question": "What objects are in front right of the ego car?",
      "answer": "In front right of the ego car, there are 8 adult pedestrians, 3 cars, 6 barriers and 1 traffic cone."
    },
    {
      "question": "How many pedestrians are in the back left of the ego vehicle?",
      "answer": "There are 2 adult pedestrians in the back left of the ego vehicle."
    },
    {
      "question": "What objects are behind the ego car?",
      "answer": "Behind the ego car, there are 2 traffic cones, 1 car, 2 barriers, 4 adult pedestrians, and 1 rigid bus."
    },
    {
      "question": "How many important objects are there in the back right of the ego vehicle?",
      "answer": "In the back right of the car, there are 4 adult pedestrians and 1 barrier."
    },
    {
      "question": "Is there any pedestrian in sight?",
      "answer": "Yes, there are pedestrians in all directions."
    },
    {
      "question": "Is there any car in sight?",
      "answer": "Yes, there are cars in the front and the back."
    },
    {
      "question": "Is there any barriers in sight?",
      "answer": "Yes, there are barriers in all directions."
    },
    {
      "question": "Is there any truck in sight?",
      "answer": "Yes, there are trucks in the front and the front left."
    },
    {
      "question": "Is there any construction vehicle in sight?",
      "answer": "Yes, there is 1 construction vehicle in the front."
    },
    {
      "question": "Is there any traffic cone in sight?",
      "answer": "Yes, there are traffic cones in front right and back."
    },
    {
      "question": "Is there any rigid bus in sight?",
      "answer": "Yes, there is 1 rigid bus in the back."
    },
    {
      "question": "Is there any bicycle in sight?",
      "answer": "Yes, there is 1 bicycle in front."
    },
    {
      "question": "Is there any pushable or pullable object in sight?",
      "answer": "Yes, there is 1 pushable or pullable object in front."
    },
    {
      "question": "Are there any moving objects in front left of the car?",
      "answer": "Yes, there are moving objects in front left of the car."
    },
    {
      "question": "Are there any stationary objects in front left of the car?",
      "answer": "No, there are not any stationary objects in front left of the car."
    },
    {
      "question": "Are there any moving objects in front of the car?",
      "answer": "Yes, there are moving objects in front of the car."
    },
    {
      "question": "Are there any stationary objects in front of the car?",
      "answer": "Yes, there are stationary objects in front of the car."
    },
    {
      "question": "Are there any moving objects in front right of the car?",
      "answer": "Yes, there are moving objects in front right of the car."
    },
    {
      "question": "Are there any stationary objects in front right of the car?",
      "answer": "Yes, there are stationary objects in front right of the car."
    },
    {
      "question": "Are there any moving objects in back left of the car?",
      "answer": "Yes, there are moving objects in back left of the car."
    },
    {
      "question": "Are there any stationary objects in back left of the car?",
      "answer": "No, there are not any stationary objects in back left of the car."
    },
    {
      "question": "Are there any moving objects behind the car?",
      "answer": "Yes, there are moving objects behind the car."
    },
    {
      "question": "Are there any stationary objects behind the car?",
      "answer": "No, there are not any stationary objects behind the car."
    },
    {
      "question": "Are there any moving objects in back right of the car?",
      "answer": "Yes, there are moving objects in back right of the car."
    },
    {
      "question": "Are there any stationary objects in back right of the car?",
      "answer": "No, there are not any stationary objects in back right of the car."
    },
    {
      "question": "What is the closest object to the ego vehicle?",
      "answer": "The closest object to the ego vehicle is the traffic cone at the back, with a distance of 10.05 meters."
    },
    {
      "question": "What is the farthest object from the ego vehicle?",
      "answer": "The farthest object from the ego vehicle is the car at the front, at a distance of 81.44 meters."
    },
    {
      "question": "Are there any objects that could potentially block the path of the ego car?",
      "answer": "Yes, there are barriers in all directions that could potentially block the path of the ego car."
    },
    {
      "question": "Do any of the pedestrians pose a potential threat to the ego car?",
      "answer": "Yes, there are several pedestrians moving in various directions that could potentially intersect with the path of the ego car."
    },
    {
      "question": "Are there any large vehicles in close proximity to the ego car?",
      "answer": "Yes, there is a truck in front left at a distance of 17.05 meters and a rigid bus at the back at a distance of 53.27 meters."
    },
    {
      "question": "Are there objects rapidly approaching the ego vehicle?",
      "answer": "It is uncertain as it depends on their speed and direction, but there are several moving objects in all directions."
    },
    {
      "question": "Do any of the cars pose a potential threat to the ego car?",
      "answer": "Yes, there are several cars moving in different directions that could potentially intersect with the path of the ego car."
    },
    {
      "question": "Is the path in front of the ego car clear?",
      "answer": "No, the path in front of the ego car is not clear with various objects including pedestrians, cars, barriers, a truck, a construction vehicle and a pushable or pullable object."
    },
    {
      "question": "How many obstructions are in front of the car?",
      "answer": "There are 48 obstructions in front of the car."
    },
    {
      "question": "Do we have any obstructions on our left?",
      "answer": "Yes, we do have obstructions – 1 adult pedestrian and 1 truck on front left and 2 adult pedestrians on back left."
    },
    {
      "question": "Do we have any obstructions on our right?",
      "answer": "Yes, we do have obstructions – 8 adult pedestrians, 3 cars, 6 barriers and 1 traffic cone on front right and 4 adult pedestrians and 1 barrier on back right."
    },
    {
      "question": "Do we have any obstructions at our back?",
      "answer": "Yes, we do have obstructions – 2 traffic cones, 1 car, 2 barriers, 4 adult pedestrians, and 1 rigid bus."
    }
  ]
}

あくまで定性的な評価ではありますが、一見 DriveLM とほぼ同等で、多様な QA が生成できているように見受けられます.

しかし、この GPT-4 での生成には、上に示した 1 フレーム・ 6 方向画像に対して 50 問程度の QA を生成するのにも2 分半程度の実行時間がかかります.

nuScenes には、既に 30000 以上のフレームが格納されています。単純計算で、30000 x 2.5(分) = 75000 分 = 約 52 日。マルチスレッドによる高速化ができるとはいえ、OpenAI API には使用制限があることも考慮すると、これは現実的なコストとはいえません。

そのため、GPT-4 による全フレームに対する Question Answering の生成は諦め、生成方法を再考することにしました。

ここで、GPT-4 が生成した先ほどの QA や DriveLM のデモデータに含まれていた QA を注意深く観察すると、

Q. What objects are in front right of the ego car?
A. In front right of the ego car, there are 8 adult pedestrians, 3 cars, 6 barriers and 1 traffic cone.

のように GPT を活用せずとも、特に状況把握のための QA である Perception に関しては、ルールベースなロジックで BoundingBox の情報を処理することで、生成できそうな QA も多く含まれていることがわかります。

そこで、Perception のようなシンプルな QA はルールベースなロジックで生成し、Prediction や Planning のように思考を必要とする一部 QA のみ、GPT で生成する、という方針に転換を行い、実行時間の節約を目指しました。

ルールベース + GPT3.5 による Visual Question Answering の自動生成

ルールベースによる Perception の生成

既に述べた通り、現在の周囲状況を把握するために用いられる QA である Perception に関してはルールベースのロジックを実装し、QA を生成します。

まず、DriveLM や GPT-4 で生成した質問文を観察し、BoundingBox を用いたルールベースのロジックにより生成可能な Perception の QA を以下の 5 種類に分類しました。

  • Important Object Count and Direction: 特定の方向に存在する重要な物体とその個数を聞く質問
  • Object Presence Confirmation: 特定方向に、特定の物体が存在するかどうかを確認する質問:
  • Object State Inquiry: 物体の状態(動いているか、いないか)に関する質問
  • Relative Distance to Vehicles: 周辺物体と自車との距離に関する質問
  • Object Location Coordinates: 周辺の物体の位置座標情報に関する質問

上の 5 分類のそれぞれに対して,2 ~ 3 個のテンプレートを用意し、各 6 方向画像に対し、網羅的に QA の生成を行いました。

以下が生成した QA の一部です。

[
    {
        "sample_token": "e93e98b63d3b40209056d129dc53ceee",
        "question": "What is the important object in front left of the ego car?",
        "answer": "There are 3 trucks in front left of the ego car.",
        "question_type": "important_object_count_and_direction"
    },
    {
        "sample_token": "e93e98b63d3b40209056d129dc53ceee",
        "question": "How many important objects are there in front left of the ego car?",
        "answer": "In front left of the ego car, there are 3 trucks.",
        "question_type": "important_object_count_and_direction"
    },
    {
        "sample_token": "e93e98b63d3b40209056d129dc53ceee",
        "question": "Is the path in front left of the ego car clear?",
        "answer": "No, the path in front left of the ego car is not clear with various objects including trucks.",
        "question_type": "important_object_count_and_direction"
    },
    ...

34,149 枚の画像全てに対して、テンプレート・方向・物体全て網羅的に QA の生成を行い、上のような QA を計 2,842,088 件(約 280 万件)生成しました。

GPT3.5 による Prediction & Planning の生成

Prediction と Planning のように思考を必要とするような QA に関しては、GPT を用いて生成を行いました。プロンプト等の設定に関しては、基本的には GPT-4 による生成の章で紹介したのと同じプロンプトを使用しています。

一部、生成される QA にルールベースで生成した Perception を含めず、 Prediction と Planning のみに限定することを目的とし、以下の文章をシステムプロンプトのOverall Roleの章に追記しました。

- The pairs of "question" and "answer" you output can be categorized into two types: **Prediction** and **Planning**.
- Prediction is a pair of questions and answers asking about the future situation of significant objects around the ego-car. For example, you can mention pairs like question: "What is the future state of ego-vehicle?", answer: "The action is to maintain speed keep on go ahead, the reason is to keep a safe distance, high.".
- Planning is a pair of questions and answers that, based on the future situation of significant objects around the ego-car, formulates a reasonable plan and avoids dangerous actions. For example, you can mention pairs like question: "Based on the observation of back, what actions might the ego-vehicle take? What is the reason to take this action? What is the probability of taking this action?", answer: "The action is to go ahead, the reason is to keep a safe distance, high.".

また、Function Calling のスキーマに、questionanswerに加え、出力した QA がpredictionplanningのどちらなのか、を示すquestion_typeというフィールドを追加しました.

    "properties": {
                ...
                "question_type": {
                    "type": "string",
                    "enum": ["prediction", "planning"],
                    "description": 'Question Type: "prediction" or "planning" ',
                }
            }
            ...

以上の設定を行った上で GPT3.5 を用いて、生成した QA の一部が以下になります。

[
  {
    "sample_token": "b94e98e801444b00ae1f120ab8f833e1",
    "question": "What possible dangers can arise from the surrounding situation?",
    "answer": "There are two cars in front of the ego car, one car and one bicycle behind the ego car. An adult pedestrian is also behind the ego car. These objects pose a potential risk of collision."
  },
  {
    "sample_token": "24959f3f5c6b4ce6a2ed1c54d7f5e3e7",
    "question": "Based on the observation of back right of the ego car, what actions might the ego-car take?",
    "answer": "The ego-car should maintain its current speed and keep a safe distance from the objects in the back right. The probability of taking this action is high."
  }
  ...

上のような方法で QA のペアを合計 7,000 件生成しました。今回は、インターンの期間的な都合で、GPT-4 を使った大量の Question-Answering の生成が間に合わず、Prediction and Planning の生成には GPT3.5 を用いました。また、生成した QA の数も Perception と比較すると非常に少ないです。この辺りは、今後改善していきたいと考えています。

まとめ

以上が 2 週間のインターンで取り組んだ内容の説明になります!

今回のインターンでは、約 280 万件の Question Answering からなる QA データセット AutoScenesQA の作成に取り組みました。AutoScenesQA は大部分の Perception をルールベースのロジックで生成し、Prediction & Planning を GPT 3.5 で生成しました。

今回作成した AutoScenesQA ですが、2 週間という時間的な制約の中で作成したこともあって、まだまだ改善の余地があります。具体的には以下のような課題・改善点が挙げられます。

  • QA の多様性が低い(特にルールベースで作成した Perception)
  • Prediction and Planning について、GPT 3.5 による生成では多様性が低いため、GPT 4 を利用した生成が必要(大量生成しようとした際に API 制限の都合で断念せざるを得なかった)
  • 現状、Bonding Box の情報しか入力できていないため、画像情報を何らかの方法で抽出し、その情報をベースとした QA も自動生成したい

この辺りの改善については今後の Future Work として取り組んでいきたいです。

今回のインターンを通して、自動運転の LLM 応用に関する直近の研究動向を知るとともに、実応用も見据えた大規模な QA データセットの作成にも取り組むことができました。優秀なエンジニア・リサーチャーの方々と最新研究をベースとした議論ができるというのは、本当に楽しく、とても有意義な時間であったと思います!Turing の方々に、改めて御礼申し上げます。

Turing でのインターンは、強い人達に囲まれて、自動運転や LLM といったテーマに関した研究開発がしてみたい!という学生には是非ともお勧めしたいインターンです。(成果がいい感じであれば国際会議への投稿もあるとか。)

Turing はインターンや新卒・中途の採用を絶賛募集中です。興味があるという方は Turing の公式サイト採用情報をご覧ください。カジュアルに話を聞いてみたいという方は、リサーチチームの棚橋さん井ノ上さん、AI ディレクターの山口さんの Twitter DM にお気軽にご連絡ください。

GitHubで編集を提案
Tech Blog - Turing

Discussion