{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "원본 JSON: /data/ai-hub/fire-dataset/106.화재_발생_예측_데이터(연기_동영상)/01.데이터/val.json\n",
      "저장 경로: /data/ai-hub/fire-dataset/106.화재_발생_예측_데이터(연기_동영상)/01.데이터/val_fixed_2.json\n",
      "삭제할 카테고리 IDs: [11]\n"
     ]
    }
   ],
   "source": [
    "# [Cell 1]\n",
    "# 환경 설정 및 라이브러리 임포트\n",
    "import os\n",
    "import json\n",
    "from datetime import datetime\n",
    "\n",
    "# 입력 JSON 파일 경로 (원본 파일)\n",
    "input_json_path = \"/data/ai-hub/fire-dataset/106.화재_발생_예측_데이터(연기_동영상)/01.데이터/val.json\"\n",
    "\n",
    "# 삭제할 카테고리 ID 리스트 (예시: 배경(background) id=11)\n",
    "remove_category_ids = [11]\n",
    "\n",
    "# 출력 디렉토리와 파일명 설정 (덮어쓰기 방지 위해 timestamp 사용)\n",
    "os.makedirs(\"/data/ai-hub/fire-dataset/106.화재_발생_예측_데이터(연기_동영상)/01.데이터\", exist_ok=True)\n",
    "timestamp = datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
    "output_json_path = f\"/data/ai-hub/fire-dataset/106.화재_발생_예측_데이터(연기_동영상)/01.데이터/val_fixed_2.json\"\n",
    "\n",
    "print(f\"원본 JSON: {input_json_path}\")\n",
    "print(f\"저장 경로: {output_json_path}\")\n",
    "print(f\"삭제할 카테고리 IDs: {remove_category_ids}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "전체 이미지 수: 43195\n",
      "전체 어노테이션 수: 47846\n",
      "전체 카테고리 수: 11\n"
     ]
    }
   ],
   "source": [
    "# [Cell 2]\n",
    "# JSON 파일 로드 및 기본 정보 확인\n",
    "with open(input_json_path, 'r', encoding='utf-8') as f:\n",
    "    coco = json.load(f)\n",
    "\n",
    "print(f\"전체 이미지 수: {len(coco.get('images', []))}\")\n",
    "print(f\"전체 어노테이션 수: {len(coco.get('annotations', []))}\")\n",
    "print(f\"전체 카테고리 수: {len(coco.get('categories', []))}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "삭제된 어노테이션 수: 9207\n"
     ]
    }
   ],
   "source": [
    "# [Cell 3]\n",
    "# 어노테이션 필터링: 삭제할 카테고리를 제외한 나머지만 유지\n",
    "filtered_annotations = [ann for ann in coco['annotations'] if ann['category_id'] not in remove_category_ids]\n",
    "removed_count = len(coco['annotations']) - len(filtered_annotations)\n",
    "print(f\"삭제된 어노테이션 수: {removed_count}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "필터링된 JSON 파일이 성공적으로 저장되었습니다.\n"
     ]
    }
   ],
   "source": [
    "# [Cell 4]\n",
    "# 결과 저장\n",
    "coco['annotations'] = filtered_annotations\n",
    "with open(output_json_path, 'w', encoding='utf-8') as f:\n",
    "    json.dump(coco, f, ensure_ascii=False, indent=2)\n",
    "\n",
    "print(\"필터링된 JSON 파일이 성공적으로 저장되었습니다.\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "250520_mmyolo",
   "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.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
