update 3-19
This commit is contained in:
+28
-83
@@ -56,6 +56,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "6a600aed",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -84,6 +85,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d1ea8b19",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1) Build UNet Manifest"
|
||||
@@ -92,6 +94,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "b07b3e69",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -108,21 +111,28 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "dgglybgo5wg",
|
||||
"source": "## 2) Build Refugelike Backbone\n\nThe `refugelike` backbone is a ResNet-50 pre-trained on REFUGE as an optic disc/cup classifier, then stripped of its classification head and used as a frozen or partially-frozen feature extractor in the HyperTower image tower.\n\n**Steps:**\n1. Train the REFUGE classifier (`--train-clf`)\n2. Export its backbone weights to `models/v2/refuge/refugelike_backbone.pt` (`--export-backbone`)\n\nThe classifier checkpoint is saved to `models/v2/refuge/classifier/resnet50/refuge_classifier_best.pt` by default. \nThe exported backbone is what `--backbone refugelike` loads at runtime (see `classes/v2/backbones.py`).",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"id": "b7jt033ul4v",
|
||||
"source": "BACKBONE_PATH = \"models/v2/refuge/refugelike_backbone.pt\"\n\n# Step 1: train the REFUGE classifier (ResNet-50, 30 epochs by default)\n!python3 scripts/main/refuge/refuge_build.py \\\n --train-clf \\\n --manifest manifest.csv \\\n --device cuda\n\n# Step 2: strip the head and export backbone weights\n!python3 scripts/main/refuge/refuge_build.py \\\n --export-backbone {BACKBONE_PATH} \\\n --manifest manifest.csv \\\n --device cuda",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2) Train UNet Segmenter (per-image normalization)\n",
|
||||
"\n",
|
||||
"Current tuned baseline:\n",
|
||||
"- `--device cuda`\n",
|
||||
"- `--batch-size 8`\n",
|
||||
"- `--loader-workers 14`\n",
|
||||
"- `--in-memory-cache`\n",
|
||||
"- `--cache-workers 4`"
|
||||
]
|
||||
"execution_count": null,
|
||||
"outputs": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8df524a2",
|
||||
"metadata": {},
|
||||
"source": "## 2b) Train UNet Segmenter (per-image normalization)\n\nCurrent tuned baseline:\n- `--device cuda`\n- `--batch-size 8`\n- `--loader-workers 14`\n- `--in-memory-cache`\n- `--cache-workers 4`"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "be2b499a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@@ -1270,6 +1280,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a2a3bd04",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5) Run Pipeline Experiments\n",
|
||||
@@ -1283,6 +1294,7 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e395f268",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -1301,41 +1313,18 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "125f35c6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 3b) GT crop — expert segmentation masks crop the optic disc region\n",
|
||||
"!python scripts/main/v2/multirun_hypertower.py \\\n",
|
||||
" --tower-modes single ensemble \\\n",
|
||||
" --eval-modes binary multiclass \\\n",
|
||||
" --epochs 40 --n-splits 5 \\\n",
|
||||
" --backbone refugelike \\\n",
|
||||
" --img-crop-gt \\\n",
|
||||
" --warmup-md-epochs 50 \\\n",
|
||||
" --fused-head \\\n",
|
||||
" --run-name pipeline_gt"
|
||||
]
|
||||
"source": "# 3b) GT crop — expert segmentation masks crop the optic disc region\n!python scripts/main/v2/multirun_hypertower.py \\\n --tower-modes single ensemble \\\n --eval-modes binary multiclass \\\n --epochs 40 --n-splits 5 \\\n --backbone refugelike \\\n --img-crop-manifest manifest.csv \\\n --img-crop-gt \\\n --warmup-md-epochs 50 \\\n --fused-head \\\n --run-name pipeline_gt"
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "83df73ac",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 3c) UNet crop — trained segmenter crops the optic disc region\n",
|
||||
"!python scripts/main/v2/multirun_hypertower.py \\\n",
|
||||
" --tower-modes single ensemble \\\n",
|
||||
" --eval-modes binary multiclass \\\n",
|
||||
" --epochs 40 --n-splits 5 \\\n",
|
||||
" --backbone refugelike \\\n",
|
||||
" --img-crop-manifest analysis_data/unet_manifest.csv \\\n",
|
||||
" --img-crop-weights models/v2/refuge/segmentation/per_image/best.pt \\\n",
|
||||
" --img-crop-normalize per_image \\\n",
|
||||
" --img-crop-cache analysis_data/v2_crops_unet_refuge \\\n",
|
||||
" --warmup-md-epochs 50 \\\n",
|
||||
" --fused-head \\\n",
|
||||
" --run-name pipeline_unet"
|
||||
]
|
||||
"source": "# 3c) UNet crop — trained segmenter crops the optic disc region\n!python scripts/main/v2/multirun_hypertower.py \\\n --tower-modes single ensemble \\\n --eval-modes binary multiclass \\\n --epochs 40 --n-splits 5 \\\n --backbone refugelike \\\n --img-crop-manifest manifest.csv \\\n --img-crop-weights models/v2/refuge/segmentation/per_image/best.pt \\\n --img-crop-normalize per_image \\\n --img-crop-cache analysis_data/v2_crops_unet_refuge \\\n --warmup-md-epochs 50 \\\n --fused-head \\\n --run-name pipeline_unet"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -1353,51 +1342,7 @@
|
||||
"id": "7yrcfu0bv1w",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import subprocess\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"RUN_DIRS = {\n",
|
||||
" \"nocrop\": Path(\"analysis_data/pipeline_nocrop\"),\n",
|
||||
" \"gt\": Path(\"analysis_data/pipeline_gt\"),\n",
|
||||
" \"unet\": Path(\"analysis_data/pipeline_unet\"),\n",
|
||||
"}\n",
|
||||
"EVAL_MODES = [\"binary\", \"multiclass\"]\n",
|
||||
"TOWER_MODES = [\"single\", \"ensemble\"]\n",
|
||||
"\n",
|
||||
"for run_name, run_dir in RUN_DIRS.items():\n",
|
||||
" for eval_mode in EVAL_MODES:\n",
|
||||
" for tower_mode in TOWER_MODES:\n",
|
||||
" mode_dir = run_dir / eval_mode / tower_mode\n",
|
||||
" if not mode_dir.exists():\n",
|
||||
" print(f\" skip (not found): {mode_dir}\")\n",
|
||||
" continue\n",
|
||||
" print(f\"--- {run_name} / {eval_mode} / {tower_mode} ---\")\n",
|
||||
"\n",
|
||||
" # ROC curves\n",
|
||||
" subprocess.run([\n",
|
||||
" \"python\", \"scripts/output_analysis/visualizations/plot_run_roc_v2.py\",\n",
|
||||
" \"--run-dir\", str(run_dir),\n",
|
||||
" \"--eval-mode\", eval_mode,\n",
|
||||
" \"--tower-mode\", tower_mode,\n",
|
||||
" ], check=True)\n",
|
||||
"\n",
|
||||
" # Probability strips — binary only\n",
|
||||
" if eval_mode == \"binary\":\n",
|
||||
" subprocess.run([\n",
|
||||
" \"python\", \"scripts/output_analysis/visualizations/plot_prob_strips.py\",\n",
|
||||
" \"--run-dir\", str(mode_dir),\n",
|
||||
" \"--head\", \"fused\", \"--style\", \"strips\",\n",
|
||||
" ], check=True)\n",
|
||||
"\n",
|
||||
" # Probability triangle-3D — multiclass only\n",
|
||||
" if eval_mode == \"multiclass\":\n",
|
||||
" subprocess.run([\n",
|
||||
" \"python\", \"scripts/output_analysis/visualizations/plot_prob_strips.py\",\n",
|
||||
" \"--run-dir\", str(mode_dir),\n",
|
||||
" \"--head\", \"fused\", \"--style\", \"triangle3d\",\n",
|
||||
" ], check=True)"
|
||||
]
|
||||
"source": "import subprocess\nfrom pathlib import Path\n\nRUN_DIRS = {\n \"nocrop\": (Path(\"analysis_data/pipeline_nocrop\"), [\"single\", \"ensemble\"]),\n \"gt\": (Path(\"analysis_data/pipeline_gt\"), [\"single\", \"ensemble\"]),\n \"unet\": (Path(\"analysis_data/pipeline_unet\"), [\"single\", \"ensemble\"]),\n \"imgonly_nocrop\":(Path(\"analysis_data/pipeline_imgonly_nocrop\"),[\"single\"]),\n \"imgonly_gt\": (Path(\"analysis_data/pipeline_imgonly_gt\"), [\"single\"]),\n \"imgonly_unet\": (Path(\"analysis_data/pipeline_imgonly_unet\"), [\"single\"]),\n}\nEVAL_MODES = [\"binary\", \"multiclass\"]\n\nfor run_name, (run_dir, tower_modes) in RUN_DIRS.items():\n for eval_mode in EVAL_MODES:\n for tower_mode in tower_modes:\n mode_dir = run_dir / eval_mode / tower_mode\n if not mode_dir.exists():\n print(f\" skip (not found): {mode_dir}\")\n continue\n print(f\"--- {run_name} / {eval_mode} / {tower_mode} ---\")\n\n # ROC curves (auto-detects all available probs stems)\n subprocess.run([\n \"python\", \"scripts/output_analysis/visualizations/plot_run_roc_v2.py\",\n \"--run-dir\", str(run_dir),\n \"--eval-mode\", eval_mode,\n \"--tower-mode\", tower_mode,\n ], check=True)\n\n # Probability strips — binary only (auto-detects all heads)\n if eval_mode == \"binary\":\n subprocess.run([\n \"python\", \"scripts/output_analysis/visualizations/plot_prob_strips.py\",\n \"--run-dir\", str(mode_dir),\n \"--style\", \"strips\",\n ], check=True)\n\n # Probability triangle-3D — multiclass only (auto-detects all heads)\n if eval_mode == \"multiclass\":\n subprocess.run([\n \"python\", \"scripts/output_analysis/visualizations/plot_prob_strips.py\",\n \"--run-dir\", str(mode_dir),\n \"--style\", \"triangle3d\",\n ], check=True)"
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
@@ -1458,4 +1403,4 @@
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user