{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":91865,"databundleVersionId":10898995,"sourceType":"competition"}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!git clone https://github.com/ffyyytt/EAR-WACV25-DAKiet-TSM.git\n%cd EAR-WACV25-DAKiet-TSM","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!git clone https://huggingface.co/fdfyaytkt/ear-wacv25-tsm-rgb-resnext50_32x4d","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport cv2\nimport glob\nimport math\n\nimport pandas as pd\nfrom tqdm import *\n\ndef mp4_to_jpg(filename, idx):\n    os.makedirs(f\"data/test_img/{idx}\")\n    vidcap = cv2.VideoCapture(filename)\n    c = 0\n    while True:\n        success, image = vidcap.read()\n        if not success:\n            return c\n        c += 1\n        image = cv2.resize(image, (224, 224))\n        cv2.imwrite(f\"data/test_img/{idx}/{c:06d}.jpg\", image)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.makedirs(f\"data/\")\nallfiles = sorted( glob.glob(\"/kaggle/input/elderly-action-recognition-challenge-at-wacv-2025/eval_FO_ids/*\") )\nwith open(\"data/classInd.txt\", \"w\") as f:\n    f.write(\"\\n\".join(map(str, range(6))))\n\nstep = 100\nfor i in range(math.ceil(len(allfiles)/step)):\n    files = allfiles[i*step: (i+1)*step]\n    txtfile = []\n    for file in tqdm(files):\n        idx = file.split(\"/\")[-1][:-4]\n        txtfile.append([idx, mp4_to_jpg(file, idx), 0])\n    with open(\"data/test_img/test.txt\", \"w\") as f:\n        f.write(\"\\n\".join([\" \".join(map(str, s)) for s in txtfile]))\n\n    os.popen(f\"python generate_submission.py elderly --arch=resnext50_32x4d --csv_file=submission_{i}.csv  --weights=/kaggle/working/EAR-WACV25-DAKiet-TSM/ear-wacv25-tsm-rgb-resnext50_32x4d/TSM_elderly_RGB_resnext50_32x4d_shift8_blockres_avg_segment8.tar --test_segments=8 --batch_size=1 --test_crops=1\").read()\n    os.popen(\"rm -rf data/test_img/\").read()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"csvfiles = sorted(glob.glob(\"submission_*.csv\"), key = lambda x: int( x[x.find(\"_\")+1:x.find(\".\")] ))\nvideo_name = []\naction_category = []\nfor file in csvfiles:\n    df = pd.read_csv(file)\n    video_name += df[\"video_name\"].values.tolist()\n    action_category += df[\"action_category\"].values.tolist()\n\ndf = pd.DataFrame()\ndf[\"video_name\"] = video_name\ndf[\"action_category\"] = action_category","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd ..","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}