|
| 1 | +""" |
| 2 | +This file contains all obsolete download scripts. They are centralized here to not have to load |
| 3 | +useless dependencies when using datasets. |
| 4 | +""" |
| 5 | + |
| 6 | +import io |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import tqdm |
| 10 | + |
| 11 | + |
| 12 | +def download_raw(root, dataset_id) -> Path: |
| 13 | + if "pusht" in dataset_id: |
| 14 | + return download_pusht(root=root, dataset_id=dataset_id) |
| 15 | + elif "xarm" in dataset_id: |
| 16 | + return download_xarm(root=root, dataset_id=dataset_id) |
| 17 | + elif "aloha" in dataset_id: |
| 18 | + return download_aloha(root=root, dataset_id=dataset_id) |
| 19 | + elif "umi" in dataset_id: |
| 20 | + return download_umi(root=root, dataset_id=dataset_id) |
| 21 | + else: |
| 22 | + raise ValueError(dataset_id) |
| 23 | + |
| 24 | + |
| 25 | +def download_and_extract_zip(url: str, destination_folder: Path) -> bool: |
| 26 | + import zipfile |
| 27 | + |
| 28 | + import requests |
| 29 | + |
| 30 | + print(f"downloading from {url}") |
| 31 | + response = requests.get(url, stream=True) |
| 32 | + if response.status_code == 200: |
| 33 | + total_size = int(response.headers.get("content-length", 0)) |
| 34 | + progress_bar = tqdm.tqdm(total=total_size, unit="B", unit_scale=True) |
| 35 | + |
| 36 | + zip_file = io.BytesIO() |
| 37 | + for chunk in response.iter_content(chunk_size=1024): |
| 38 | + if chunk: |
| 39 | + zip_file.write(chunk) |
| 40 | + progress_bar.update(len(chunk)) |
| 41 | + |
| 42 | + progress_bar.close() |
| 43 | + |
| 44 | + zip_file.seek(0) |
| 45 | + |
| 46 | + with zipfile.ZipFile(zip_file, "r") as zip_ref: |
| 47 | + zip_ref.extractall(destination_folder) |
| 48 | + return True |
| 49 | + else: |
| 50 | + return False |
| 51 | + |
| 52 | + |
| 53 | +def download_pusht(root: str, dataset_id: str = "pusht", fps: int = 10) -> Path: |
| 54 | + pusht_url = "https://diffusion-policy.cs.columbia.edu/data/training/pusht.zip" |
| 55 | + pusht_zarr = Path("pusht/pusht_cchi_v7_replay.zarr") |
| 56 | + |
| 57 | + root = Path(root) |
| 58 | + raw_dir: Path = root / f"{dataset_id}_raw" |
| 59 | + zarr_path: Path = (raw_dir / pusht_zarr).resolve() |
| 60 | + if not zarr_path.is_dir(): |
| 61 | + raw_dir.mkdir(parents=True, exist_ok=True) |
| 62 | + download_and_extract_zip(pusht_url, raw_dir) |
| 63 | + return zarr_path |
| 64 | + |
| 65 | + |
| 66 | +def download_xarm(root: str, dataset_id: str, fps: int = 15) -> Path: |
| 67 | + root = Path(root) |
| 68 | + raw_dir: Path = root / "xarm_datasets_raw" |
| 69 | + if not raw_dir.exists(): |
| 70 | + import zipfile |
| 71 | + |
| 72 | + import gdown |
| 73 | + |
| 74 | + raw_dir.mkdir(parents=True, exist_ok=True) |
| 75 | + # from https://github.com/fyhMer/fowm/blob/main/scripts/download_datasets.py |
| 76 | + url = "https://drive.google.com/uc?id=1nhxpykGtPDhmQKm-_B8zBSywVRdgeVya" |
| 77 | + zip_path = raw_dir / "data.zip" |
| 78 | + gdown.download(url, str(zip_path), quiet=False) |
| 79 | + print("Extracting...") |
| 80 | + with zipfile.ZipFile(str(zip_path), "r") as zip_f: |
| 81 | + for member in zip_f.namelist(): |
| 82 | + if member.startswith("data/xarm") and member.endswith(".pkl"): |
| 83 | + print(member) |
| 84 | + zip_f.extract(member=member) |
| 85 | + zip_path.unlink() |
| 86 | + |
| 87 | + dataset_path: Path = root / f"{dataset_id}" |
| 88 | + return dataset_path |
| 89 | + |
| 90 | + |
| 91 | +def download_aloha(root: str, dataset_id: str) -> Path: |
| 92 | + folder_urls = { |
| 93 | + "aloha_sim_insertion_human": "https://drive.google.com/drive/folders/1RgyD0JgTX30H4IM5XZn8I3zSV_mr8pyF", |
| 94 | + "aloha_sim_insertion_scripted": "https://drive.google.com/drive/folders/1TsojQQSXtHEoGnqgJ3gmpPQR2DPLtS2N", |
| 95 | + "aloha_sim_transfer_cube_human": "https://drive.google.com/drive/folders/1sc-E4QYW7A0o23m1u2VWNGVq5smAsfCo", |
| 96 | + "aloha_sim_transfer_cube_scripted": "https://drive.google.com/drive/folders/1aRyoOhQwxhyt1J8XgEig4s6kzaw__LXj", |
| 97 | + } |
| 98 | + |
| 99 | + ep48_urls = { |
| 100 | + "aloha_sim_insertion_human": "https://drive.google.com/file/d/18Cudl6nikDtgRolea7je8iF_gGKzynOP/view?usp=drive_link", |
| 101 | + "aloha_sim_insertion_scripted": "https://drive.google.com/file/d/1wfMSZ24oOh5KR_0aaP3Cnu_c4ZCveduB/view?usp=drive_link", |
| 102 | + "aloha_sim_transfer_cube_human": "https://drive.google.com/file/d/18smMymtr8tIxaNUQ61gW6dG50pt3MvGq/view?usp=drive_link", |
| 103 | + "aloha_sim_transfer_cube_scripted": "https://drive.google.com/file/d/1pnGIOd-E4-rhz2P3VxpknMKRZCoKt6eI/view?usp=drive_link", |
| 104 | + } |
| 105 | + |
| 106 | + ep49_urls = { |
| 107 | + "aloha_sim_insertion_human": "https://drive.google.com/file/d/1C1kZYyROzs-PrLc0SkDgUgMi4-L3lauE/view?usp=drive_link", |
| 108 | + "aloha_sim_insertion_scripted": "https://drive.google.com/file/d/17EuCUWS6uCCr6yyNzpXdcdE-_TTNCKtf/view?usp=drive_link", |
| 109 | + "aloha_sim_transfer_cube_human": "https://drive.google.com/file/d/1Nk7l53d9sJoGDBKAOnNrExX5nLacATc6/view?usp=drive_link", |
| 110 | + "aloha_sim_transfer_cube_scripted": "https://drive.google.com/file/d/1GKReZHrXU73NMiC5zKCq_UtqPVtYq8eo/view?usp=drive_link", |
| 111 | + } |
| 112 | + num_episodes = { # noqa: F841 # we keep this for reference |
| 113 | + "aloha_sim_insertion_human": 50, |
| 114 | + "aloha_sim_insertion_scripted": 50, |
| 115 | + "aloha_sim_transfer_cube_human": 50, |
| 116 | + "aloha_sim_transfer_cube_scripted": 50, |
| 117 | + } |
| 118 | + |
| 119 | + episode_len = { # noqa: F841 # we keep this for reference |
| 120 | + "aloha_sim_insertion_human": 500, |
| 121 | + "aloha_sim_insertion_scripted": 400, |
| 122 | + "aloha_sim_transfer_cube_human": 400, |
| 123 | + "aloha_sim_transfer_cube_scripted": 400, |
| 124 | + } |
| 125 | + |
| 126 | + cameras = { # noqa: F841 # we keep this for reference |
| 127 | + "aloha_sim_insertion_human": ["top"], |
| 128 | + "aloha_sim_insertion_scripted": ["top"], |
| 129 | + "aloha_sim_transfer_cube_human": ["top"], |
| 130 | + "aloha_sim_transfer_cube_scripted": ["top"], |
| 131 | + } |
| 132 | + root = Path(root) |
| 133 | + raw_dir: Path = root / f"{dataset_id}_raw" |
| 134 | + if not raw_dir.is_dir(): |
| 135 | + import gdown |
| 136 | + |
| 137 | + assert dataset_id in folder_urls |
| 138 | + assert dataset_id in ep48_urls |
| 139 | + assert dataset_id in ep49_urls |
| 140 | + |
| 141 | + raw_dir.mkdir(parents=True, exist_ok=True) |
| 142 | + |
| 143 | + gdown.download_folder(folder_urls[dataset_id], output=str(raw_dir)) |
| 144 | + |
| 145 | + # because of the 50 files limit per directory, two files episode 48 and 49 were missing |
| 146 | + gdown.download(ep48_urls[dataset_id], output=str(raw_dir / "episode_48.hdf5"), fuzzy=True) |
| 147 | + gdown.download(ep49_urls[dataset_id], output=str(raw_dir / "episode_49.hdf5"), fuzzy=True) |
| 148 | + return raw_dir |
| 149 | + |
| 150 | + |
| 151 | +def download_umi(root: str, dataset_id: str) -> Path: |
| 152 | + url_cup_in_the_wild = "https://real.stanford.edu/umi/data/zarr_datasets/cup_in_the_wild.zarr.zip" |
| 153 | + cup_in_the_wild_zarr = Path("umi/cup_in_the_wild/cup_in_the_wild.zarr") |
| 154 | + |
| 155 | + root = Path(root) |
| 156 | + raw_dir: Path = root / f"{dataset_id}_raw" |
| 157 | + zarr_path: Path = (raw_dir / cup_in_the_wild_zarr).resolve() |
| 158 | + if not zarr_path.is_dir(): |
| 159 | + raw_dir.mkdir(parents=True, exist_ok=True) |
| 160 | + download_and_extract_zip(url_cup_in_the_wild, zarr_path) |
| 161 | + return zarr_path |
| 162 | + |
| 163 | + |
| 164 | +if __name__ == "__main__": |
| 165 | + root = "data" |
| 166 | + dataset_ids = [ |
| 167 | + "pusht", |
| 168 | + "xarm_lift_medium", |
| 169 | + "xarm_lift_medium_replay", |
| 170 | + "xarm_push_medium", |
| 171 | + "xarm_push_medium_replay", |
| 172 | + "aloha_sim_insertion_human", |
| 173 | + "aloha_sim_insertion_scripted", |
| 174 | + "aloha_sim_transfer_cube_human", |
| 175 | + "aloha_sim_transfer_cube_scripted", |
| 176 | + "umi_cup_in_the_wild", |
| 177 | + ] |
| 178 | + for dataset_id in dataset_ids: |
| 179 | + download_raw(root=root, dataset_id=dataset_id) |
0 commit comments