-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaugment_data.py
More file actions
124 lines (112 loc) · 3.49 KB
/
Copy pathaugment_data.py
File metadata and controls
124 lines (112 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""
Standalone script for data augmentation.
Apply various augmentations to your training dataset.
"""
from dataset_manager import DatasetManager
import argparse
def main():
parser = argparse.ArgumentParser(
description="Augment dataset with rotations, intensity adjustments, and noise"
)
parser.add_argument(
'--dataset',
type=str,
required=True,
help='Path to the dataset directory'
)
parser.add_argument(
'--split',
type=str,
default='train',
help='Split to augment (default: train)'
)
parser.add_argument(
'--factor',
type=int,
default=2,
help='Number of augmented versions per image (default: 2)'
)
parser.add_argument(
'--rotations',
type=float,
nargs='+',
default=None,
help='Specific rotation angles in degrees (e.g., -15 15 -30 30). If not specified, uses random rotations.'
)
parser.add_argument(
'--intensity-min',
type=float,
default=0.8,
help='Minimum intensity multiplier (default: 0.8)'
)
parser.add_argument(
'--intensity-max',
type=float,
default=1.2,
help='Maximum intensity multiplier (default: 1.2)'
)
parser.add_argument(
'--noise',
type=float,
default=0.02,
help='Gaussian noise sigma (0-1 range, default: 0.02)'
)
parser.add_argument(
'--no-combinations',
action='store_true',
help='Apply only single augmentation per image instead of combinations'
)
parser.add_argument(
'--suffix',
type=str,
default='_aug',
help='Suffix for augmented image filenames (default: _aug)'
)
parser.add_argument(
'--seed',
type=int,
default=42,
help='Random seed for reproducibility (default: 42)'
)
args = parser.parse_args()
print("="*70)
print("DATA AUGMENTATION TOOL")
print("="*70)
print(f"\nDataset: {args.dataset}")
print(f"Split: {args.split}")
print(f"Augmentation factor: {args.factor}")
print(f"\nAugmentation settings:")
print(f" Rotations: {args.rotations if args.rotations else 'Random (-30 to 30 degrees)'}")
print(f" Intensity range: ({args.intensity_min}, {args.intensity_max})")
print(f" Noise sigma: {args.noise}")
print(f" Combinations: {not args.no_combinations}")
print(f" Random seed: {args.seed}")
print()
# Create manager and augment
manager = DatasetManager()
try:
summary = manager.augment_dataset(
dataset_path=args.dataset,
split=args.split,
augmentation_factor=args.factor,
rotation_angles=args.rotations,
intensity_range=(args.intensity_min, args.intensity_max),
noise_sigma=args.noise,
combinations=not args.no_combinations,
output_suffix=args.suffix,
seed=args.seed
)
print("\n" + "="*70)
print("AUGMENTATION COMPLETE!")
print("="*70)
print(f"Original images: {summary['original_images']}")
print(f"Augmented images: {summary['augmented_images']}")
print(f"Total images: {summary['total_images']}")
print(f"Total annotations: {summary['total_annotations']}")
print("="*70)
except Exception as e:
print(f"\n❌ Error: {e}")
return 1
return 0
if __name__ == "__main__":
exit(main())