You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
349 lines
10 KiB
349 lines
10 KiB
{
|
|
"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
|
|
}
|