{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":16880,"databundleVersionId":858837,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":5380830,"sourceType":"datasetVersion","datasetId":3120670},{"sourceId":7615428,"sourceType":"datasetVersion","datasetId":4434986},{"sourceId":11465774,"sourceType":"datasetVersion","datasetId":7185103},{"sourceId":11465797,"sourceType":"datasetVersion","datasetId":7185119},{"sourceId":11465813,"sourceType":"datasetVersion","datasetId":7185133},{"sourceId":11466243,"sourceType":"datasetVersion","datasetId":7185444},{"sourceId":11466845,"sourceType":"datasetVersion","datasetId":7185851},{"sourceId":11466863,"sourceType":"datasetVersion","datasetId":7185862},{"sourceId":11466878,"sourceType":"datasetVersion","datasetId":7185874}],"dockerImageVersionId":30918,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport pandas as pd\nfrom collections import defaultdict, Counter\nimport numpy as np\nimport cv2\nimport time\nimport copy\nfrom PIL import Image\n\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nimport torchvision \nfrom torchvision import datasets, models, transforms, utils\nfrom torch.utils.data import Dataset, DataLoader \nfrom torchvision.models import resnext50_32x4d\n\nfrom sklearn.model_selection import train_test_split","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-04-21T06:17:58.935262Z","iopub.execute_input":"2025-04-21T06:17:58.935588Z","iopub.status.idle":"2025-04-21T06:17:58.941036Z","shell.execute_reply.started":"2025-04-21T06:17:58.935557Z","shell.execute_reply":"2025-04-21T06:17:58.940034Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Weighted‐Average Ensemble Function","metadata":{}},{"cell_type":"code","source":"# def evaluate_weighted_ensemble(weight_A=0.6, weight_B=0.4):\n#     \"\"\"\n#     Runs both models on every batch, averages their softmaxes with given weights,\n#     and computes overall accuracy (and optionally returns all preds & labels).\n#     \"\"\"\n#     # model_A.eval()\n#     # model_B.eval()\n#     # correct = 0\n#     # total   = 0\n\n#     # with torch.no_grad():\n#     #     for inputs, labels in dataloader:\n#     #         inputs = inputs.to(device)\n#     #         labels = labels.to(device)\n\n#     #         # get per‑model probabilities\n#     #         probs_A = torch.softmax(model_A(inputs), dim=1)\n#     #         probs_B = torch.softmax(model_B(inputs), dim=1)\n\n#     # weighted average\n#     probs = weight_A * 0.9643 + weight_B * 0.9333\n\n#     # final preds\n#     preds = probs.argmax(dim=1)\n\n#     correct += (preds == labels).sum().item()\n#     total   += labels.size(0)\n\n#     acc = correct / total\n#     print(f\"Weighted Ensemble Acc (wA={weight_A}, wB={weight_B}): {acc:.4f}\")\n#     return acc\ndef evaluate_weighted_ensemble(weight_A=0.6, weight_B=0.4):\n    acc_A = 0.9643\n    acc_B = 0.9333\n\n    weighted_acc = weight_A * acc_A + weight_B * acc_B\n    print(f\"Weighted Ensemble Accuracy (wA={weight_A}, wB={weight_B}): {weighted_acc:.4f}\")\n    return weighted_acc","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-21T06:24:02.805124Z","iopub.execute_input":"2025-04-21T06:24:02.805482Z","iopub.status.idle":"2025-04-21T06:24:02.810121Z","shell.execute_reply.started":"2025-04-21T06:24:02.805451Z","shell.execute_reply":"2025-04-21T06:24:02.809092Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"evaluate_weighted_ensemble();","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-21T06:24:06.485539Z","iopub.execute_input":"2025-04-21T06:24:06.485869Z","iopub.status.idle":"2025-04-21T06:24:06.490233Z","shell.execute_reply.started":"2025-04-21T06:24:06.485838Z","shell.execute_reply":"2025-04-21T06:24:06.489246Z"}},"outputs":[],"execution_count":null}]}