File size: 10,723 Bytes
924c71f 769bc77 03e5bbf 769bc77 924c71f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | {
"cells": [
{
"cell_type": "markdown",
"id": "intro",
"metadata": {},
"source": "# CounterStrike-1K — Quickstart\n\nEnd-to-end walkthrough of the public preview dataset. **Open in Colab and run all** — the first cell installs the loader.\n\n[](https://colab.research.google.com/github/AnirudhhRamesh/CounterStrike-1K/blob/main/cs2_release/quickstart.ipynb)\n\n**What you'll see**: 1) browse the manifest, 2) decode one sample, 3) inspect actions/state, 4) watch the video, 5) **HUD overlay to verify action–video alignment**, 6) load all 10 synchronized POVs of one round.\n\nIf you're running locally instead of Colab, `uv add datasets \"counterstrike1k @ git+https://github.com/AnirudhhRamesh/counterstrike1k\"` once and skip the next cell."
},
{
"cell_type": "code",
"id": "2d22fcd3",
"source": "# Colab / fresh-kernel install. Skipped automatically if counterstrike1k is\n# already importable (e.g. local `uv add` users) so the cell is silent.\nimport importlib.util\nif importlib.util.find_spec(\"counterstrike1k\") is None:\n %pip install -q \"counterstrike1k @ git+https://github.com/AnirudhhRamesh/counterstrike1k\" datasets pandas matplotlib pillow av",
"metadata": {},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"id": "browse-md",
"metadata": {},
"source": [
"## 1. Browse the manifest\n",
"\n",
"The manifest is a small Parquet file (~25 MB) listing every released POV sample with split, map, weapon, kill counts, and round/match grouping. Read it with pandas — no media is downloaded here."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "browse-code",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"from huggingface_hub import hf_hub_download\n",
"\n",
"manifest = pd.read_parquet(hf_hub_download(\n",
" \"ArnieRamesh/CounterStrike-1K\", \"manifest.parquet\", repo_type=\"dataset\",\n",
"))\n",
"print(f\"{len(manifest):,} POV samples across all splits\")\n",
"manifest.head()[[\"sample_key\", \"split\", \"map_slug\", \"round_id\", \"pov_idx\", \"duration_s\", \"frames\"]]"
]
},
{
"cell_type": "markdown",
"id": "filter-md",
"metadata": {},
"source": [
"Boolean masks give you fast, vectorized filtering — much faster than `.filter(lambda)`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "filter-code",
"metadata": {},
"outputs": [],
"source": [
"mirage_train = manifest[(manifest[\"map_slug\"] == \"mirage\") & (manifest[\"split\"] == \"train\")]\n",
"print(f\"{len(mirage_train):,} Mirage train clips\")\n",
"manifest[\"map_slug\"].value_counts()"
]
},
{
"cell_type": "markdown",
"id": "decode-md",
"metadata": {},
"source": [
"## 2. Stream one sample\n",
"\n",
"We stream from the small preview repo (no full download). `decode_sample` turns one shard sample into numpy arrays plus mp4 bytes."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "decode-code",
"metadata": {},
"outputs": [],
"source": [
"from counterstrike1k import load_sample\n",
"\n",
"samples = list(load_sample()) # downloads ~2 GB on first call, then cached.\n",
"sample = samples[0]\n",
"\n",
"print(\"key: \", sample[\"key\"])\n",
"print(\"actions:\", sample[\"actions\"].shape, sample[\"actions\"].dtype.names)\n",
"print(\"state: \", sample[\"state\"].shape, sample[\"state\"].dtype.names[:6], \"...\")\n",
"print(\"events: \", len(sample[\"events\"]), \"events\")\n",
"print(\"video: \", len(sample[\"video\"]), \"mp4 bytes\")"
]
},
{
"cell_type": "markdown",
"id": "buttons-md",
"metadata": {},
"source": [
"## 3. Inspect actions and state\n",
"\n",
"Buttons are stored as a `uint16` bitmask. `unpack_buttons` expands them into one boolean array per button (`FORWARD`, `FIRE`, `JUMP`, ...)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "buttons-code",
"metadata": {},
"outputs": [],
"source": [
"from counterstrike1k import unpack_buttons\n",
"\n",
"buttons = unpack_buttons(sample[\"actions\"])\n",
"pressed = {name: int(values.sum()) for name, values in buttons.items() if values.any()}\n",
"print(\"pressed frames per button:\", pressed)\n",
"\n",
"state = sample[\"state\"]\n",
"print(\"\\nFirst frame:\")\n",
"print(f\" pos = ({state['pos_x'][0]:.1f}, {state['pos_y'][0]:.1f}, {state['pos_z'][0]:.1f})\")\n",
"print(f\" view = pitch {state['pitch'][0]:.1f}°, yaw {state['yaw'][0]:.1f}°\")\n",
"print(f\" health = {state['health'][0]}, armor = {state['armor_value'][0]}\")\n",
"print(f\" score = T {state['t_score'][0]} : CT {state['ct_score'][0]}\")"
]
},
{
"cell_type": "markdown",
"id": "video-md",
"metadata": {},
"source": [
"## 4. Watch the video\n",
"\n",
"Write the mp4 bytes to a file and embed the player. Audio plays in browsers that allow it."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "video-code",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"from IPython.display import Video\n",
"\n",
"out = Path(\"data/quickstart\") / f\"{sample['key']}.mp4\"\n",
"out.parent.mkdir(parents=True, exist_ok=True)\n",
"out.write_bytes(sample[\"video\"])\n",
"Video(str(out), embed=False, html_attributes=\"controls\")"
]
},
{
"cell_type": "markdown",
"id": "overlay-md",
"metadata": {},
"source": [
"## 5. Verify alignment with the debug overlay\n",
"\n",
"When working with action-conditioned video, the first thing you want to check is: *do the labels actually align with the video?* `overlay_frame` draws a HUD with the WASD keys, FIRE/JUMP/DUCK chips, mouse delta, HP/armor/money, and current score onto any frame.\n",
"\n",
"Pick a frame around something interesting — e.g., the first frame where FIRE is pressed:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "overlay-code-frame",
"metadata": {},
"outputs": [],
"source": [
"from counterstrike1k import overlay_frame\n",
"\n",
"fire_frames = buttons[\"FIRE\"].nonzero()[0]\n",
"frame_idx = int(fire_frames[0]) if len(fire_frames) else len(sample[\"actions\"]) // 2\n",
"print(f\"showing frame {frame_idx}\")\n",
"overlay_frame(sample, frame_idx)"
]
},
{
"cell_type": "markdown",
"id": "overlay-video-md",
"metadata": {},
"source": [
"For a moving overlay, `overlay_video` writes a debug mp4. This is what to share with collaborators when you're explaining what's in the dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "overlay-code-video",
"metadata": {},
"outputs": [],
"source": [
"from counterstrike1k import overlay_video\n",
"\n",
"debug_path = Path(\"data/quickstart\") / f\"{sample['key']}.debug.mp4\"\n",
"overlay_video(sample, debug_path, max_frames=192) # ~6 seconds at 32 FPS\n",
"Video(str(debug_path), embed=False, html_attributes=\"controls\")"
]
},
{
"cell_type": "markdown",
"id": "round-md",
"metadata": {},
"source": [
"## 6. Load all 10 POVs of one synchronized round\n",
"\n",
"Every round has exactly 10 synchronized POVs sharing a `round_id`. Group them with the manifest, then pull each one."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "round-code",
"metadata": {},
"outputs": [],
"source": [
"rows = pd.DataFrame([{**s[\"metadata\"], \"frames_actual\": len(s[\"actions\"])} for s in samples])\n",
"round_id = rows[\"round_id\"].iloc[0]\n",
"round_samples = rows[rows[\"round_id\"] == round_id].sort_values(\"pov_idx\")\n",
"print(f\"round {round_id}: {len(round_samples)} POVs\")\n",
"round_samples[[\"sample_key\", \"pov_idx\", \"team_side\", \"frames_actual\", \"alive_duration_s\"]]"
]
},
{
"cell_type": "markdown",
"id": "grid-md",
"metadata": {},
"source": [
"## 7. (Optional) Display all 10 POVs as a grid\n",
"\n",
"Decodes the midpoint frame from each POV and stacks them into a 5×2 grid."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "grid-code",
"metadata": {},
"outputs": [],
"source": [
"import io\n",
"import av\n",
"from PIL import Image, ImageDraw\n",
"\n",
"def midpoint_frame(video_bytes):\n",
" with av.open(io.BytesIO(video_bytes)) as container:\n",
" frames = list(container.decode(video=0))\n",
" return frames[len(frames) // 2].to_image()\n",
"\n",
"by_pov = {int(s[\"metadata\"][\"pov_idx\"]): s for s in samples if s[\"metadata\"][\"round_id\"] == round_id}\n",
"tile_w = 320\n",
"tiles = []\n",
"for pov in sorted(by_pov):\n",
" img = midpoint_frame(by_pov[pov][\"video\"])\n",
" th = int(round(tile_w * img.height / img.width))\n",
" tiles.append((pov, by_pov[pov][\"metadata\"].get(\"team_side\", \"\"), img.resize((tile_w, th))))\n",
"\n",
"tw, th = tiles[0][2].size\n",
"cols, rows_n = 5, 2\n",
"grid = Image.new(\"RGB\", (cols * tw + 4, rows_n * (th + 22) + 4), (18, 18, 18))\n",
"draw = ImageDraw.Draw(grid)\n",
"for i, (pov, side, img) in enumerate(tiles):\n",
" r, c = divmod(i, cols)\n",
" x, y = c * tw + 2, r * (th + 22) + 2\n",
" draw.text((x + 4, y), f\"pov {pov} {side}\", fill=(245, 245, 245))\n",
" grid.paste(img, (x, y + 22))\n",
"grid"
]
},
{
"cell_type": "markdown",
"id": "next-md",
"metadata": {},
"source": [
"## What's next\n",
"\n",
"- For training: stream the **360p** or **720p** WebDataset shards. See `examples/torch_dataset.py`.\n",
"- For full schema details: open the [`schema/` folder](https://huggingface.co/datasets/ArnieRamesh/CounterStrike-1K/tree/main/schema) on the dataset card.\n",
"- For deeper exploration (parquet+offset access, smoke checks): see `examples/advanced/`."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
} |