{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":112509,"databundleVersionId":14254895,"sourceType":"competition"},{"sourceId":285516575,"sourceType":"kernelVersion"},{"sourceId":285865832,"sourceType":"kernelVersion"}],"dockerImageVersionId":31192,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"The notebook below preprocesses the images using the ConvNext-large model, and then trains a head model for final predictions.\n\ntotal = clover + dead + green\n\nGDM = clover + green","metadata":{}},{"cell_type":"code","source":"!pip install --no-index --find-links /kaggle/input/transformers-wheel torch tqdm torchvision optuna-integration[xgboost] transformers==4.38.2.0 protobuf==3.20.3","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-12-17T05:58:05.773993Z","iopub.execute_input":"2025-12-17T05:58:05.774541Z","iopub.status.idle":"2025-12-17T06:01:23.984231Z","shell.execute_reply.started":"2025-12-17T05:58:05.774518Z","shell.execute_reply":"2025-12-17T06:01:23.982971Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport optuna\nfrom sklearn.model_selection import train_test_split, KFold, cross_val_score\nimport torch\nimport torch.nn as nn\nimport torch.optim as optim\nfrom torch.utils.data import Dataset, DataLoader\nfrom torchvision.models import convnext_large\nfrom PIL import Image\nimport urllib.request\nimport torchvision.transforms as T\nfrom sklearn.metrics import mean_squared_error, r2_score\nfrom tqdm import tqdm\nimport cv2\n\nLEARNING_RATE = 1e-3\nWEIGHT_DECAY = 1e-4\nEPOCHS = 50\ndevice = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\nMAIN_PATH = \"/kaggle/input/csiro-biomass\"\nWEIGHTS_PATH = \"/kaggle/input/convnext-models/convnext_large_state_dict.pth\"","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:23.985762Z","iopub.execute_input":"2025-12-17T06:01:23.986107Z","iopub.status.idle":"2025-12-17T06:01:29.002705Z","shell.execute_reply.started":"2025-12-17T06:01:23.986069Z","shell.execute_reply":"2025-12-17T06:01:29.001772Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/csiro-biomass/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/csiro-biomass/test.csv\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:29.005192Z","iopub.execute_input":"2025-12-17T06:01:29.005783Z","iopub.status.idle":"2025-12-17T06:01:29.035885Z","shell.execute_reply.started":"2025-12-17T06:01:29.005732Z","shell.execute_reply":"2025-12-17T06:01:29.034961Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i, _ in train_data.iterrows():\n    train_data.loc[i, \"sample_id\"] = train_data.loc[i, \"sample_id\"].split(\"_\")[0]\ncols = [c for c in train_data.columns if c not in [\"target_name\", \"target\"]]\ndf_static = (\n    train_data[cols]\n      .drop_duplicates(subset=\"sample_id\")\n)\n\ndf_pivot = (\n    train_data.pivot(index=\"sample_id\", columns=\"target_name\", values=\"target\")\n      .rename(columns=lambda x: f\"{x}_target\")\n      .reset_index()\n)\n\ndf_final = df_static.merge(df_pivot, on=\"sample_id\", how=\"left\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:29.036926Z","iopub.execute_input":"2025-12-17T06:01:29.037391Z","iopub.status.idle":"2025-12-17T06:01:29.509190Z","shell.execute_reply.started":"2025-12-17T06:01:29.037368Z","shell.execute_reply":"2025-12-17T06:01:29.508529Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df_final","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:29.510047Z","iopub.execute_input":"2025-12-17T06:01:29.510252Z","iopub.status.idle":"2025-12-17T06:01:29.538488Z","shell.execute_reply.started":"2025-12-17T06:01:29.510235Z","shell.execute_reply":"2025-12-17T06:01:29.537916Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = convnext_large(weights=None)\nstate_dict = torch.load(WEIGHTS_PATH, map_location=\"cpu\")\nmodel.load_state_dict(state_dict)\n\npreprocess = T.Compose([\n    T.Resize(480, interpolation=T.InterpolationMode.BILINEAR),\n    T.CenterCrop(480),\n    T.ToTensor(),\n    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),\n])\n\nmodel.classifier = nn.Identity()\nmodel.eval()\nmodel.to(device)\n\nprint(f\"ConvNeXt Large Ready !\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:29.539404Z","iopub.execute_input":"2025-12-17T06:01:29.539714Z","iopub.status.idle":"2025-12-17T06:01:39.513820Z","shell.execute_reply.started":"2025-12-17T06:01:29.539686Z","shell.execute_reply":"2025-12-17T06:01:39.513060Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class Head(nn.Module):\n    def __init__(self, in_features = 1536, hidden_features = 512, out_features = 3):\n        super().__init__()\n        self.layers = nn.Sequential(\n            nn.Linear(in_features, hidden_features),\n            nn.BatchNorm1d(hidden_features),\n            nn.ReLU(),\n            nn.Linear(hidden_features, hidden_features // 2),\n            nn.BatchNorm1d(hidden_features // 2),\n            nn.ReLU(),\n            nn.Linear(hidden_features // 2, hidden_features // 4),\n            nn.BatchNorm1d(hidden_features // 4),\n            nn.ReLU(),\n            nn.Linear(hidden_features // 4, out_features),\n            nn.ReLU()\n        )\n    def forward(self, x):\n        return self.layers(x)\nHead_model = Head().to(device)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:39.514542Z","iopub.execute_input":"2025-12-17T06:01:39.514756Z","iopub.status.idle":"2025-12-17T06:01:39.538094Z","shell.execute_reply.started":"2025-12-17T06:01:39.514722Z","shell.execute_reply":"2025-12-17T06:01:39.537403Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preprocessed_images = []\nfor _, row in tqdm(df_final.iterrows(), total=len(df_final)):\n    image_path = os.path.join(MAIN_PATH, row[\"image_path\"])\n    try:\n        img = Image.open(image_path).convert(\"RGB\")\n    except Exception as e:\n        print(f\"Skipping bad image {image_path}: {e}\")\n        continue\n    img_tensor = preprocess(img).unsqueeze(0).to(device)\n    with torch.no_grad():\n        feature = model(img_tensor)\n\n    preprocessed_images.append(feature.cpu())\n    \npreprocessed_images = torch.cat(preprocessed_images, dim=0)\n\nprint(f\"Final Tensor Shape: {preprocessed_images.shape}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:01:39.538937Z","iopub.execute_input":"2025-12-17T06:01:39.539235Z","iopub.status.idle":"2025-12-17T06:02:50.523141Z","shell.execute_reply.started":"2025-12-17T06:01:39.539198Z","shell.execute_reply":"2025-12-17T06:02:50.522387Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = preprocessed_images.detach().cpu().numpy().squeeze()\ny = df_final.loc[:, [\"Dry_Clover_g_target\", \"Dry_Dead_g_target\", \"Dry_Green_g_target\"]]\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.525574Z","iopub.execute_input":"2025-12-17T06:02:50.525850Z","iopub.status.idle":"2025-12-17T06:02:50.534403Z","shell.execute_reply.started":"2025-12-17T06:02:50.525831Z","shell.execute_reply":"2025-12-17T06:02:50.533718Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class custom_dataset(Dataset):\n    def __init__(self, features, labels):\n        self.features = features\n        self.labels = labels\n\n    def __len__(self):\n        return self.features.shape[0]\n\n    def __getitem__(self, idx):\n        return self.features[idx], torch.tensor(self.labels.iloc[idx, :].values, dtype = torch.float32)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.536221Z","iopub.execute_input":"2025-12-17T06:02:50.536475Z","iopub.status.idle":"2025-12-17T06:02:50.551561Z","shell.execute_reply.started":"2025-12-17T06:02:50.536456Z","shell.execute_reply":"2025-12-17T06:02:50.550655Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_dataset = custom_dataset(X, y)\n# test_dataset = custom_dataset(X_test, y_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.552351Z","iopub.execute_input":"2025-12-17T06:02:50.552565Z","iopub.status.idle":"2025-12-17T06:02:50.566711Z","shell.execute_reply.started":"2025-12-17T06:02:50.552549Z","shell.execute_reply":"2025-12-17T06:02:50.565997Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_loader = DataLoader(train_dataset, batch_size = 16, shuffle = True)\n# test_loader = DataLoader(test_dataset, batch_size = 16)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.567599Z","iopub.execute_input":"2025-12-17T06:02:50.567875Z","iopub.status.idle":"2025-12-17T06:02:50.582230Z","shell.execute_reply.started":"2025-12-17T06:02:50.567856Z","shell.execute_reply":"2025-12-17T06:02:50.581549Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"optimizer = optim.SGD(Head_model.parameters(), lr = LEARNING_RATE, weight_decay = WEIGHT_DECAY)\ncriterion = nn.MSELoss()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.582963Z","iopub.execute_input":"2025-12-17T06:02:50.583233Z","iopub.status.idle":"2025-12-17T06:02:50.598840Z","shell.execute_reply.started":"2025-12-17T06:02:50.583198Z","shell.execute_reply":"2025-12-17T06:02:50.598125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for epoch in range(EPOCHS):\n    Head_model.train()\n    tr_loss = 0\n    for batch_features, batch_labels in train_loader:    \n        batch_features, batch_labels = batch_features.to(device), batch_labels.to(device)    \n        outputs = Head_model(batch_features)\n\n        loss = criterion(outputs, batch_labels)\n        tr_loss += loss\n        optimizer.zero_grad()\n        loss.backward()\n        optimizer.step()\n        \n    print(f\"Epoch : {epoch + 1}\\tTraining Loss : {tr_loss/len(train_loader)}\\t\", end = \"\")\n    \n    # Head_model.eval()\n    # ev_loss = 0\n\n    # with torch.no_grad():\n    #     for batch_features, batch_labels in test_loader:\n    #         batch_features, batch_labels = batch_features.to(device), batch_labels.to(device)\n    #         outputs = Head_model(batch_features)\n    #         ev_loss += criterion(outputs, batch_labels)\n\n    # print(f\"Testing Loss : {ev_loss/len(test_loader)}\", end = \"\\n\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:50.599488Z","iopub.execute_input":"2025-12-17T06:02:50.599686Z","iopub.status.idle":"2025-12-17T06:02:54.601061Z","shell.execute_reply.started":"2025-12-17T06:02:50.599650Z","shell.execute_reply":"2025-12-17T06:02:54.600163Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Epoch : 1\tTraining Loss : 509.7394714355469\tTesting Loss : 435.598388671875\n# Epoch : 2\tTraining Loss : 306.1037292480469\tTesting Loss : 378.2073974609375\n# Epoch : 3\tTraining Loss : 244.49224853515625\tTesting Loss : 223.3683319091797\n# Epoch : 4\tTraining Loss : 182.3696746826172\tTesting Loss : 132.74989318847656\n# Epoch : 5\tTraining Loss : 162.31732177734375\tTesting Loss : 155.07223510742188\n# Epoch : 6\tTraining Loss : 142.522705078125\tTesting Loss : 134.06503295898438\n# Epoch : 7\tTraining Loss : 139.18353271484375\tTesting Loss : 116.65501403808594\n# Epoch : 8\tTraining Loss : 107.38734436035156\tTesting Loss : 106.592041015625\n# Epoch : 9\tTraining Loss : 96.70783996582031\tTesting Loss : 106.45513916015625\n# Epoch : 10\tTraining Loss : 83.0400619506836\tTesting Loss : 88.18980407714844\n# Epoch : 11\tTraining Loss : 87.65103149414062\tTesting Loss : 92.88655090332031\n# Epoch : 12\tTraining Loss : 74.4643783569336\tTesting Loss : 84.85013580322266\n# Epoch : 13\tTraining Loss : 90.7572021484375\tTesting Loss : 102.75528717041016\n# Epoch : 14\tTraining Loss : 76.44073486328125\tTesting Loss : 92.16221618652344\n# Epoch : 15\tTraining Loss : 75.53275299072266\tTesting Loss : 117.849853515625\n# Epoch : 16\tTraining Loss : 57.77907180786133\tTesting Loss : 92.01152801513672\n# Epoch : 17\tTraining Loss : 63.42722702026367\tTesting Loss : 101.90560913085938\n# Epoch : 18\tTraining Loss : 48.60166931152344\tTesting Loss : 94.0804443359375\n# Epoch : 19\tTraining Loss : 69.17282104492188\tTesting Loss : 108.01081848144531\n# Epoch : 20\tTraining Loss : 57.4012451171875\tTesting Loss : 84.14154815673828\n# Epoch : 21\tTraining Loss : 50.487083435058594\tTesting Loss : 89.59910583496094\n# Epoch : 22\tTraining Loss : 57.33448791503906\tTesting Loss : 96.7498779296875\n# Epoch : 23\tTraining Loss : 57.73798370361328\tTesting Loss : 99.14515686035156\n# Epoch : 24\tTraining Loss : 55.85783386230469\tTesting Loss : 91.93644714355469\n# Epoch : 25\tTraining Loss : 39.81120681762695\tTesting Loss : 97.05919647216797\n# Epoch : 26\tTraining Loss : 45.873165130615234\tTesting Loss : 97.57281494140625\n# Epoch : 27\tTraining Loss : 34.281883239746094\tTesting Loss : 91.88189697265625\n# Epoch : 28\tTraining Loss : 44.30299758911133\tTesting Loss : 86.68551635742188\n# Epoch : 29\tTraining Loss : 37.810523986816406\tTesting Loss : 89.29451751708984\n# Epoch : 30\tTraining Loss : 33.93898010253906\tTesting Loss : 82.92346954345703\n# Epoch : 31\tTraining Loss : 32.61309051513672\tTesting Loss : 85.87872314453125\n# Epoch : 32\tTraining Loss : 41.67609786987305\tTesting Loss : 97.77323913574219\n# Epoch : 33\tTraining Loss : 34.44379425048828\tTesting Loss : 96.1205825805664\n# Epoch : 34\tTraining Loss : 46.46975326538086\tTesting Loss : 87.3957290649414\n# Epoch : 35\tTraining Loss : 43.855411529541016\tTesting Loss : 110.03338623046875\n# Epoch : 36\tTraining Loss : 37.257041931152344\tTesting Loss : 93.68960571289062\n# Epoch : 37\tTraining Loss : 32.80340576171875\tTesting Loss : 98.14605712890625\n# Epoch : 38\tTraining Loss : 28.301939010620117\tTesting Loss : 89.64006805419922\n# Epoch : 39\tTraining Loss : 35.20630645751953\tTesting Loss : 101.0854263305664\n# Epoch : 40\tTraining Loss : 35.37874221801758\tTesting Loss : 111.38578796386719\n# Epoch : 41\tTraining Loss : 32.96018600463867\tTesting Loss : 102.99736022949219\n# Epoch : 42\tTraining Loss : 39.54618835449219\tTesting Loss : 100.2508544921875\n# Epoch : 43\tTraining Loss : 33.30972671508789\tTesting Loss : 92.52153778076172\n# Epoch : 44\tTraining Loss : 30.766279220581055\tTesting Loss : 90.24549865722656\n# Epoch : 45\tTraining Loss : 30.155160903930664\tTesting Loss : 90.09384155273438\n# Epoch : 46\tTraining Loss : 31.024824142456055\tTesting Loss : 90.932861328125\n# Epoch : 47\tTraining Loss : 35.93645477294922\tTesting Loss : 89.64955139160156\n# Epoch : 48\tTraining Loss : 37.44270706176758\tTesting Loss : 92.80351257324219\n# Epoch : 49\tTraining Loss : 32.633331298828125\tTesting Loss : 96.83451080322266\n# Epoch : 50\tTraining Loss : 31.361690521240234\tTesting Loss : 87.34698486328125","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.601989Z","iopub.execute_input":"2025-12-17T06:02:54.602360Z","iopub.status.idle":"2025-12-17T06:02:54.607078Z","shell.execute_reply.started":"2025-12-17T06:02:54.602330Z","shell.execute_reply":"2025-12-17T06:02:54.606278Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# pred_c = xgb_clover.predict(X_test_c)\n# pred_d = xgb_dead.predict(X_test_d)\n# pred_g = xgb_green.predict(X_test_g)\n# print(f\"Predictions Calculated !\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.608140Z","iopub.execute_input":"2025-12-17T06:02:54.608420Z","iopub.status.idle":"2025-12-17T06:02:54.625240Z","shell.execute_reply.started":"2025-12-17T06:02:54.608395Z","shell.execute_reply":"2025-12-17T06:02:54.624485Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# def calculate_r2(preds, targets):\n#     target_mean = np.mean(targets, axis=0)\n#     ss_tot = np.sum((targets - target_mean) ** 2, axis=0)\n#     ss_res = np.sum((targets - preds) ** 2, axis=0)\n#     r2 = 1 - (ss_res / (ss_tot + 1e-8))\n#     return np.mean(r2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.626074Z","iopub.execute_input":"2025-12-17T06:02:54.626352Z","iopub.status.idle":"2025-12-17T06:02:54.641415Z","shell.execute_reply.started":"2025-12-17T06:02:54.626327Z","shell.execute_reply":"2025-12-17T06:02:54.640520Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# mse_c = mean_squared_error(pred_c, y_test_c)\n# r2_c = calculate_r2(pred_c, y_test_c)\n# mse_d = mean_squared_error(pred_d, y_test_d)\n# r2_d = calculate_r2(pred_d, y_test_d)\n# mse_g = mean_squared_error(pred_g, y_test_g)\n# r2_g = calculate_r2(pred_g, y_test_g)\n\n# print(f\"MSE (Clover): {mse_c}\\n\\nR2 Score (Clover): {r2_c}\\n\")\n# print(f\"MSE (Dead): {mse_d}\\n\\nR2 Score (Dead): {r2_d}\\n\")\n# print(f\"MSE (Green): {mse_g}\\n\\nR2 Score (Green): {r2_g}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.642266Z","iopub.execute_input":"2025-12-17T06:02:54.642543Z","iopub.status.idle":"2025-12-17T06:02:54.654151Z","shell.execute_reply.started":"2025-12-17T06:02:54.642518Z","shell.execute_reply":"2025-12-17T06:02:54.653448Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data_2 = test_data.copy()\nfor i, _ in test_data.iterrows():\n    test_data_2.loc[i, \"sample_id\"] = test_data_2.loc[i, \"sample_id\"].split(\"_\")[0]\ncols = [c for c in test_data_2.columns if c not in [\"target_name\", \"target\"]]\nfinal_test_data = (\n    test_data_2[cols]\n      .drop_duplicates(subset=\"sample_id\")\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.654891Z","iopub.execute_input":"2025-12-17T06:02:54.655129Z","iopub.status.idle":"2025-12-17T06:02:54.671091Z","shell.execute_reply.started":"2025-12-17T06:02:54.655104Z","shell.execute_reply":"2025-12-17T06:02:54.670325Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preprocessed_test_images = []\nfor _, row in tqdm(final_test_data.iterrows(), total=len(final_test_data)):\n    image_path = os.path.join(MAIN_PATH, row[\"image_path\"])\n    try:\n        img = Image.open(image_path).convert(\"RGB\")\n    except Exception as e:\n        print(f\"Skipping bad image {image_path}: {e}\")\n        continue\n    img_tensor = preprocess(img).unsqueeze(0).to(device)\n    with torch.no_grad():\n        feature = model(img_tensor)\n\n    preprocessed_test_images.append(feature.cpu())\n    \npreprocessed_test_images = torch.cat(preprocessed_test_images, dim=0).detach().cpu().numpy().squeeze()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:54.671957Z","iopub.execute_input":"2025-12-17T06:02:54.672339Z","iopub.status.idle":"2025-12-17T06:02:55.005732Z","shell.execute_reply.started":"2025-12-17T06:02:54.672313Z","shell.execute_reply":"2025-12-17T06:02:55.004990Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preprocessed_test_images.shape[0]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:55.006656Z","iopub.execute_input":"2025-12-17T06:02:55.007073Z","iopub.status.idle":"2025-12-17T06:02:55.012938Z","shell.execute_reply.started":"2025-12-17T06:02:55.007045Z","shell.execute_reply":"2025-12-17T06:02:55.012296Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Only for saving the notebook\nif preprocessed_test_images.shape[0] == 1536:\n    preprocessed_test_images = preprocessed_test_images.reshape(1, 1536)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:02:55.013838Z","iopub.execute_input":"2025-12-17T06:02:55.014089Z","iopub.status.idle":"2025-12-17T06:02:55.025684Z","shell.execute_reply.started":"2025-12-17T06:02:55.014063Z","shell.execute_reply":"2025-12-17T06:02:55.025066Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Head_model.eval()\noutputs = Head_model(torch.tensor(preprocessed_test_images, dtype = torch.float32).to(device))\nclover = outputs[:, 0]\ndead = outputs[:, 1]\ngreen = outputs[:, 2]\ntotal = clover + dead + green\ngdm = clover + green\nprint(f\"Targets Predicted !\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:13:23.855641Z","iopub.execute_input":"2025-12-17T06:13:23.856534Z","iopub.status.idle":"2025-12-17T06:13:23.869571Z","shell.execute_reply.started":"2025-12-17T06:13:23.856507Z","shell.execute_reply":"2025-12-17T06:13:23.868724Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"c, d, g, t, gd = 0, 0, 0, 0, 0\nsubmission = []\nfor _, row in test_data.iterrows():\n    if \"Clover\" in row[\"sample_id\"]:\n        value = clover[c].item()\n        c += 1\n    elif \"Dead\" in row[\"sample_id\"]:\n        value = dead[d].item()\n        d += 1\n    elif \"Green\" in row[\"sample_id\"]:\n        value = green[g].item()\n        g += 1\n    elif \"Total\" in row[\"sample_id\"]:\n        value = total[t].item()\n        t += 1\n    else:\n        value = gdm[gd].item()\n        gd += 1\n    submission_entry = {\n        \"sample_id\" : row[\"sample_id\"],\n        \"target\" : value\n    }\n    submission.append(submission_entry)\nsubmission = pd.DataFrame(submission)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:13:25.083531Z","iopub.execute_input":"2025-12-17T06:13:25.083874Z","iopub.status.idle":"2025-12-17T06:13:25.093173Z","shell.execute_reply.started":"2025-12-17T06:13:25.083853Z","shell.execute_reply":"2025-12-17T06:13:25.092279Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:13:27.141983Z","iopub.execute_input":"2025-12-17T06:13:27.142822Z","iopub.status.idle":"2025-12-17T06:13:27.151664Z","shell.execute_reply.started":"2025-12-17T06:13:27.142792Z","shell.execute_reply":"2025-12-17T06:13:27.150577Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv(\"/kaggle/working/submission.csv\", index = False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:13:30.053847Z","iopub.execute_input":"2025-12-17T06:13:30.054452Z","iopub.status.idle":"2025-12-17T06:13:30.064939Z","shell.execute_reply.started":"2025-12-17T06:13:30.054426Z","shell.execute_reply":"2025-12-17T06:13:30.064083Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"The entire notebook runs successfully, if error happens, I don't just know why.\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-12-17T06:13:30.420967Z","iopub.execute_input":"2025-12-17T06:13:30.421272Z","iopub.status.idle":"2025-12-17T06:13:30.426777Z","shell.execute_reply.started":"2025-12-17T06:13:30.421247Z","shell.execute_reply":"2025-12-17T06:13:30.425973Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}