{"cells": [{"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "from pathlib import Path\nimport numpy as np\nimport pandas as pd\n\nOUT_DIR  = Path('/kaggle/working')\nPRED_DIR = Path('/kaggle/input/csiro-final-preds-v1')\n\nTARGET_COLS = ['Dry_Green_g', 'Dry_Dead_g', 'Dry_Clover_g', 'GDM_g', 'Dry_Total_g']\n"}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "ids   = np.load(PRED_DIR / 'test_image_ids_order.npy', allow_pickle=True)\npreds = np.load(PRED_DIR / 'test_preds_aligned.npy',    allow_pickle=True)\nprint(f'Loaded predictions: {preds.shape} for {len(set(ids))} unique image(s)')\nprint(f'IDs: {set(ids)}')\nprint(f'Preds[0]: {dict(zip(TARGET_COLS, preds[0].tolist()))}')\n"}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": "# Try to load sample_submission.csv from competition for correct sample_ids\nfor _p in [Path('/kaggle/input/csiro-biomass'), Path('/kaggle/input/csiro-biomass-data')]:\n    _ss = _p / 'sample_submission.csv'\n    if _ss.exists():\n        sample_sub = pd.read_csv(_ss)\n        print(f'sample_submission.csv from {_p}: {len(sample_sub)} rows')\n        break\nelse:\n    # Hardcoded fallback \u2014 competition has exactly 1 test image, IDs are stable\n    sample_sub = pd.DataFrame({\n        'sample_id': [f'ID1001187975__{t}' for t in TARGET_COLS],\n        'target': 0.0,\n    })\n    print('Using hardcoded sample_ids (competition data not mounted)')\n\n# Map predictions keyed by image_id \u2192 {target_name: value}\npred_map = {}\nfor i, img_id in enumerate(ids):\n    pred_map[str(img_id)] = dict(zip(TARGET_COLS, preds[i].tolist()))\n\ndef _lookup(sample_id):\n    img_id, target_name = sample_id.rsplit('__', 1)\n    return pred_map.get(img_id, {}).get(target_name, 0.0)\n\nsample_sub['target'] = sample_sub['sample_id'].apply(_lookup).clip(lower=0)\nassert list(sample_sub.columns) == ['sample_id', 'target'], f'Wrong columns: {sample_sub.columns.tolist()}'\nassert sample_sub['target'].isna().sum() == 0, 'NaN values in submission'\n\nsample_sub.to_csv(OUT_DIR / 'submission.csv', index=False)\nprint(f'submission.csv saved \u2014 {len(sample_sub)} rows')\nprint(sample_sub.to_string())\n"}], "metadata": {"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"}, "language_info": {"name": "python", "version": "3.10.0"}}, "nbformat": 4, "nbformat_minor": 5}