Correcoes 5 notebooks
This commit is contained in:
@@ -327,250 +327,93 @@
|
||||
"## 2.1 Phase 2 augmentation settings\n",
|
||||
"<!-- augmentation-table -->\n",
|
||||
"\n",
|
||||
"The Phase 2 augmentation configs define a deliberately light policy. The table below is generated from `classifier/configs/phase2/*.json` and `DFFImagePipeline.DEFAULTS`, so it documents the actual values available to training rather than a manually copied list.\n"
|
||||
"The Phase 2 augmentation runs use one shared light policy. Instead of listing every pipeline default, the next cell reads the actual Phase 2 config files and reports only the stochastic operations that are active during training. Values marked `config` are written in the run JSON files; values marked `pipeline default` are active because the config gives partial overrides and the pipeline fills the rest from `DFFImagePipeline.DEFAULTS`.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": null,
|
||||
"id": "428047fa",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th>run</th>\n",
|
||||
" <th>p2d_resnet18_aug</th>\n",
|
||||
" <th>p2d_simplecnn_aug</th>\n",
|
||||
" <th>p2e_resnet18_facecrop_aug</th>\n",
|
||||
" <th>p2e_simplecnn_facecrop_aug</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>setting</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>blur_p</th>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>blur_radius</th>\n",
|
||||
" <td>[0.1, 1.5]</td>\n",
|
||||
" <td>[0.1, 1.5]</td>\n",
|
||||
" <td>[0.1, 1.5]</td>\n",
|
||||
" <td>[0.1, 1.5]</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>brightness</th>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>center_jitter</th>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>contrast</th>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>crop_scale</th>\n",
|
||||
" <td>[0.85, 1.0]</td>\n",
|
||||
" <td>[0.85, 1.0]</td>\n",
|
||||
" <td>[0.85, 1.0]</td>\n",
|
||||
" <td>[0.85, 1.0]</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>erase_p</th>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" <td>0.2</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>erase_scale</th>\n",
|
||||
" <td>[0.02, 0.15]</td>\n",
|
||||
" <td>[0.02, 0.15]</td>\n",
|
||||
" <td>[0.02, 0.15]</td>\n",
|
||||
" <td>[0.02, 0.15]</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>grayscale_p</th>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>hflip_p</th>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>hue</th>\n",
|
||||
" <td>0.02</td>\n",
|
||||
" <td>0.02</td>\n",
|
||||
" <td>0.02</td>\n",
|
||||
" <td>0.02</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>jpeg_p</th>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>jpeg_quality</th>\n",
|
||||
" <td>[65, 95]</td>\n",
|
||||
" <td>[65, 95]</td>\n",
|
||||
" <td>[65, 95]</td>\n",
|
||||
" <td>[65, 95]</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>noise_p</th>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" <td>0.3</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>noise_std</th>\n",
|
||||
" <td>0.04</td>\n",
|
||||
" <td>0.04</td>\n",
|
||||
" <td>0.04</td>\n",
|
||||
" <td>0.04</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>rotation_degrees</th>\n",
|
||||
" <td>10</td>\n",
|
||||
" <td>10</td>\n",
|
||||
" <td>10</td>\n",
|
||||
" <td>10</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>saturation</th>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" <td>0.1</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
"run p2d_resnet18_aug p2d_simplecnn_aug p2e_resnet18_facecrop_aug \\\n",
|
||||
"setting \n",
|
||||
"blur_p 0.1 0.1 0.1 \n",
|
||||
"blur_radius [0.1, 1.5] [0.1, 1.5] [0.1, 1.5] \n",
|
||||
"brightness 0.2 0.2 0.2 \n",
|
||||
"center_jitter 0.1 0.1 0.1 \n",
|
||||
"contrast 0.2 0.2 0.2 \n",
|
||||
"crop_scale [0.85, 1.0] [0.85, 1.0] [0.85, 1.0] \n",
|
||||
"erase_p 0.2 0.2 0.2 \n",
|
||||
"erase_scale [0.02, 0.15] [0.02, 0.15] [0.02, 0.15] \n",
|
||||
"grayscale_p 0.1 0.1 0.1 \n",
|
||||
"hflip_p 0.5 0.5 0.5 \n",
|
||||
"hue 0.02 0.02 0.02 \n",
|
||||
"jpeg_p 0.3 0.3 0.3 \n",
|
||||
"jpeg_quality [65, 95] [65, 95] [65, 95] \n",
|
||||
"noise_p 0.3 0.3 0.3 \n",
|
||||
"noise_std 0.04 0.04 0.04 \n",
|
||||
"rotation_degrees 10 10 10 \n",
|
||||
"saturation 0.1 0.1 0.1 \n",
|
||||
"\n",
|
||||
"run p2e_simplecnn_facecrop_aug \n",
|
||||
"setting \n",
|
||||
"blur_p 0.1 \n",
|
||||
"blur_radius [0.1, 1.5] \n",
|
||||
"brightness 0.2 \n",
|
||||
"center_jitter 0.1 \n",
|
||||
"contrast 0.2 \n",
|
||||
"crop_scale [0.85, 1.0] \n",
|
||||
"erase_p 0.2 \n",
|
||||
"erase_scale [0.02, 0.15] \n",
|
||||
"grayscale_p 0.1 \n",
|
||||
"hflip_p 0.5 \n",
|
||||
"hue 0.02 \n",
|
||||
"jpeg_p 0.3 \n",
|
||||
"jpeg_quality [65, 95] \n",
|
||||
"noise_p 0.3 \n",
|
||||
"noise_std 0.04 \n",
|
||||
"rotation_degrees 10 \n",
|
||||
"saturation 0.1 "
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# <!-- augmentation-table -->\n",
|
||||
"phase2_aug_runs = [\n",
|
||||
" \"p2d_resnet18_aug\",\n",
|
||||
" \"p2d_simplecnn_aug\",\n",
|
||||
" \"p2e_resnet18_facecrop_aug\",\n",
|
||||
" \"p2e_simplecnn_facecrop_aug\",\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"rows = []\n",
|
||||
"for run_name in phase2_aug_runs:\n",
|
||||
" cfg_path = CONFIGS_DIR / \"phase2\" / f\"{run_name}.json\"\n",
|
||||
"aug_run_paths = sorted((CONFIGS_DIR / \"phase2\").glob(\"*.json\"))\n",
|
||||
"aug_runs = []\n",
|
||||
"for cfg_path in aug_run_paths:\n",
|
||||
" cfg = load_config(str(cfg_path))\n",
|
||||
" aug_cfg = cfg.get(\"augment\") or {}\n",
|
||||
" merged = {**DFFImagePipeline.DEFAULTS, **aug_cfg}\n",
|
||||
" for key in [\n",
|
||||
" \"crop_scale\", \"center_jitter\", \"hflip_p\", \"rotation_degrees\",\n",
|
||||
" \"brightness\", \"contrast\", \"saturation\", \"hue\", \"grayscale_p\",\n",
|
||||
" \"blur_p\", \"blur_radius\", \"jpeg_p\", \"jpeg_quality\", \"erase_p\",\n",
|
||||
" \"erase_scale\", \"noise_p\", \"noise_std\",\n",
|
||||
" ]:\n",
|
||||
" rows.append({\n",
|
||||
" \"run\": run_name,\n",
|
||||
" \"data_dir\": cfg.get(\"data_dir\"),\n",
|
||||
" \"setting\": key,\n",
|
||||
" \"value\": merged.get(key),\n",
|
||||
" \"explicit_in_config\": key in aug_cfg,\n",
|
||||
" })\n",
|
||||
" if cfg.get(\"augment\"):\n",
|
||||
" aug_runs.append((cfg_path.stem, cfg))\n",
|
||||
"\n",
|
||||
"augmentation_table = pd.DataFrame(rows)\n",
|
||||
"display(augmentation_table.pivot(index=\"setting\", columns=\"run\", values=\"value\"))\n"
|
||||
"active_keys = []\n",
|
||||
"for key in DFFImagePipeline.DEFAULTS:\n",
|
||||
" values = []\n",
|
||||
" for _, cfg in aug_runs:\n",
|
||||
" merged = {**DFFImagePipeline.DEFAULTS, **cfg.get(\"augment\", {})}\n",
|
||||
" value = merged.get(key)\n",
|
||||
" values.append(value)\n",
|
||||
" if any(value not in (None, 0, 0.0, [1.0, 1.0], [1, 1]) for value in values):\n",
|
||||
" active_keys.append(key)\n",
|
||||
"\n",
|
||||
"setting_groups = {\n",
|
||||
" \"crop_scale\": \"crop jitter\",\n",
|
||||
" \"center_jitter\": \"crop jitter\",\n",
|
||||
" \"hflip_p\": \"geometry\",\n",
|
||||
" \"rotation_degrees\": \"geometry\",\n",
|
||||
" \"brightness\": \"color\",\n",
|
||||
" \"contrast\": \"color\",\n",
|
||||
" \"saturation\": \"color\",\n",
|
||||
" \"hue\": \"color\",\n",
|
||||
" \"grayscale_p\": \"color\",\n",
|
||||
" \"blur_p\": \"quality degradation\",\n",
|
||||
" \"blur_radius\": \"quality degradation\",\n",
|
||||
" \"jpeg_p\": \"quality degradation\",\n",
|
||||
" \"jpeg_quality\": \"quality degradation\",\n",
|
||||
" \"erase_p\": \"occlusion/noise\",\n",
|
||||
" \"erase_scale\": \"occlusion/noise\",\n",
|
||||
" \"noise_p\": \"occlusion/noise\",\n",
|
||||
" \"noise_std\": \"occlusion/noise\",\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"def compact_value(value):\n",
|
||||
" if isinstance(value, float):\n",
|
||||
" return f\"{value:g}\"\n",
|
||||
" if isinstance(value, list):\n",
|
||||
" return \"[\" + \", \".join(compact_value(v) for v in value) + \"]\"\n",
|
||||
" return str(value)\n",
|
||||
"\n",
|
||||
"summary_rows = []\n",
|
||||
"for key in active_keys:\n",
|
||||
" merged_values = []\n",
|
||||
" explicit = []\n",
|
||||
" for run_name, cfg in aug_runs:\n",
|
||||
" aug_cfg = cfg.get(\"augment\", {})\n",
|
||||
" merged = {**DFFImagePipeline.DEFAULTS, **aug_cfg}\n",
|
||||
" merged_values.append(merged.get(key))\n",
|
||||
" explicit.append(key in aug_cfg)\n",
|
||||
" same_value = all(value == merged_values[0] for value in merged_values)\n",
|
||||
" source = \"config\" if any(explicit) else \"pipeline default\"\n",
|
||||
" summary_rows.append({\n",
|
||||
" \"group\": setting_groups.get(key, \"other\"),\n",
|
||||
" \"setting\": key,\n",
|
||||
" \"phase2_value\": compact_value(merged_values[0]) if same_value else \"varies by run\",\n",
|
||||
" \"value_source\": source,\n",
|
||||
" })\n",
|
||||
"\n",
|
||||
"augmentation_summary = pd.DataFrame(summary_rows)\n",
|
||||
"run_summary = pd.DataFrame([\n",
|
||||
" {\n",
|
||||
" \"run\": run_name,\n",
|
||||
" \"model\": cfg.get(\"backbone\"),\n",
|
||||
" \"data_dir\": cfg.get(\"data_dir\"),\n",
|
||||
" \"explicit_aug_keys\": len(cfg.get(\"augment\", {})),\n",
|
||||
" }\n",
|
||||
" for run_name, cfg in aug_runs\n",
|
||||
"])\n",
|
||||
"\n",
|
||||
"print(\"Augmentation runs read from configs:\")\n",
|
||||
"display(run_summary)\n",
|
||||
"display(augmentation_summary)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -579,7 +422,9 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- augmentation-table -->\n",
|
||||
"**Readout:** Phase 2 explicitly reduces several defaults: rotation is `10` degrees instead of the pipeline default `15`, color jitter is milder, blur probability is `0.1`, erase probability is `0.2`, and Gaussian noise uses `p=0.3`, `std=0.04`. JPEG recompression is inherited from the pipeline defaults when augmentation is enabled. Validation/test still bypass all stochastic operations because their pipeline is called with `train=False`.\n"
|
||||
"These settings are intentionally modest. Crop jitter, flips, and rotation test whether the detector is robust to small pose and framing changes. Color jitter, grayscale, blur, JPEG recompression, and Gaussian noise test whether the model survives normal image-quality variation. Random erase is the strongest perturbation because it can hide local evidence.\n",
|
||||
"\n",
|
||||
"That last point is also the risk: deepfake cues can be subtle, so augmentation can remove useful evidence as well as nuisance variation. This is why Phase 2 treats augmentation as an ablation rather than assuming it will help. Validation and test transforms still use `train=False`, so they keep only deterministic square crop, resize, and normalization.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -737,7 +582,7 @@
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"<!-- facecrop-augmentation-examples -->\n",
|
||||
"**Readout:** evaluation stays stable, while training draws can flip, rotate, jitter color, blur, erase, add noise, or recompress the cropped face. This is exactly the question later tested in Phase 2: whether extra variation helps the facecrop model generalize or over-regularizes it.\n"
|
||||
"For facecropped data, evaluation remains deterministic but training draws can still flip, rotate, jitter color, blur, erase, add noise, or recompress the cropped face. This is the exact Phase 2 question: after the input has already been focused on the face, does extra variation improve robustness or does it hide the evidence the model needs?\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user