-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
171 lines (153 loc) · 4.68 KB
/
config.py
File metadata and controls
171 lines (153 loc) · 4.68 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
Configuration file for the Image Classifier project
Contains all configurable parameters and settings
"""
import os
from pathlib import Path
# Project paths
PROJECT_ROOT = Path(__file__).parent
DATA_DIR = PROJECT_ROOT / "data"
MODELS_DIR = PROJECT_ROOT / "models"
LOGS_DIR = PROJECT_ROOT / "logs"
EXAMPLES_DIR = PROJECT_ROOT / "examples"
TESTS_DIR = PROJECT_ROOT / "tests"
# Model configuration
MODEL_CONFIG = {
'input_shape': (256, 256, 3),
'batch_size': 32,
'validation_split': 0.2,
'test_split': 0.1,
'random_seed': 123,
}
# Training configuration
TRAINING_CONFIG = {
'epochs': 20,
'patience': 3,
'learning_rate': 0.001,
'optimizer': 'adam',
'loss_function': 'binary_crossentropy',
'metrics': ['accuracy'],
'early_stopping_monitor': 'val_loss',
'early_stopping_mode': 'min',
'restore_best_weights': True,
}
# Data configuration
DATA_CONFIG = {
'supported_formats': ['.jpg', '.jpeg', '.png', '.bmp', '.gif'],
'target_size': (256, 256),
'color_mode': 'rgb',
'interpolation': 'bilinear',
'normalization_factor': 255.0,
}
# Model architecture configuration
ARCHITECTURE_CONFIG = {
'conv_layers': [
{'filters': 16, 'kernel_size': (3, 3), 'activation': 'relu'},
{'filters': 32, 'kernel_size': (3, 3), 'activation': 'relu'},
{'filters': 16, 'kernel_size': (3, 3), 'activation': 'relu'},
],
'dense_layers': [
{'units': 256, 'activation': 'relu'},
{'units': 1, 'activation': 'sigmoid'},
],
'dropout_rate': 0.5,
'regularization': None,
}
# Logging configuration
LOGGING_CONFIG = {
'level': 'INFO',
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
'file_handler': True,
'console_handler': True,
'log_file': 'training.log',
}
# Evaluation configuration
EVALUATION_CONFIG = {
'metrics': ['accuracy', 'precision', 'recall'],
'confusion_matrix': True,
'classification_report': True,
'roc_curve': True,
'pr_curve': True,
}
# Visualization configuration
VISUALIZATION_CONFIG = {
'figure_size': (15, 5),
'dpi': 300,
'save_format': 'png',
'show_plots': True,
'save_plots': True,
'plot_style': 'default',
}
# Performance configuration
PERFORMANCE_CONFIG = {
'use_mixed_precision': True,
'use_gpu': True,
'memory_growth': True,
'parallel_processing': True,
'cache_dataset': True,
'prefetch_buffer': 'AUTOTUNE',
}
# File paths
PATHS = {
'data': str(DATA_DIR),
'models': str(MODELS_DIR),
'logs': str(LOGS_DIR),
'examples': str(EXAMPLES_DIR),
'tests': str(TESTS_DIR),
'sample_data': str(DATA_DIR / "sample"),
'trained_model': str(MODELS_DIR / "image_classifier.h5"),
'training_history': str(LOGS_DIR / "training_history.png"),
'model_summary': str(LOGS_DIR / "model_summary.txt"),
}
# Create necessary directories
def create_directories():
"""Create necessary project directories"""
directories = [DATA_DIR, MODELS_DIR, LOGS_DIR]
for directory in directories:
directory.mkdir(exist_ok=True)
# Environment variables
ENV_VARS = {
'CUDA_VISIBLE_DEVICES': os.getenv('CUDA_VISIBLE_DEVICES', ''),
'TF_FORCE_GPU_ALLOW_GROWTH': os.getenv('TF_FORCE_GPU_ALLOW_GROWTH', 'true'),
'TF_CPP_MIN_LOG_LEVEL': os.getenv('TF_CPP_MIN_LOG_LEVEL', '2'),
}
# Default parameters for command line arguments
DEFAULT_ARGS = {
'data_dir': str(DATA_DIR),
'model_name': 'v1',
'input_shape': (256, 256, 3),
'epochs': 20,
'batch_size': 32,
'validation_split': 0.2,
'patience': 3,
'num_samples': 50,
'create_sample': True,
}
# Validation rules
VALIDATION_RULES = {
'min_images_per_class': 10,
'max_image_size': (2048, 2048),
'min_image_size': (32, 32),
'supported_formats': ['.jpg', '.jpeg', '.png', '.bmp', '.gif'],
'max_classes': 10,
'min_classes': 2,
}
# Error messages
ERROR_MESSAGES = {
'data_dir_not_found': "Data directory '{dir}' not found",
'insufficient_images': "Insufficient images in class '{class_name}'. Minimum required: {min_count}",
'invalid_image_format': "Invalid image format '{format}'. Supported formats: {supported}",
'model_not_found': "Model file '{model_path}' not found",
'training_failed': "Training failed: {error}",
'prediction_failed': "Prediction failed: {error}",
}
# Success messages
SUCCESS_MESSAGES = {
'setup_complete': "Project setup completed successfully!",
'training_complete': "Training completed successfully!",
'model_saved': "Model saved to: {path}",
'prediction_success': "Prediction completed: {class_name} (confidence: {confidence:.3f})",
'evaluation_complete': "Evaluation completed successfully!",
}
# Initialize directories on import
create_directories()