Skip to content

Configuration Reference

Complete reference for all configuration parameters in autoStructN2V.

Configuration Structure

The configuration is a nested dictionary with the following top-level structure:

python
config = {
    # General parameters
    'experiment_name': '...',
    'input_dir': '...',
    # ...

    # Stage 1 parameters
    'stage1': {
        'features': 64,
        # ...
    },

    # Stage 2 parameters
    'stage2': {
        'features': 64,
        'extractor': {
            # Extractor parameters
        }
    }
}

General Parameters

Experiment Setup

ParameterTypeDefaultDescription
experiment_namestr'autoStructN2V_experiment'Name for the experiment directory
output_dirstr'./results'Base directory for all outputs
input_dirstrRequiredDirectory containing input images
random_seedint42Random seed for reproducibility
image_extensionstr'.tif'File extension for input images

Device and Execution

ParameterTypeDefaultDescription
devicestr'cuda'Device for training ('cuda' or 'cpu')
verboseboolFalsePrint detailed information and visualizations

Dataset Splitting

ParameterTypeDefaultDescription
split_ratiotuple(0.7, 0.15, 0.15)Train/validation/test split ratios (must sum to 1.0)

Training Control

ParameterTypeDefaultDescription
num_epochsint100Maximum number of training epochs
early_stoppingboolTrueEnable early stopping
early_stopping_patienceint10Epochs without improvement before stopping

Stage Execution Control

ParameterTypeDefaultDescription
run_stage1boolTrueExecute Stage 1 training
run_stage2boolTrueExecute Stage 2 training

Note: At least one of run_stage1 or run_stage2 must be True.

Stage 1 Parameters

All Stage 1 parameters are nested under the 'stage1' key.

Model Architecture

ParameterTypeDefaultRangeDescription
featuresint6416-128Base number of features in U-Net
num_layersint22-4Number of down/upsampling layers in U-Net
use_resize_convboolTrue-Use resize convolution (reduces artifacts)
upsampling_modestr'bilinear''bilinear', 'nearest', 'bicubic'Upsampling interpolation mode

Training Parameters

ParameterTypeDefaultRangeDescription
patch_sizeint3232-128Size of image patches
batch_sizeint41-64Training batch size
learning_ratefloat1e-41e-5 to 1e-3Learning rate for optimizer
patches_per_imageint10050-500Number of patches extracted per image

Masking Parameters

ParameterTypeDefaultRangeDescription
mask_percentagefloat15.010.0-30.0Percentage of pixels to mask
mask_center_sizeint11-3Size of mask center (blind spot)
masking_strategyint00, 1, 2Strategy for masked values: 0=local mean, 1=zeros, 2=random

ROI Selection

ParameterTypeDefaultRangeDescription
use_roiboolTrue-Enable ROI-based patch selection
roi_thresholdfloat0.50.3-0.7Intensity threshold for ROI detection
scale_factorfloat0.250.1-0.5Scale factor for ROI preprocessing
select_backgroundboolTrue-Select background (True) vs structures (False)

Data Augmentation

ParameterTypeDefaultDescription
use_augmentationboolTrueEnable data augmentation (flips, rotations)

Example Stage 1 Configuration

python
'stage1': {
    # Architecture
    'features': 64,
    'num_layers': 3,
    'use_resize_conv': True,
    'upsampling_mode': 'bilinear',

    # Training
    'patch_size': 64,
    'batch_size': 8,
    'learning_rate': 2e-4,
    'patches_per_image': 150,

    # Masking
    'mask_percentage': 15.0,
    'mask_center_size': 1,
    'masking_strategy': 0,

    # ROI
    'use_roi': True,
    'roi_threshold': 0.5,
    'scale_factor': 0.25,
    'select_background': True,

    # Augmentation
    'use_augmentation': True,
}

Stage 2 Parameters

All Stage 2 parameters are nested under the 'stage2' key.

Model Architecture

Same as Stage 1 architecture parameters.

ParameterTypeDefaultRangeDescription
featuresint6416-128Base number of features in U-Net
num_layersint22-5Number of down/upsampling layers
use_resize_convboolTrue-Use resize convolution
upsampling_modestr'bilinear''bilinear', 'nearest', 'bicubic'Upsampling mode

