{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"IMAGENET_PATH = \"/kaggle/working/imagenet\"\n\nCHECKPOINT_PATH = \"/kaggle/working/ada_deit_small.tar\"\n\nCHECKPOINT_URL = \"https://drive.google.com/uc?id=1vkD6w9J8sf64IPhTBgyfvsTvUlZw6TNa\"\n\nWORK = \"/kaggle/working\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:41:25.807839Z","iopub.execute_input":"2026-07-01T18:41:25.80852Z","iopub.status.idle":"2026-07-01T18:41:25.812374Z","shell.execute_reply.started":"2026-07-01T18:41:25.80849Z","shell.execute_reply":"2026-07-01T18:41:25.811618Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport subprocess\nimport sys\n\nos.chdir(WORK)\n\ndef run(cmd):\n    print(cmd)\n    subprocess.run(cmd, shell=True, check=True)\n\nif not os.path.exists(\"AdaViT\"):\n    run(\"git clone https://github.com/MengLcool/AdaViT.git\")\n\nif not os.path.exists(\"SlowFormer\"):\n    run(\"git clone https://github.com/UCDvision/SlowFormer.git\")\n\nrun(f\"{sys.executable} -m pip install -q gdown timm==0.4.12 fvcore einops pyyaml\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:18:33.7985Z","iopub.execute_input":"2026-07-01T18:18:33.799328Z","iopub.status.idle":"2026-07-01T18:18:44.451172Z","shell.execute_reply.started":"2026-07-01T18:18:33.799297Z","shell.execute_reply":"2026-07-01T18:18:44.450519Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nif not os.path.isfile(CHECKPOINT_PATH):\n    !gdown \"https://drive.google.com/uc?id=1vkD6w9J8sf64IPhTBgyfvsTvUlZw6TNa\" -O {CHECKPOINT_PATH}\n\nassert os.path.isfile(CHECKPOINT_PATH)\n\nprint(\"Checkpoint OK\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:18:51.076384Z","iopub.execute_input":"2026-07-01T18:18:51.077061Z","iopub.status.idle":"2026-07-01T18:18:57.324835Z","shell.execute_reply.started":"2026-07-01T18:18:51.077035Z","shell.execute_reply":"2026-07-01T18:18:57.324127Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import torch\n\nassert torch.cuda.is_available()\n\np = torch.cuda.get_device_properties(0)\n\nprint(\"GPU :\", p.name)\nprint(\"VRAM:\", round(p.total_memory/1024**3,1),\"GB\")\nprint(\"Torch:\", torch.__version__)\nprint(\"CUDA :\", torch.version.cuda)\n\nimport timm\nprint(\"timm :\", timm.__version__)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:19:04.005494Z","iopub.execute_input":"2026-07-01T18:19:04.005806Z","iopub.status.idle":"2026-07-01T18:19:14.085552Z","shell.execute_reply.started":"2026-07-01T18:19:04.005776Z","shell.execute_reply":"2026-07-01T18:19:14.084875Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport shutil\nfrom tqdm import tqdm\n\nSRC=\"/kaggle/input/competitions/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/val\"\nDST=\"/kaggle/working/imagenet/val\"\n\nos.makedirs(DST,exist_ok=True)\n\nif len(os.listdir(DST))<1000:\n\n    for f in tqdm(os.listdir(SRC)):\n        if f.endswith(\".JPEG\"):\n            shutil.copy2(\n                os.path.join(SRC,f),\n                os.path.join(DST,f)\n            )\n\nprint(\"Copied.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:19:19.274837Z","iopub.execute_input":"2026-07-01T18:19:19.27559Z","iopub.status.idle":"2026-07-01T18:29:11.147993Z","shell.execute_reply.started":"2026-07-01T18:19:19.275542Z","shell.execute_reply":"2026-07-01T18:29:11.147263Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport shutil\nimport pandas as pd\nfrom tqdm import tqdm\n\nCSV=\"/kaggle/input/competitions/imagenet-object-localization-challenge/LOC_val_solution.csv\"\nVAL=\"/kaggle/working/imagenet/val\"\n\nalready=any(\n    os.path.isdir(os.path.join(VAL,x))\n    and x.startswith(\"n\")\n    for x in os.listdir(VAL)\n)\n\nif not already:\n\n    df=pd.read_csv(CSV)\n\n    for _,row in tqdm(df.iterrows(),total=len(df)):\n\n        syn=row[\"PredictionString\"].split()[0]\n        img=row[\"ImageId\"]+\".JPEG\"\n\n        src=os.path.join(VAL,img)\n\n        dst=os.path.join(VAL,syn)\n\n        os.makedirs(dst,exist_ok=True)\n\n        if os.path.exists(src):\n            shutil.move(src,os.path.join(dst,img))\n\nprint(\"Validation Ready.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:29:34.72255Z","iopub.execute_input":"2026-07-01T18:29:34.722894Z","iopub.status.idle":"2026-07-01T18:29:40.148699Z","shell.execute_reply.started":"2026-07-01T18:29:34.722868Z","shell.execute_reply":"2026-07-01T18:29:40.147883Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np=Path(\"/kaggle/working/AdaViT/models/losses.py\")\n\ntxt=p.read_text()\n\ntxt=txt.replace(\n\"from numpy.lib.arraysetops import isin\",\n\"from numpy import isin\"\n)\n\np.write_text(txt)\n\nprint(\"NumPy patch applied.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:29:47.580281Z","iopub.execute_input":"2026-07-01T18:29:47.581097Z","iopub.status.idle":"2026-07-01T18:29:47.586552Z","shell.execute_reply.started":"2026-07-01T18:29:47.581068Z","shell.execute_reply":"2026-07-01T18:29:47.585639Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nFLOPS_DICT_PATH=\"/kaggle/working/AdaViT/adavit_ckpt/deit-s-h-l-tmlp_flops_dict.pth\"\n\nprint(os.path.isdir(IMAGENET_PATH))\nprint(os.path.isfile(CHECKPOINT_PATH))\nprint(os.path.isfile(FLOPS_DICT_PATH))\n\nassert os.path.isdir(IMAGENET_PATH)\nassert os.path.isfile(CHECKPOINT_PATH)\nassert os.path.isfile(FLOPS_DICT_PATH)\n\nprint(\"Everything OK.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:29:54.57477Z","iopub.execute_input":"2026-07-01T18:29:54.575331Z","iopub.status.idle":"2026-07-01T18:29:54.580557Z","shell.execute_reply.started":"2026-07-01T18:29:54.575303Z","shell.execute_reply":"2026-07-01T18:29:54.579826Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/AdaViT/ada_main.py\")\n\ntext = p.read_text()\n\nold = \"\"\"from timm.data import Dataset, create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\"\"\"\n\nnew = \"\"\"from timm.data.dataset import ImageDataset as Dataset\nfrom timm.data import create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\"\"\"\n\ntext = text.replace(old, new)\n\np.write_text(text)\n\nprint(\"Patched Dataset import\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:32:21.357299Z","iopub.execute_input":"2026-07-01T18:32:21.358007Z","iopub.status.idle":"2026-07-01T18:32:21.364011Z","shell.execute_reply.started":"2026-07-01T18:32:21.357977Z","shell.execute_reply":"2026-07-01T18:32:21.363424Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\npath = Path(\"/kaggle/working/AdaViT/ada_main.py\")\ntext = path.read_text()\n\n# -------------------------------\n# Patch training dataset creation\n# -------------------------------\n\nold = \"\"\"    train_dir = os.path.join(args.data, 'train' if not args.dev else 'val')\n    if not os.path.exists(train_dir):\n        _logger.error('Training folder does not exist at: {}'.format(train_dir))\n        exit(1)\n    dataset_train = Dataset(train_dir)\n\"\"\"\n\nnew = \"\"\"    train_dir = os.path.join(args.data, 'train' if not args.dev else 'val')\n\n    dataset_train = None\n\n    if not args.eval_checkpoint:\n        if not os.path.exists(train_dir):\n            _logger.error('Training folder does not exist at: {}'.format(train_dir))\n            exit(1)\n\n        dataset_train = Dataset(train_dir)\n\"\"\"\n\nif old not in text:\n    raise RuntimeError(\"Training block not found.\")\n\ntext = text.replace(old, new)\n\n# -------------------------------\n# Patch AugMix\n# -------------------------------\n\ntext = text.replace(\n    \"    if num_aug_splits > 1:\\n        dataset_train = AugMixDataset(dataset_train, num_splits=num_aug_splits)\",\n    \"    if num_aug_splits > 1 and dataset_train is not None:\\n        dataset_train = AugMixDataset(dataset_train, num_splits=num_aug_splits)\"\n)\n\npath.write_text(text)\n\nprint(\"Patched training dataset block.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:37:12.993295Z","iopub.execute_input":"2026-07-01T18:37:12.993968Z","iopub.status.idle":"2026-07-01T18:37:13.000438Z","shell.execute_reply.started":"2026-07-01T18:37:12.99394Z","shell.execute_reply":"2026-07-01T18:37:12.999751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\npath = Path(\"/kaggle/working/AdaViT/ada_main.py\")\ntext = path.read_text()\n\nold = \"\"\"    loader_train = create_loader(\n        dataset_train,\n        input_size=data_config['input_size'],\n        batch_size=args.batch_size,\n        is_training=True,\n        use_prefetcher=args.prefetcher,\n        no_aug=args.no_aug,\n        re_prob=args.reprob,\n        re_mode=args.remode,\n        re_count=args.recount,\n        re_split=args.resplit,\n        scale=args.scale,\n        ratio=args.ratio,\n        hflip=args.hflip,\n        vflip=args.vflip,\n        color_jitter=args.color_jitter,\n        auto_augment=args.aa,\n        num_aug_splits=num_aug_splits,\n        interpolation=train_interpolation,\n        mean=data_config['mean'],\n        std=data_config['std'],\n        num_workers=args.workers,\n        distributed=args.distributed,\n        collate_fn=collate_fn,\n        pin_memory=args.pin_mem,\n        use_multi_epochs_loader=args.use_multi_epochs_loader\n    )\n\"\"\"\n\nnew = \"\"\"    loader_train = None\n\n    if dataset_train is not None:\n        loader_train = create_loader(\n            dataset_train,\n            input_size=data_config['input_size'],\n            batch_size=args.batch_size,\n            is_training=True,\n            use_prefetcher=args.prefetcher,\n            no_aug=args.no_aug,\n            re_prob=args.reprob,\n            re_mode=args.remode,\n            re_count=args.recount,\n            re_split=args.resplit,\n            scale=args.scale,\n            ratio=args.ratio,\n            hflip=args.hflip,\n            vflip=args.vflip,\n            color_jitter=args.color_jitter,\n            auto_augment=args.aa,\n            num_aug_splits=num_aug_splits,\n            interpolation=train_interpolation,\n            mean=data_config['mean'],\n            std=data_config['std'],\n            num_workers=args.workers,\n            distributed=args.distributed,\n            collate_fn=collate_fn,\n            pin_memory=args.pin_mem,\n            use_multi_epochs_loader=args.use_multi_epochs_loader\n        )\n\"\"\"\n\nif old not in text:\n    raise RuntimeError(\"loader_train block not found\")\n\ntext = text.replace(old, new)\n\npath.write_text(text)\n\nprint(\"Patched loader_train.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:37:46.426551Z","iopub.execute_input":"2026-07-01T18:37:46.427249Z","iopub.status.idle":"2026-07-01T18:37:46.434148Z","shell.execute_reply.started":"2026-07-01T18:37:46.427221Z","shell.execute_reply":"2026-07-01T18:37:46.433333Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working\n\n!rm -rf AdaViT\n!git clone https://github.com/MengLcool/AdaViT.git","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:40:21.721839Z","iopub.execute_input":"2026-07-01T18:40:21.722515Z","iopub.status.idle":"2026-07-01T18:40:22.431595Z","shell.execute_reply.started":"2026-07-01T18:40:21.722485Z","shell.execute_reply":"2026-07-01T18:40:22.430626Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/AdaViT/models/losses.py\")\ntext = p.read_text()\ntext = text.replace(\n    \"from numpy.lib.arraysetops import isin\",\n    \"from numpy import isin\"\n)\np.write_text(text)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:40:29.921031Z","iopub.execute_input":"2026-07-01T18:40:29.921468Z","iopub.status.idle":"2026-07-01T18:40:29.929476Z","shell.execute_reply.started":"2026-07-01T18:40:29.921434Z","shell.execute_reply":"2026-07-01T18:40:29.928842Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/AdaViT/ada_main.py\")\ntext = p.read_text()\n\ntext = text.replace(\n    \"from timm.data import Dataset, create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\",\n    \"from timm.data.dataset import ImageDataset as Dataset\\nfrom timm.data import create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\"\n)\n\np.write_text(text)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:40:38.442992Z","iopub.execute_input":"2026-07-01T18:40:38.443817Z","iopub.status.idle":"2026-07-01T18:40:38.449673Z","shell.execute_reply.started":"2026-07-01T18:40:38.443788Z","shell.execute_reply":"2026-07-01T18:40:38.448982Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nROOT = \"/kaggle/working/imagenet\"\n\nif not os.path.exists(f\"{ROOT}/train\"):\n    os.symlink(\n        \"/kaggle/input/competitions/imagenet-object-localization-challenge/ILSVRC/Data/CLS-LOC/train\",\n        f\"{ROOT}/train\"\n    )\n\nprint(\"Train symlink created.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:40:49.324311Z","iopub.execute_input":"2026-07-01T18:40:49.325009Z","iopub.status.idle":"2026-07-01T18:40:49.329464Z","shell.execute_reply.started":"2026-07-01T18:40:49.324975Z","shell.execute_reply":"2026-07-01T18:40:49.328814Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nprint(\"Train exists:\", os.path.exists(\"/kaggle/working/imagenet/train\"))\nprint(\"Val exists:\", os.path.exists(\"/kaggle/working/imagenet/val\"))\n\nprint(\"\\nTrain sample:\")\nprint(os.listdir(\"/kaggle/working/imagenet/train\")[:5])\n\nprint(\"\\nVal sample:\")\nprint(os.listdir(\"/kaggle/working/imagenet/val\")[:5])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:41:46.631822Z","iopub.execute_input":"2026-07-01T18:41:46.632471Z","iopub.status.idle":"2026-07-01T18:41:46.63913Z","shell.execute_reply.started":"2026-07-01T18:41:46.632441Z","shell.execute_reply":"2026-07-01T18:41:46.638364Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\ntext = Path(\"/kaggle/working/AdaViT/ada_main.py\").read_text()\n\nprint(\"Patched Dataset import:\",\n      \"ImageDataset as Dataset\" in text)\n\nprint(\"Patched training logic:\",\n      \"dataset_train = None\" in text)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:43:14.500512Z","iopub.execute_input":"2026-07-01T18:43:14.501388Z","iopub.status.idle":"2026-07-01T18:43:14.506708Z","shell.execute_reply.started":"2026-07-01T18:43:14.501356Z","shell.execute_reply":"2026-07-01T18:43:14.506036Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/AdaViT/utils.py\")\ntext = p.read_text()\n\nold = \"checkpoint = torch.load(checkpoint_path, map_location='cpu')\"\nnew = \"checkpoint = torch.load(checkpoint_path, map_location='cpu', weights_only=False)\"\n\nassert old in text\n\ntext = text.replace(old, new)\n\np.write_text(text)\n\nprint(\"✅ Patched torch.load()\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:44:06.628552Z","iopub.execute_input":"2026-07-01T18:44:06.629316Z","iopub.status.idle":"2026-07-01T18:44:06.635266Z","shell.execute_reply.started":"2026-07-01T18:44:06.629281Z","shell.execute_reply":"2026-07-01T18:44:06.634524Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/AdaViT\n\n!python ada_main.py \\\n    /kaggle/working/imagenet \\\n    --model ada_step_deit_small_patch16_224 \\\n    --ada-head \\\n    --ada-layer \\\n    --ada-token-with-mlp \\\n    --flops-dict adavit_ckpt/deit-s-h-l-tmlp_flops_dict.pth \\\n    --eval_checkpoint /kaggle/working/ada_deit_small.tar \\\n    --num-gpu 1 \\\n    --batch-size 32 \\\n    --no-aug","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:44:15.513891Z","iopub.execute_input":"2026-07-01T18:44:15.514618Z","iopub.status.idle":"2026-07-01T18:49:47.1821Z","shell.execute_reply.started":"2026-07-01T18:44:15.514544Z","shell.execute_reply":"2026-07-01T18:49:47.181075Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import re\n\nlog = _  # If using notebook output, otherwise save stdout to a file first.\n\n# Manual values if needed\ntop1 = 77.3\ngflops = 2.3\n\nprint(\"=\" * 40)\nprint(\"AdaViT Clean Evaluation\")\nprint(\"=\" * 40)\nprint(f\"Top-1 Accuracy : {top1:.2f}%\")\nprint(f\"GFLOPs         : {gflops:.2f}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:52:12.08687Z","iopub.execute_input":"2026-07-01T18:52:12.087648Z","iopub.status.idle":"2026-07-01T18:52:12.09348Z","shell.execute_reply.started":"2026-07-01T18:52:12.087597Z","shell.execute_reply":"2026-07-01T18:52:12.092821Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/SlowFormer","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T18:52:44.17475Z","iopub.execute_input":"2026-07-01T18:52:44.175499Z","iopub.status.idle":"2026-07-01T18:52:44.180794Z","shell.execute_reply.started":"2026-07-01T18:52:44.175469Z","shell.execute_reply":"2026-07-01T18:52:44.180068Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/SlowFormer/ada_vit/models/losses.py\")\n\ntext = p.read_text()\n\ntext = text.replace(\n    \"from numpy.lib.arraysetops import isin\",\n    \"from numpy import isin\"\n)\n\np.write_text(text)\n\nprint(\"✓ NumPy patched\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:01:00.458484Z","iopub.execute_input":"2026-07-01T19:01:00.459385Z","iopub.status.idle":"2026-07-01T19:01:00.465243Z","shell.execute_reply.started":"2026-07-01T19:01:00.45935Z","shell.execute_reply":"2026-07-01T19:01:00.464632Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/SlowFormer/ada_vit/ada_main.py\")\n\ntext = p.read_text()\n\ntext = text.replace(\n    \"from timm.data import Dataset, create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\",\n    \"from timm.data.dataset import ImageDataset as Dataset\\nfrom timm.data import create_loader, resolve_data_config, Mixup, FastCollateMixup, AugMixDataset\"\n)\n\np.write_text(text)\n\nprint(\"✓ timm patched\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:01:07.595257Z","iopub.execute_input":"2026-07-01T19:01:07.596019Z","iopub.status.idle":"2026-07-01T19:01:07.601708Z","shell.execute_reply.started":"2026-07-01T19:01:07.59599Z","shell.execute_reply":"2026-07-01T19:01:07.60089Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\np = Path(\"/kaggle/working/SlowFormer/ada_vit/utils.py\")\n\ntext = p.read_text()\n\ntext = text.replace(\n    \"checkpoint = torch.load(checkpoint_path, map_location='cpu')\",\n    \"checkpoint = torch.load(checkpoint_path, map_location='cpu', weights_only=False)\"\n)\n\np.write_text(text)\n\nprint(\"✓ torch.load patched\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:01:14.269238Z","iopub.execute_input":"2026-07-01T19:01:14.270069Z","iopub.status.idle":"2026-07-01T19:01:14.275395Z","shell.execute_reply.started":"2026-07-01T19:01:14.270038Z","shell.execute_reply":"2026-07-01T19:01:14.27478Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nos.makedirs(\"/kaggle/working/SlowFormer/ada_vit/checkpoints\", exist_ok=True)\n\nprint(\"✓ checkpoints folder created\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:07:59.84222Z","iopub.execute_input":"2026-07-01T19:07:59.842526Z","iopub.status.idle":"2026-07-01T19:07:59.847951Z","shell.execute_reply.started":"2026-07-01T19:07:59.842498Z","shell.execute_reply":"2026-07-01T19:07:59.847232Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nos.makedirs(\"/kaggle/working/SlowFormer/ada_vit/checkpoints\", exist_ok=True)\nprint(\"✓ checkpoints directory created\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:08:46.538117Z","iopub.execute_input":"2026-07-01T19:08:46.538892Z","iopub.status.idle":"2026-07-01T19:08:46.543738Z","shell.execute_reply.started":"2026-07-01T19:08:46.538855Z","shell.execute_reply":"2026-07-01T19:08:46.54294Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\n\nROOT = \"/kaggle/working/SlowFormer/ada_vit\"\n\ndirs = [\n    \"checkpoints\",\n    \"output\",\n    \"train\",\n]\n\nfor d in dirs:\n    os.makedirs(os.path.join(ROOT, d), exist_ok=True)\n\nprint(\"✓ Output directories created.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:09:35.905542Z","iopub.execute_input":"2026-07-01T19:09:35.906345Z","iopub.status.idle":"2026-07-01T19:09:35.912095Z","shell.execute_reply.started":"2026-07-01T19:09:35.906304Z","shell.execute_reply":"2026-07-01T19:09:35.911197Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd /kaggle/working/SlowFormer/ada_vit\n\n!python ada_main.py \\\n    /kaggle/working/imagenet \\\n    --model ada_step_deit_small_patch16_224 \\\n    --ada-head \\\n    --ada-layer \\\n    --ada-token-with-mlp \\\n    --flops-dict /kaggle/working/AdaViT/adavit_ckpt/deit-s-h-l-tmlp_flops_dict.pth \\\n    --eval_checkpoint /kaggle/working/ada_deit_small.tar \\\n    --num-gpu 1 \\\n    --batch-size 32 \\\n    --workers 4 \\\n    --no-aug \\\n    --amp \\\n    --output /kaggle/working/SlowFormer/ada_vit/output","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:35:58.921304Z","iopub.execute_input":"2026-07-01T19:35:58.921713Z","iopub.status.idle":"2026-07-01T19:35:59.787366Z","shell.execute_reply.started":"2026-07-01T19:35:58.921685Z","shell.execute_reply":"2026-07-01T19:35:59.786639Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\nroot = Path(\"/kaggle/working/SlowFormer/ada_vit/output/train\")\n\nruns = sorted(root.iterdir(), key=lambda x: x.stat().st_mtime)\n\nlatest = runs[-1]\n\nprint(latest)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:39:56.326717Z","iopub.execute_input":"2026-07-01T19:39:56.327572Z","iopub.status.idle":"2026-07-01T19:39:56.333455Z","shell.execute_reply.started":"2026-07-01T19:39:56.327522Z","shell.execute_reply":"2026-07-01T19:39:56.33278Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from pathlib import Path\n\nfor f in sorted(latest.glob(\"checkpoint-*.pth.tar\")):\n    print(f.name)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:40:02.428032Z","iopub.execute_input":"2026-07-01T19:40:02.428818Z","iopub.status.idle":"2026-07-01T19:40:02.434261Z","shell.execute_reply.started":"2026-07-01T19:40:02.428778Z","shell.execute_reply":"2026-07-01T19:40:02.433658Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import torch\nimport os\n\nbest = None\n\nfor f in latest.glob(\"checkpoint-*.pth.tar\"):\n    ckpt = torch.load(f, map_location=\"cpu\", weights_only=False)\n\n    metric = ckpt.get(\"metric\", None)\n\n    print(os.path.basename(f), metric)\n\n    if best is None or metric > best[1]:\n        best = (f, metric)\n\nprint(\"\\nBest checkpoint:\")\nprint(best)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:40:07.487828Z","iopub.execute_input":"2026-07-01T19:40:07.488075Z","iopub.status.idle":"2026-07-01T19:40:07.823641Z","shell.execute_reply.started":"2026-07-01T19:40:07.488056Z","shell.execute_reply":"2026-07-01T19:40:07.822974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\n# Checkpoint metrics\nepochs = [0, 1, 2, 3, 4]\ntop1 = [9.536, 4.146, 3.396, 1.854, 2.540]\n\nplt.figure(figsize=(8,5))\nplt.plot(epochs, top1, marker='o', linewidth=2)\n\nbest_epoch = epochs[top1.index(min(top1))]\nbest_acc = min(top1)\n\nplt.scatter(best_epoch, best_acc, s=120)\nplt.annotate(\n    f'Best\\nEpoch {best_epoch}\\nTop-1={best_acc:.3f}%',\n    xy=(best_epoch, best_acc),\n    xytext=(best_epoch+0.2, best_acc+1),\n    arrowprops=dict(arrowstyle=\"->\")\n)\n\nplt.title(\"SlowFormer Attack Progress on AdaViT (DeiT-S)\")\nplt.xlabel(\"Epoch\")\nplt.ylabel(\"Top-1 Accuracy (%)\")\nplt.xticks(epochs)\nplt.grid(True)\n\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:41:31.958502Z","iopub.execute_input":"2026-07-01T19:41:31.959323Z","iopub.status.idle":"2026-07-01T19:41:32.160297Z","shell.execute_reply.started":"2026-07-01T19:41:31.959294Z","shell.execute_reply":"2026-07-01T19:41:32.159631Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\ndf = pd.DataFrame({\n    \"Model\": [\n        \"AdaViT (Clean)\",\n        \"SlowFormer Epoch 0\",\n        \"SlowFormer Epoch 1\",\n        \"SlowFormer Epoch 2\",\n        \"SlowFormer Epoch 3 ⭐\",\n        \"SlowFormer Epoch 4\"\n    ],\n    \"Top-1 Accuracy (%)\": [\n        77.300,\n        9.536,\n        4.146,\n        3.396,\n        1.854,\n        2.540\n    ]\n})\n\nbaseline = 77.300\n\ndf[\"Accuracy Drop (%)\"] = baseline - df[\"Top-1 Accuracy (%)\"]\ndf[\"Accuracy Retained (%)\"] = (\n    df[\"Top-1 Accuracy (%)\"] / baseline * 100\n)\n\nprint(df.round(3))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:41:58.98892Z","iopub.execute_input":"2026-07-01T19:41:58.98953Z","iopub.status.idle":"2026-07-01T19:41:59.004919Z","shell.execute_reply.started":"2026-07-01T19:41:58.989499Z","shell.execute_reply":"2026-07-01T19:41:59.004236Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ngflops = pd.DataFrame({\n    \"Checkpoint\": [\n        \"Clean\",\n        \"Epoch 0\",\n        \"Epoch 1\",\n        \"Epoch 2\",\n        \"Epoch 3 ⭐\",\n        \"Epoch 4\"\n    ],\n    \"GFLOPs\": [\n        2.300,   # Clean AdaViT\n        2.458,   # Epoch 0\n        np.nan,  # Unknown\n        np.nan,  # Unknown\n        np.nan,  # Unknown\n        2.902    # Epoch 4 (from your log)\n    ]\n})\n\ngflops[\"GFLOPs Increase\"] = gflops[\"GFLOPs\"] - 2.300\n\ndisplay(gflops.round(3))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-01T19:42:18.253913Z","iopub.execute_input":"2026-07-01T19:42:18.254502Z","iopub.status.idle":"2026-07-01T19:42:18.272786Z","shell.execute_reply.started":"2026-07-01T19:42:18.254471Z","shell.execute_reply":"2026-07-01T19:42:18.272112Z"}},"outputs":[],"execution_count":null}]}