{"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":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\nimport kagglehub","metadata":{"_uuid":"80e38318-bf62-4947-a636-3d8a21a5f64d","_cell_guid":"ef2a7d9c-5188-4472-bfbc-9d080ca0fb57","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:45:03.071710Z","iopub.execute_input":"2026-07-25T17:45:03.072051Z","iopub.status.idle":"2026-07-25T17:45:03.657992Z","shell.execute_reply.started":"2026-07-25T17:45:03.072022Z","shell.execute_reply":"2026-07-25T17:45:03.656984Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nimport kagglehub\n\n# Download latest version\npath = kagglehub.competition_download('csiro-biomass')\n\nprint(\"Path to competition files:\", path)","metadata":{"_uuid":"4ec2aad1-6402-4c3d-842c-eadeac67c52d","_cell_guid":"be52fafd-d92e-4235-a2e8-0bd67b9083d1","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:45:03.659901Z","iopub.execute_input":"2026-07-25T17:45:03.660247Z","iopub.status.idle":"2026-07-25T17:45:04.371592Z","shell.execute_reply.started":"2026-07-25T17:45:03.660219Z","shell.execute_reply":"2026-07-25T17:45:04.370606Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Task: Predict pasture biomass from top‑view RGB images of fields.","metadata":{"_uuid":"f2a16bc3-c6df-421b-9d33-734fbdaec511","_cell_guid":"5c04faa1-2c3c-4edd-95a2-39fd617bf9e8","trusted":true,"collapsed":false,"jupyter":{"outputs_hidden":false}}},{"cell_type":"code","source":"train=pd.read_csv('/kaggle/input/competitions/csiro-biomass/train.csv')\ntest=pd.read_csv('/kaggle/input/competitions/csiro-biomass/test.csv')","metadata":{"_uuid":"fc161b8e-1edc-4a7b-8364-693a50ea79ec","_cell_guid":"5f2c4b23-2c93-403f-97cf-522c72bd2320","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:45:04.372775Z","iopub.execute_input":"2026-07-25T17:45:04.373139Z","iopub.status.idle":"2026-07-25T17:45:04.391807Z","shell.execute_reply.started":"2026-07-25T17:45:04.373094Z","shell.execute_reply":"2026-07-25T17:45:04.390814Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(train.shape)\nprint(test.shape)\nprint(train.columns)\nprint(test.columns)","metadata":{"_uuid":"2d303de2-5982-44be-b57b-9dece6a7cde7","_cell_guid":"23509ead-12be-4138-865d-e05d5a90f9b5","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:45:04.393095Z","iopub.execute_input":"2026-07-25T17:45:04.393814Z","iopub.status.idle":"2026-07-25T17:45:04.399600Z","shell.execute_reply.started":"2026-07-25T17:45:04.393781Z","shell.execute_reply":"2026-07-25T17:45:04.398396Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nBASE_DIR = '/kaggle/input/competitions/csiro-biomass'\n\ndef load_image(path, size=(128, 128)):\n    full_path = os.path.join(BASE_DIR, path)\n    img = tf.keras.utils.load_img(full_path, target_size=size)\n    img = tf.keras.utils.img_to_array(img)\n    img = img / 255.0\n    return img\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-25T17:47:18.212544Z","iopub.execute_input":"2026-07-25T17:47:18.212902Z","iopub.status.idle":"2026-07-25T17:47:18.218742Z","shell.execute_reply.started":"2026-07-25T17:47:18.212871Z","shell.execute_reply":"2026-07-25T17:47:18.217725Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = np.array([load_image(p) for p in train['image_path']])\ny = train['target'].values","metadata":{"_uuid":"659affe8-e7eb-4b71-b4e4-a7284407652d","_cell_guid":"97cdc66f-790c-4b7c-a5d1-cdc8844543d6","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:47:21.564724Z","iopub.execute_input":"2026-07-25T17:47:21.565090Z","iopub.status.idle":"2026-07-25T17:49:12.138737Z","shell.execute_reply.started":"2026-07-25T17:47:21.565058Z","shell.execute_reply":"2026-07-25T17:49:12.137528Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import layers,models\nmodel=models.Sequential([\n    layers.Input(shape=(128, 128, 3)),\n    layers.Conv2D(32, (3, 3), activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(64, (3, 3), activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Conv2D(128, (3, 3), activation='relu'),\n    layers.MaxPooling2D(),\n    layers.Flatten(),\n    layers.Dense(128, activation='relu'),\n    layers.Dense(1)\n    \n])","metadata":{"_uuid":"5817e445-1e4c-43e1-a999-be636e65bbe6","_cell_guid":"3701663b-4af1-4ec7-a2c3-7c7be49c5707","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:50:31.237492Z","iopub.execute_input":"2026-07-25T17:50:31.238708Z","iopub.status.idle":"2026-07-25T17:50:31.318643Z","shell.execute_reply.started":"2026-07-25T17:50:31.238658Z","shell.execute_reply":"2026-07-25T17:50:31.317531Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(\n    optimizer=\"adam\",\n    loss=\"mse\",\n    metrics=[\"mae\",\"accuracy\"]\n)","metadata":{"_uuid":"ab8a51a3-3eb8-426e-932b-146a253f4972","_cell_guid":"21dbf4f4-515a-40d6-b712-7243eaf93685","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:52:54.467155Z","iopub.execute_input":"2026-07-25T17:52:54.467844Z","iopub.status.idle":"2026-07-25T17:52:54.477970Z","shell.execute_reply.started":"2026-07-25T17:52:54.467810Z","shell.execute_reply":"2026-07-25T17:52:54.476783Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2)\nmodel.fit(x_train,y_train)\nhistory = model.fit(\n    x_train, y_train,\n    validation_data=(x_test, y_test),\n    epochs=5,\n    batch_size=32\n)","metadata":{"_uuid":"047a127a-8f83-4349-9dfc-1978d3cfbeb6","_cell_guid":"f8139fff-e30d-47e3-aa3a-fb631b4f76d9","trusted":true,"collapsed":false,"execution":{"iopub.status.busy":"2026-07-25T17:52:57.129985Z","iopub.execute_input":"2026-07-25T17:52:57.130533Z","iopub.status.idle":"2026-07-25T17:55:37.838866Z","shell.execute_reply.started":"2026-07-25T17:52:57.130490Z","shell.execute_reply":"2026-07-25T17:55:37.837541Z"},"jupyter":{"outputs_hidden":false}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds=model.predict(x_test)\nmae = np.mean(np.abs(preds - y_test) <= 5)\nprint(mae)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-25T17:57:38.015819Z","iopub.execute_input":"2026-07-25T17:57:38.016330Z","iopub.status.idle":"2026-07-25T17:57:39.828358Z","shell.execute_reply.started":"2026-07-25T17:57:38.016284Z","shell.execute_reply":"2026-07-25T17:57:39.827476Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import mlflow\nimport mlflow.tensorflow\nmlflow.set_experiment(\"csiro_biomass_baseline\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-25T17:59:49.146188Z","iopub.execute_input":"2026-07-25T17:59:49.146569Z","iopub.status.idle":"2026-07-25T17:59:59.118827Z","shell.execute_reply.started":"2026-07-25T17:59:49.146532Z","shell.execute_reply":"2026-07-25T17:59:59.117938Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"with mlflow.start_run():\n    mlflow.log_param(\"image_size\", 128)\n    mlflow.log_param(\"epochs\", 5)\n    mlflow.log_param(\"batch_size\", 32)\n\n    history = model.fit(\n        x_train, y_train,\n        validation_data=(x_test, y_test),\n        epochs=5,\n        batch_size=32\n    )\n\n    mlflow.log_metric(\"val_mae\", history.history[\"val_mae\"][-1])\n    mlflow.log_metric(\"val_loss\", history.history[\"val_loss\"][-1])\n\n    mlflow.tensorflow.log_model(model, \"model\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-07-25T18:00:14.129920Z","iopub.execute_input":"2026-07-25T18:00:14.130492Z"}},"outputs":[],"execution_count":null}]}