-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
232 lines (180 loc) · 6.65 KB
/
setup.py
File metadata and controls
232 lines (180 loc) · 6.65 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
"""
Setup and Installation Script
Run this first to set up the anomaly detection module
"""
import os
import sys
from pathlib import Path
def print_header(text):
"""Print formatted header"""
print("\n" + "="*70)
print(f" {text}")
print("="*70 + "\n")
def create_directories():
"""Create necessary directories"""
print_header("Creating Directory Structure")
directories = [
'weights',
'logs',
'data/videos/normal',
'data/videos/anomalous',
]
for dir_path in directories:
path = Path(dir_path)
path.mkdir(parents=True, exist_ok=True)
print(f"✓ Created: {dir_path}")
print("\n✅ Directory structure created successfully!")
def check_dependencies():
"""Check if required packages are installed"""
print_header("Checking Dependencies")
dependencies = {
'torch': 'PyTorch',
'torchvision': 'TorchVision',
'cv2': 'OpenCV',
'numpy': 'NumPy',
'pandas': 'Pandas',
'sklearn': 'Scikit-learn',
'matplotlib': 'Matplotlib',
'seaborn': 'Seaborn',
'tqdm': 'TQDM'
}
missing = []
installed = []
for module, name in dependencies.items():
try:
__import__(module)
installed.append(name)
print(f"✓ {name} - Installed")
except ImportError:
missing.append(name)
print(f"✗ {name} - NOT INSTALLED")
if missing:
print(f"\n⚠️ Missing packages: {', '.join(missing)}")
print("\nTo install missing packages, run:")
print(" pip install -r requirements.txt")
return False
else:
print("\n✅ All dependencies installed!")
return True
def check_cuda():
"""Check CUDA availability"""
print_header("Checking CUDA/GPU Support")
try:
import torch
if torch.cuda.is_available():
print(f"✓ CUDA is available!")
print(f" Device: {torch.cuda.get_device_name(0)}")
print(f" CUDA Version: {torch.version.cuda}")
print(f" Number of GPUs: {torch.cuda.device_count()}")
return True
else:
print("⚠️ CUDA not available - will use CPU")
print(" Training will be slower on CPU")
return False
except ImportError:
print("✗ PyTorch not installed - cannot check CUDA")
return False
def test_imports():
"""Test if all modules can be imported"""
print_header("Testing Module Imports")
modules_to_test = [
('models', 'Model architectures'),
('data', 'Data processing'),
('utils', 'Utilities'),
('inference', 'Inference pipeline'),
('config', 'Configuration')
]
all_success = True
for module, description in modules_to_test:
try:
__import__(module)
print(f"✓ {module:15s} - {description}")
except Exception as e:
print(f"✗ {module:15s} - ERROR: {e}")
all_success = False
if all_success:
print("\n✅ All modules imported successfully!")
else:
print("\n⚠️ Some modules failed to import")
return all_success
def show_next_steps():
"""Display next steps"""
print_header("Next Steps")
steps = """
1. Prepare Your Data
─────────────────
Place your surveillance videos in:
• data/videos/normal/ - Normal footage
• data/videos/anomalous/ - Anomalous footage
2. Train the Autoencoder
───────────────────────
python training/train_autoencoder.py --data_dir data/videos
3. Train the CNN-LSTM
──────────────────
python training/train_cnn_lstm.py --data_dir data/videos
4. Run Inference
─────────────
python demo.py
5. Integrate with Backend (Member 4)
─────────────────────────────────
Update backend URL in config.py, then use:
from inference.integration import BackendIntegration
For more details, see:
• GUIDE.md - Complete usage guide
• README.md - Project overview
• demo.py - Working examples
"""
print(steps)
def create_sample_config():
"""Create a sample configuration file if needed"""
print_header("Configuration")
config_path = Path('config.py')
if config_path.exists():
print("✓ config.py already exists")
print("\nCurrent configuration:")
print(" Frame Size: 224x224")
print(" Sequence Length: 16 frames")
print(" Anomaly Threshold: 0.7")
print("\nEdit config.py to customize parameters")
else:
print("⚠️ config.py not found - this should not happen!")
def main():
"""Main setup function"""
print("""
╔═══════════════════════════════════════════════════════════════════╗
║ ║
║ ANOMALY DETECTION MODULE - SETUP SCRIPT ║
║ Member 3 - CU Hackathon ║
║ ║
╚═══════════════════════════════════════════════════════════════════╝
""")
# Step 1: Create directories
create_directories()
# Step 2: Check dependencies
deps_ok = check_dependencies()
if not deps_ok:
print("\n" + "="*70)
print(" ⚠️ SETUP INCOMPLETE - Install missing dependencies first")
print("="*70)
print("\nRun: pip install -r requirements.txt")
return
# Step 3: Check CUDA
has_cuda = check_cuda()
# Step 4: Test imports
imports_ok = test_imports()
# Step 5: Show configuration
create_sample_config()
# Final summary
print("\n" + "="*70)
if imports_ok and deps_ok:
print(" ✅ SETUP COMPLETE - Ready to start!")
print("="*70)
if not has_cuda:
print("\n ⚠️ Note: No GPU detected - training will use CPU")
show_next_steps()
else:
print(" ⚠️ SETUP INCOMPLETE - Please fix errors above")
print("="*70)
print("\n💡 Tip: Run 'python demo.py' to see a complete overview\n")
if __name__ == "__main__":
main()