|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +import argparse |
| 17 | +import os |
| 18 | + |
| 19 | +from tqdm import tqdm |
| 20 | + |
| 21 | + |
| 22 | +"""example command |
| 23 | +python create_prompts_for_gr1_dataset.py --dataset_path datasets/benchmark_train/gr1 |
| 24 | +""" |
| 25 | + |
| 26 | + |
| 27 | +def parse_args() -> argparse.ArgumentParser: |
| 28 | + parser = argparse.ArgumentParser(description="Create text prompts for GR1 dataset") |
| 29 | + parser.add_argument( |
| 30 | + "--dataset_path", type=str, default="datasets/benchmark_train/gr1", help="Root path to the dataset" |
| 31 | + ) |
| 32 | + parser.add_argument( |
| 33 | + "--prompt_prefix", type=str, default="The robot arm is performing a task. ", help="Prefix of the prompt" |
| 34 | + ) |
| 35 | + parser.add_argument( |
| 36 | + "--meta_csv", type=str, default=None, help="Metadata csv file (defaults to <dataset_path>/metadata.csv)" |
| 37 | + ) |
| 38 | + return parser.parse_args() |
| 39 | + |
| 40 | + |
| 41 | +def main(args) -> None: |
| 42 | + meta_csv = args.meta_csv or os.path.join(args.dataset_path, "metadata.csv") |
| 43 | + meta_lines = open(meta_csv).readlines()[1:] |
| 44 | + meta_txt_dir = os.path.join(args.dataset_path, "metas") |
| 45 | + os.makedirs(meta_txt_dir, exist_ok=True) |
| 46 | + |
| 47 | + for meta_line in tqdm(meta_lines): |
| 48 | + video_filename, prompt = meta_line.split(",", 1) |
| 49 | + prompt = prompt.strip("\n") |
| 50 | + if prompt.startswith('"') and prompt.endswith('"'): |
| 51 | + # Remove the quotes |
| 52 | + prompt = prompt[1:-1] |
| 53 | + prompt = args.prompt_prefix + prompt |
| 54 | + meta_txt_filename = os.path.join(meta_txt_dir, os.path.basename(video_filename).replace(".mp4", ".txt")) |
| 55 | + with open(meta_txt_filename, "w") as fp: |
| 56 | + fp.write(prompt) |
| 57 | + |
| 58 | + print(f"encoding prompt: {prompt}") |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + args = parse_args() |
| 63 | + main(args) |
0 commit comments