{ "cells": [ { "cell_type": "code", "execution_count": 5, "id": "817586c7", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "๐Ÿ” Checking split: train (files: 6471)\n", "\n", "๐Ÿ” Checking split: val (files: 548)\n", "\n", "๐Ÿ” Checking split: test (files: 1610)\n", "\n", "๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\n", " - Class 0: 147747 ๊ฐœ\n", " - Class 1: 187005 ๊ฐœ\n", " - Class 2: 32702 ๊ฐœ\n", " - Class 3: 16284 ๊ฐœ\n", " - Class 4: 9117 ๊ฐœ\n", " - Class 5: 40378 ๊ฐœ\n", "\n", "์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: 6\n" ] } ], "source": [ "import os\n", "from collections import Counter\n", "\n", "# label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels copy\"\n", "label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels\"\n", "splits = [\"train\", \"val\",'test']\n", "\n", "class_counter = Counter()\n", "\n", "for split in splits:\n", " split_path = os.path.join(label_root, split)\n", " \n", " # ๋ผ๋ฒจ txt ํŒŒ์ผ ํƒ์ƒ‰\n", " label_files = [f for f in os.listdir(split_path) if f.endswith(\".txt\")]\n", " \n", " print(f\"\\n๐Ÿ” Checking split: {split} (files: {len(label_files)})\")\n", "\n", " for file in label_files:\n", " file_path = os.path.join(split_path, file)\n", " with open(file_path, \"r\") as f:\n", " for line in f.readlines():\n", " if line.strip(): # ๋นˆ ์ค„ ์ œ๊ฑฐ\n", " class_id = line.split()[0] # ์ฒซ๋ฒˆ์งธ ๊ฐ’ = ํด๋ž˜์Šค\n", " class_counter[class_id] += 1\n", "\n", "# ์ตœ์ข… ๊ฒฐ๊ณผ ์ถœ๋ ฅ\n", "print(\"\\n๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\")\n", "for cls, count in sorted(class_counter.items(), key=lambda x: int(x[0])):\n", " print(f\" - Class {cls}: {count} ๊ฐœ\")\n", "\n", "print(f\"\\n์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: {len(class_counter)}\")\n" ] }, { "cell_type": "code", "execution_count": 6, "id": "35cf2381", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "๐Ÿ“‚ Updating: train (files: 6471)\n", "\n", "๐Ÿ“‚ Updating: val (files: 548)\n", "\n", "๐Ÿ“‚ Updating: test (files: 1610)\n", "\n", "โœ… ๋ผ๋ฒจ ํด๋ž˜์Šค ๋ฒˆํ˜ธ ์žฌ์ •๋ ฌ ์™„๋ฃŒ!\n" ] } ], "source": [ "import os\n", "\n", "label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels\"\n", "splits = [\"train\", \"val\", \"test\"]\n", "\n", "# ํด๋ž˜์Šค ์žฌ๋งคํ•‘ ์„ค์ •\n", "mapping = {\n", " \"0\": \"0\", # person stays 0\n", " \"1\": \"1\", # car stays 1\n", " \"2\": \"5\", # van -> 5\n", " \"3\": \"2\", # truck -> 2\n", " \"4\": \"3\", # bus -> 3\n", " \"5\": \"4\" # motor -> 4\n", "}\n", "\n", "for split in splits:\n", " split_path = os.path.join(label_root, split)\n", " label_files = [f for f in os.listdir(split_path) if f.endswith(\".txt\")]\n", "\n", " print(f\"\\n๐Ÿ“‚ Updating: {split} (files: {len(label_files)})\")\n", "\n", " for file in label_files:\n", " file_path = os.path.join(split_path, file)\n", "\n", " new_lines = []\n", " with open(file_path, \"r\") as f:\n", " for line in f.readlines():\n", " if line.strip():\n", " parts = line.split()\n", " cls = parts[0]\n", " parts[0] = mapping[cls] # ํด๋ž˜์Šค ๋ฒˆํ˜ธ ๋ณ€๊ฒฝ\n", " new_lines.append(\" \".join(parts) + \"\\n\")\n", "\n", " # ๋ฎ์–ด์“ฐ๊ธฐ\n", " with open(file_path, \"w\") as f:\n", " f.writelines(new_lines)\n", "\n", "print(\"\\nโœ… ๋ผ๋ฒจ ํด๋ž˜์Šค ๋ฒˆํ˜ธ ์žฌ์ •๋ ฌ ์™„๋ฃŒ!\")\n" ] }, { "cell_type": "code", "execution_count": 7, "id": "3fdd6e44", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "๐Ÿ” Checking split: train (files: 6471)\n", "\n", "๐Ÿ” Checking split: val (files: 548)\n", "\n", "๐Ÿ” Checking split: test (files: 1610)\n", "\n", "๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\n", " - Class 0: 147747 ๊ฐœ\n", " - Class 1: 187005 ๊ฐœ\n", " - Class 2: 16284 ๊ฐœ\n", " - Class 3: 9117 ๊ฐœ\n", " - Class 4: 40378 ๊ฐœ\n", " - Class 5: 32702 ๊ฐœ\n", "\n", "์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: 6\n" ] } ], "source": [ "import os\n", "from collections import Counter\n", "\n", "# label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels copy\"\n", "label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels\"\n", "splits = [\"train\", \"val\",'test']\n", "\n", "class_counter = Counter()\n", "\n", "for split in splits:\n", " split_path = os.path.join(label_root, split)\n", " \n", " # ๋ผ๋ฒจ txt ํŒŒ์ผ ํƒ์ƒ‰\n", " label_files = [f for f in os.listdir(split_path) if f.endswith(\".txt\")]\n", " \n", " print(f\"\\n๐Ÿ” Checking split: {split} (files: {len(label_files)})\")\n", "\n", " for file in label_files:\n", " file_path = os.path.join(split_path, file)\n", " with open(file_path, \"r\") as f:\n", " for line in f.readlines():\n", " if line.strip(): # ๋นˆ ์ค„ ์ œ๊ฑฐ\n", " class_id = line.split()[0] # ์ฒซ๋ฒˆ์งธ ๊ฐ’ = ํด๋ž˜์Šค\n", " class_counter[class_id] += 1\n", "\n", "# ์ตœ์ข… ๊ฒฐ๊ณผ ์ถœ๋ ฅ\n", "print(\"\\n๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\")\n", "for cls, count in sorted(class_counter.items(), key=lambda x: int(x[0])):\n", " print(f\" - Class {cls}: {count} ๊ฐœ\")\n", "\n", "print(f\"\\n์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: {len(class_counter)}\")\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "ca796e3d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Processing train: 6471 files\n", "Processing val: 548 files\n", "Processing test: 1610 files\n", "Done. All label files updated!\n" ] } ], "source": [ "import os\n", "from glob import glob\n", "\n", "# ๋ผ๋ฒจ ๋งคํ•‘\n", "mapping = {\n", " 0: 0,\n", " 1: 2,\n", " 2: 5,\n", " 3: 4,\n", " 4: 3,\n", " 5: 1\n", "}\n", "\n", "# labels ํด๋” ๊ฒฝ๋กœ\n", "base_dir = \"/home/cuuva/experiment/datasets/VisDrone/labels\"\n", "\n", "# train, val, test ๋ชจ๋‘ ์ฒ˜๋ฆฌ\n", "splits = [\"train\", \"val\", \"test\"]\n", "\n", "for split in splits:\n", " label_dir = os.path.join(base_dir, split)\n", " txt_files = glob(os.path.join(label_dir, \"*.txt\"))\n", "\n", " print(f\"Processing {split}: {len(txt_files)} files\")\n", "\n", " for txt_path in txt_files:\n", " lines = []\n", " with open(txt_path, \"r\") as f:\n", " for line in f.readlines():\n", " parts = line.strip().split()\n", " if len(parts) < 5:\n", " continue\n", "\n", " old_cls = int(parts[0])\n", " new_cls = mapping[old_cls]\n", "\n", " # ํด๋ž˜์Šค๋งŒ ๋ณ€๊ฒฝํ•ด์„œ ๋‹ค์‹œ ์ €์žฅ\n", " parts[0] = str(new_cls)\n", " lines.append(\" \".join(parts))\n", "\n", " with open(txt_path, \"w\") as f:\n", " f.write(\"\\n\".join(lines))\n", "\n", "print(\"Done. All label files updated!\")\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "a461857c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "๐Ÿ” Checking split: train (files: 6471)\n", "\n", "๐Ÿ” Checking split: val (files: 548)\n", "\n", "๐Ÿ” Checking split: test (files: 1610)\n", "\n", "๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\n", " - Class 0: 147747 ๊ฐœ\n", " - Class 1: 32702 ๊ฐœ\n", " - Class 2: 187005 ๊ฐœ\n", " - Class 3: 40378 ๊ฐœ\n", " - Class 4: 9117 ๊ฐœ\n", " - Class 5: 16284 ๊ฐœ\n", "\n", "์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: 6\n" ] } ], "source": [ "import os\n", "from collections import Counter\n", "\n", "# label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels copy\"\n", "label_root = \"/home/cuuva/experiment/datasets/VisDrone/labels\"\n", "splits = [\"train\", \"val\",'test']\n", "\n", "class_counter = Counter()\n", "\n", "for split in splits:\n", " split_path = os.path.join(label_root, split)\n", " \n", " # ๋ผ๋ฒจ txt ํŒŒ์ผ ํƒ์ƒ‰\n", " label_files = [f for f in os.listdir(split_path) if f.endswith(\".txt\")]\n", " \n", " print(f\"\\n๐Ÿ” Checking split: {split} (files: {len(label_files)})\")\n", "\n", " for file in label_files:\n", " file_path = os.path.join(split_path, file)\n", " with open(file_path, \"r\") as f:\n", " for line in f.readlines():\n", " if line.strip(): # ๋นˆ ์ค„ ์ œ๊ฑฐ\n", " class_id = line.split()[0] # ์ฒซ๋ฒˆ์งธ ๊ฐ’ = ํด๋ž˜์Šค\n", " class_counter[class_id] += 1\n", "\n", "# ์ตœ์ข… ๊ฒฐ๊ณผ ์ถœ๋ ฅ\n", "print(\"\\n๐Ÿ“Œ ํด๋ž˜์Šค ํ†ต๊ณ„ ๊ฒฐ๊ณผ:\")\n", "for cls, count in sorted(class_counter.items(), key=lambda x: int(x[0])):\n", " print(f\" - Class {cls}: {count} ๊ฐœ\")\n", "\n", "print(f\"\\n์ด ํด๋ž˜์Šค ์ข…๋ฅ˜: {len(class_counter)}\")\n" ] }, { "cell_type": "code", "execution_count": null, "id": "8320460f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "1stagedetect", "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.10.18" } }, "nbformat": 4, "nbformat_minor": 5 }