Training Parameters

ParameterTypeDefaultRangeDescription
patch_sizeint6464-256Size of image patches (typically larger than Stage 1)
batch_sizeint21-32Training batch size
learning_ratefloat1e-51e-6 to 1e-4Learning rate (typically lower than Stage 1)
patches_per_imageint200100-1000Number of patches per image

Masking Parameters

ParameterTypeDefaultRangeDescription
mask_percentagefloat10.05.0-20.0Percentage of pixels to mask (typically lower than Stage 1)
masking_strategyint00, 1, 2Masking strategy: 0=local mean, 1=zeros, 2=random

Mask Source Configuration

ParameterTypeDefaultOptionsDescription
mask_sourcestr'stage1''stage1', 'file', 'extractor'Source for creating structural mask
mask_file_pathstrNone-Path to .npy mask file (required if mask_source='file')

Mask Source Options:

  • 'stage1': Use denoised patches from Stage 1 to create mask (default for full pipeline)
  • 'file': Load pre-saved mask from .npy file (for independent Stage 2 execution)
  • 'extractor': Create mask directly from original noisy images

Validation Rules:

  • If run_stage1=False and mask_source='stage1': Error (Stage 1 must run first)
  • If mask_source='file' and mask_file_path=None: Error (file path required)
  • Mask file must exist and be a .npy file

ROI Selection

ParameterTypeDefaultDescription
use_roiboolFalseEnable ROI selection (usually disabled for Stage 2)
roi_thresholdfloat0.5Intensity threshold
scale_factorfloat0.25Scale factor
select_backgroundboolFalseSelect structures (False) instead of background

Data Augmentation

ParameterTypeDefaultDescription
use_augmentationboolTrueEnable data augmentation

Structural Noise Extractor Parameters

Nested under stage2 → extractor. These control how structural patterns are extracted.

Autocorrelation Processing

ParameterTypeDefaultDescription
norm_autocorrboolTrueNormalize autocorrelation by zero-lag value
log_autocorrboolTrueApply log transform to autocorrelation
crop_autocorrboolTrueCrop autocorrelation to center region
adapt_autocorrboolTrueUse adaptive thresholding
adapt_CBfloat50.0Base coefficient for adaptive threshold (5.0-100.0)
adapt_DFfloat0.95Distance factor for adaptive threshold (0.8-0.99)

Ring Analysis Parameters

ParameterTypeDefaultRangeDescription
center_sizeint107-25Size of center square to analyze
base_percentilefloat5030-70Base percentile for thresholding
percentile_decayfloat1.151.0-1.3Threshold decay factor per ring
center_ratio_thresholdfloat0.30.1-0.5Minimum ratio of ring max to center value

Selection Criteria

ParameterTypeDefaultRangeDescription
use_center_proximityboolTrue-Use proximity-based selection criterion
center_proximity_thresholdfloat0.950.5-0.99Threshold for center proximity measure

Post-Processing

ParameterTypeDefaultRangeDescription
keep_center_component_onlyboolTrue-Keep only connected component containing center
max_true_pixelsint2510-30Maximum number of True pixels in final mask

Example Stage 2 Configuration

python
'stage2': {
    # Architecture
    'features': 64,
    'num_layers': 3,
    'use_resize_conv': True,
    'upsampling_mode': 'bilinear',

    # Training
    'patch_size': 96,
    'batch_size': 4,
    'learning_rate': 5e-6,
    'patches_per_image': 250,

    # Masking
    'mask_percentage': 8.0,
    'masking_strategy': 0,

    # Mask source
    'mask_source': 'stage1',

    # ROI (usually disabled)
    'use_roi': False,
    'select_background': False,

    # Extractor configuration
    'extractor': {
        'norm_autocorr': True,
        'log_autocorr': True,
        'crop_autocorr': True,
        'adapt_autocorr': True,
        'adapt_CB': 50.0,
        'adapt_DF': 0.95,
        'center_size': 12,
        'base_percentile': 55,
        'percentile_decay': 1.2,
        'center_ratio_threshold': 0.25,
        'use_center_proximity': True,
        'center_proximity_threshold': 0.9,
        'keep_center_component_only': True,
        'max_true_pixels': 20,
    }
}

Parameter Guidelines

