crackmnist_eccv.run_experiment ¶
Run CrackMNIST pollution experiments across seeds, intensities, and splits.
Trains a UNet model under controlled input pollution and evaluates average Dice loss on train/val/test splits across multiple random seeds. Results are written incrementally to a CSV file named after the experiment configuration.
Functions:
| Name | Description |
|---|---|
evaluate | Run model in eval mode and return average DiceLoss over the loader. |
fix_random_seeds | Fix all relevant random seeds for reproducibility. |
get_pollution_config | Return keyword arguments for apply_per_image_pollution. |
parse_python_literal | Convert a string like '[0.1,0.2]' or '[(0.1,0.2)]' to a Python object. |
train_and_evaluate | Train a UNet and evaluate on val and test sets. |
Attributes:
Attributes¶
BATCH_SIZE module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
INTENSITY_RANGE module-attribute ¶
INTENSITY_RANGE = parse_python_literal(args.intensity_range, list)
NAMING_CONSTANT module-attribute ¶
NAMING_CONSTANT = f'{PIXELS}_F9_{SELECTED_POLLUTION_TYPE}_radius{RADIUS}'
PIXELS module-attribute ¶
PIXELS = args.pixels
- API Reference
crackmnist_eccvrun_experiment Attributes
RADIUS module-attribute ¶
RADIUS = args.radius
- API Reference
crackmnist_eccvrun_experiment AttributesNAMING_CONSTANT
SELECTED_POLLUTION_TYPE module-attribute ¶
SELECTED_POLLUTION_TYPE = args.pollution_type
- API Reference
crackmnist_eccvrun_experiment AttributesNAMING_CONSTANT
SIZE module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
args module-attribute ¶
args = parser.parse_args()
- API Reference
crackmnist_eccvrun_experiment Attributes
data_transform module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
parser module-attribute ¶
parser = argparse.ArgumentParser(
description="Run CrackMNIST experiments with flexible settings."
)
- API Reference
crackmnist_eccvrun_experiment Attributesargs
results module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributesdf
target_transform module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
test_dataset_full module-attribute ¶
test_dataset_full = CrackMNIST(
split="test",
pixels=PIXELS,
size=SIZE,
transform=data_transform,
target_transform=target_transform,
)
- API Reference
crackmnist_eccvrun_experiment Attributestest_loader_full
test_loader_full module-attribute ¶
test_loader_full = data.DataLoader(
test_dataset_full, batch_size=BATCH_SIZE, shuffle=False, num_workers=4
)
test_losses_seeds module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
train_dataset_full module-attribute ¶
train_dataset_full = CrackMNIST(
split="train",
pixels=PIXELS,
size=SIZE,
transform=data_transform,
target_transform=target_transform,
)
- API Reference
crackmnist_eccvrun_experiment Attributestrain_loader_full
train_loader_full module-attribute ¶
train_loader_full = data.DataLoader(
train_dataset_full, batch_size=BATCH_SIZE, shuffle=False, num_workers=4
)
train_losses_seeds module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
val_dataset_full module-attribute ¶
val_dataset_full = CrackMNIST(
split="val",
pixels=PIXELS,
size=SIZE,
transform=data_transform,
target_transform=target_transform,
)
- API Reference
crackmnist_eccvrun_experiment Attributesval_loader_full
val_loader_full module-attribute ¶
val_loader_full = data.DataLoader(
val_dataset_full, batch_size=BATCH_SIZE, shuffle=False, num_workers=4
)
val_losses_seeds module-attribute ¶
- API Reference
crackmnist_eccvrun_experiment Attributes
Functions:¶
evaluate ¶
evaluate(
model: Module,
loader: DataLoader,
pollution_ratio: float,
pollution_type: str,
pollution_kwargs: dict,
) -> float
Run model in eval mode and return average DiceLoss over the loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Module | Trained PyTorch model. | required |
| DataLoader | DataLoader to evaluate on. | required |
| float | Fraction of images to pollute. | required |
| str | Type of pollution to apply. | required |
| dict | Additional keyword arguments for the pollution function. | required |
Returns:
| Type | Description |
|---|---|
float | Average DiceLoss as a float. |
Source code in src/crackmnist_eccv/run_experiment.py
fix_random_seeds ¶
get_pollution_config ¶
Return keyword arguments for apply_per_image_pollution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| str | One of 'blob', 'gaussian', 'salt_pepper', 'gaussian_blur'. | required |
| float | tuple[float, float] | Float or (min, max) tuple depending on pollution type. | required |
Returns:
| Type | Description |
|---|---|
dict | Dict with 'pollution_type' and 'pollution_kwargs' keys. |
Raises:
| Type | Description |
|---|---|
ValueError | If the pollution type is unsupported or intensity format is wrong. |
Source code in src/crackmnist_eccv/run_experiment.py
parse_python_literal ¶
parse_python_literal(text: str, expected_type: type) -> list
Convert a string like '[0.1,0.2]' or '[(0.1,0.2)]' to a Python object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| str | String representation of a Python literal. | required |
| type | The expected Python type (e.g. list). | required |
Returns:
| Type | Description |
|---|---|
list | Parsed Python object of the expected type. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError | If parsing fails or type does not match. |
TypeError | If the parsed value is not an instance of expected_type. |
- API Reference
crackmnist_eccvrun_experiment AttributesINTENSITY_RANGE
Source code in src/crackmnist_eccv/run_experiment.py
train_and_evaluate ¶
train_and_evaluate(
train_perc: float, test_perc: float, intensity: float | tuple[float, float], seed: int
) -> tuple[float, float, float]
Train a UNet and evaluate on val and test sets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| float | Fraction of training images to pollute. | required |
| float | Fraction of test images to pollute during evaluation. | required |
| float | tuple[float, float] | Pollution intensity (float or tuple for blob). | required |
| int | Random seed for reproducibility. | required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float] | Tuple of (final_val_loss, final_test_loss, final_train_loss). |