From 036064ea10395de82b4029db39f354bea21c0d24 Mon Sep 17 00:00:00 2001 From: YANG Shiyun Date: Fri, 4 Sep 2026 15:42:09 +0900 Subject: [PATCH 1/2] Document CV scaling and use scaled features for reconstruction --- feature-decoding/README.md | 26 ++++++++++++++++ reconstruction/atlasnet/README.md | 30 +++++++++++++++++-- .../atlasnet/recon_from_features.py | 10 +++---- 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/feature-decoding/README.md b/feature-decoding/README.md index 7c60911..ce0c15d 100644 --- a/feature-decoding/README.md +++ b/feature-decoding/README.md @@ -57,6 +57,32 @@ python scripts/predict_feature_fastl2lir.py train-3d-natural-objects_rep3_fmap_t Output: decoded features saved to the path specified by `decoded_feature.path` in the config. +### Cross-validation for feature scaling + +Cross-validation predictions on the training dataset are used to estimate the +standard deviation of decoded features for feature scaling. + +#### 1. Train cross-validation decoders + +```bash +uv run python scripts/cv_train_decoder_fastl2lir.py config/cv_train-3d-natural-objects-image_rep3_fmap_fmriprep_5000voxel_atlasnet.yaml +``` + +Output: cross-validation decoders are saved to the path specified by +`decoder.path` in the CV config. + +#### 2. Decode cross-validation features + +```bash +uv run python scripts/cv_predict_feature_fastl2lir.py config/cv_train-3d-natural-objects-image_rep3_fmap_fmriprep_5000voxel_atlasnet.yaml +``` + +Output: cross-validated training features are saved to the path specified by +`decoded_feature.path` in the CV config. + +The cross-validated features are subsequently used for feature scaling. See +[the AtlasNet reconstruction instructions](../reconstruction/atlasnet/README.md#feature-scaling). + ## Config files Config files are located in `config/`. Each file specifies a combination of training and test datasets. diff --git a/reconstruction/atlasnet/README.md b/reconstruction/atlasnet/README.md index 32bd2e4..5f11ee4 100644 --- a/reconstruction/atlasnet/README.md +++ b/reconstruction/atlasnet/README.md @@ -20,6 +20,29 @@ The AtlasNet model weights must be placed at: data/models/atlasnet/network_crtd.pth ``` +## Feature scaling + +Before reconstructing shapes from decoded features, scale the decoded test +features using the standard deviation estimated from cross-validation predictions. + +First, complete: + +1. Regular feature decoder training and feature prediction. +2. Cross-validation decoder training and prediction described in + [feature-decoding/README.md](../../feature-decoding/README.md#cross-validation-for-feature-scaling). + +Then run: + +```bash +uv run feature_scaling.py +``` + +For every experiment listed in `feature_scaling.py`, the scaled features are saved to: + +```text +data/decoded-features/{experiment}_scaled_traincvstd/atlasnet/ +``` + ## Usage ```bash @@ -51,9 +74,12 @@ true/ ### From decoded features -Input: `data/decoded-features/{experiment}/atlasnet/` +Input: `data/decoded-features/{experiment}_scaled_traincvstd/atlasnet/` + +Output: `data/reconstruction/atlasnet_encoder_bn5/decoded/{experiment}_scaled_traincvstd/{subject}/{roi}/` -Output: `data/reconstruction/atlasnet_encoder_bn5/decoded/{experiment}/{subject}/{roi}/` +`recon_from_features.py` reconstructs shapes only from the scaled decoded-feature +datasets listed in `decoded_datasets`. ``` decoded/ diff --git a/reconstruction/atlasnet/recon_from_features.py b/reconstruction/atlasnet/recon_from_features.py index 623f5ee..de0e592 100644 --- a/reconstruction/atlasnet/recon_from_features.py +++ b/reconstruction/atlasnet/recon_from_features.py @@ -152,11 +152,11 @@ def reconstruct_all(recon, features, output_dir, source_layer, subject=None, roi # Decoded features decoded_datasets = [ - 'train-3d-natural-objects_rep3_test-3d-natural-objects_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000', - 'train-3d-natural-objects_rep3_test-3d-artificial-objects-image_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000', - 'train-3d-natural-objects_rep3_test-3d-artificial-objects-rds_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000', - 'train-3d-natural-objects_rep3_test-3d-contour-matched-rds-horizontal-shape-variants_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000', - 'train-3d-natural-objects_rep3_test-3d-contour-matched-rds-thin-tilt-variants_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000', + 'train-3d-natural-objects_rep3_test-3d-natural-objects_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000_scaled_traincvstd', + 'train-3d-natural-objects_rep3_test-3d-artificial-objects-image_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000_scaled_traincvstd', + 'train-3d-natural-objects_rep3_test-3d-artificial-objects-rds_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000_scaled_traincvstd', + 'train-3d-natural-objects_rep3_test-3d-contour-matched-rds-horizontal-shape-variants_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000_scaled_traincvstd', + 'train-3d-natural-objects_rep3_test-3d-contour-matched-rds-thin-tilt-variants_rep8_fmap_fmriprep_5000voxel_fastl2lir_alpha5000_scaled_traincvstd', ] subjects = ['S1', 'S2', 'S3', 'S4', 'S5'] From c2b708f5c10c46a55791bb8b4b32971daf7b4df6 Mon Sep 17 00:00:00 2001 From: YANG Shiyun Date: Fri, 4 Sep 2026 15:45:11 +0900 Subject: [PATCH 2/2] Document CV scaling and use scaled features for reconstruction --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 03d23ea..c8d1416 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,11 @@ git submodule update --init --recursive See [feature-extraction/atlasnet/README.md](feature-extraction/atlasnet/README.md) for instructions. 2. **Feature decoding** — Decode DNN features from fMRI data using linear decoders. - See [feature-decoding/README.md](feature-decoding/README.md) for instructions. - -3. **Reconstruction** — Reconstruct 3D shapes from true or decoded features using AtlasNet. - See [reconstruction/atlasnet/README.md](reconstruction/atlasnet/README.md) for instructions. + This includes cross-validation training and prediction for estimating the + decoded-feature scaling factor. See + [feature-decoding/README.md](feature-decoding/README.md) for instructions. +3. **Feature scaling and reconstruction** — Scale decoded features using the + cross-validation estimate, then reconstruct 3D shapes from true or scaled + decoded features using AtlasNet. See + [reconstruction/atlasnet/README.md](reconstruction/atlasnet/README.md) for instructions.