Patch Size Selection

Stage 1: Smaller patches (32-64)

  • Faster training
  • More patches per image
  • Good for general noise removal

Stage 2: Larger patches (64-128)

  • Captures larger structural patterns
  • Better context for structured noise
  • Requires more memory

Rule: Patch size must be divisible by 2^num_layers

Batch Size Selection

Depends on available GPU memory:

GPU MemoryStage 1 BatchStage 2 Batch
4 GB2-41-2
8 GB4-82-4
12+ GB8-164-8

Features and Layers

More features/layers: Better capacity, slower training, more memory Fewer features/layers: Faster, less memory, may underfit

Image ComplexityFeaturesLayers
Simple (low noise)32-482
Moderate642-3
Complex (high noise)64-963-4

Learning Rate

Stage 1: Higher (1e-4 to 2e-4)

  • Fresh training
  • More aggressive learning

Stage 2: Lower (1e-5 to 5e-5)

  • Fine-tuning structured patterns
  • More careful optimization

Mask Percentage

Stage 1: Higher (15-20%)

  • More training signal
  • Faster convergence

Stage 2: Lower (8-12%)

  • Structural patterns are sparse
  • Avoid over-masking

Complete Example Configurations

High-Quality Configuration (Slow, Best Results)

python
config = {
    'input_dir': './data/',
    'experiment_name': 'high_quality',
    'device': 'cuda',
    'num_epochs': 200,
    'early_stopping_patience': 20,
    'verbose': True,

    'stage1': {
        'features': 96,
        'num_layers': 3,
        'patch_size': 64,
        'batch_size': 8,
        'learning_rate': 2e-4,
        'patches_per_image': 200,
        'mask_percentage': 18.0,
    },

    'stage2': {
        'features': 96,
        'num_layers': 4,
        'patch_size': 128,
        'batch_size': 4,
        'learning_rate': 5e-6,
        'patches_per_image': 300,
        'mask_percentage': 8.0,
        'extractor': {
            'center_size': 15,
            'base_percentile': 60,
            'max_true_pixels': 30,
        }
    }
}

Fast Configuration (Quick Experiments)

python
config = {
    'input_dir': './data/',
    'experiment_name': 'fast_test',
    'device': 'cuda',
    'num_epochs': 50,
    'verbose': False,

    'stage1': {
        'features': 48,
        'num_layers': 2,
        'patch_size': 32,
        'batch_size': 16,
        'learning_rate': 2e-4,
        'patches_per_image': 50,
    },

    'stage2': {
        'features': 48,
        'num_layers': 2,
        'patch_size': 64,
        'batch_size': 8,
        'learning_rate': 1e-5,
        'patches_per_image': 100,
    }
}

Memory-Efficient Configuration (Limited GPU)

python
config = {
    'input_dir': './data/',
    'experiment_name': 'low_memory',
    'device': 'cuda',

    'stage1': {
        'features': 32,
        'num_layers': 2,
        'patch_size': 32,
        'batch_size': 2,
        'learning_rate': 1e-4,
        'patches_per_image': 75,
    },

    'stage2': {
        'features': 32,
        'num_layers': 2,
        'patch_size': 48,
        'batch_size': 1,
        'learning_rate': 1e-5,
        'patches_per_image': 150,
    }
}

Configuration Validation

The pipeline automatically validates configuration and provides helpful error messages:

python
# Example validation errors:

# Error: Missing required field
config = {}
# ValueError: input_dir must be specified in the configuration

# Error: Invalid split ratio
config = {'split_ratio': (0.5, 0.3, 0.3)}  # Sums to 1.1
# ValueError: split_ratio must sum to 1.0

# Error: Invalid upsampling mode
config = {'stage1': {'upsampling_mode': 'cubic'}}
# ValueError: Invalid upsampling_mode 'cubic'. Must be one of: ['bilinear', 'nearest', 'bicubic']

# Error: Incompatible stage configuration
config = {'run_stage1': False, 'run_stage2': True, 'stage2': {'mask_source': 'stage1'}}
# ValueError: mask_source cannot be 'stage1' when run_stage1 is False

See Also


Next: Training Guide for training best practices.

Part of DFG Priority Programme SPP2332 "Physics of Parasitism"