-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_setup.py
More file actions
168 lines (147 loc) · 6.2 KB
/
verify_setup.py
File metadata and controls
168 lines (147 loc) · 6.2 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
#!/usr/bin/env python3
"""
Setup verification script for the Pneumonia Detection ML project.
Run this to check if everything is ready before starting.
"""
import sys
import os
from pathlib import Path
def check_file(filepath, description):
"""Check if a file exists."""
if Path(filepath).exists():
size = Path(filepath).stat().st_size
size_str = f"{size/1024:.1f}KB" if size < 1024*1024 else f"{size/(1024*1024):.1f}MB"
print(f" ✓ {description}: {filepath} ({size_str})")
return True
else:
print(f" ✗ {description}: {filepath} NOT FOUND")
return False
def check_module(module_name, package_name=None):
"""Check if a Python module can be imported."""
if package_name is None:
package_name = module_name
try:
module = __import__(module_name)
version = getattr(module, '__version__', 'unknown')
print(f" ✓ {package_name}: {version}")
return True
except ImportError:
print(f" ✗ {package_name}: NOT INSTALLED")
return False
def main():
print("="*70)
print("🔍 PNEUMONIA DETECTION PROJECT - SETUP VERIFICATION")
print("="*70)
all_good = True
# Check core files
print("\n📚 Checking Core Project Files...")
files_to_check = [
('pneumonia_detection_ml.ipynb', 'Main Jupyter Notebook'),
('download_chest_xray_dataset.py', 'Dataset Download Script'),
('train_model.py', 'Training Script'),
('predict.py', 'Prediction Script'),
('requirements.txt', 'Requirements File'),
('README_PNEUMONIA_DETECTION.md', 'Main README'),
('QUICK_START_GUIDE.md', 'Quick Start Guide'),
('PROJECT_SUMMARY.md', 'Project Summary'),
]
for filepath, description in files_to_check:
if not check_file(filepath, description):
all_good = False
# Check Python packages
print("\n📦 Checking Python Packages...")
packages_to_check = [
('numpy', 'NumPy'),
('pandas', 'Pandas'),
('PIL', 'Pillow'),
('cv2', 'OpenCV'),
('matplotlib', 'Matplotlib'),
('seaborn', 'Seaborn'),
('sklearn', 'scikit-learn'),
('plotly', 'Plotly'),
('jupyter', 'Jupyter'),
]
for module_name, package_name in packages_to_check:
if not check_module(module_name, package_name):
all_good = False
# Check TensorFlow/Keras separately (special handling)
print("\n🧠 Checking Deep Learning Frameworks...")
try:
import tensorflow as tf
print(f" ✓ TensorFlow: {tf.__version__}")
try:
from tensorflow import keras
print(f" ✓ Keras: {keras.__version__}")
except:
print(f" ⚠️ Keras: Available through TensorFlow")
except ImportError:
print(f" ✗ TensorFlow: NOT INSTALLED")
print(f" Run: pip install tensorflow")
all_good = False
# Check dataset
print("\n📊 Checking Dataset...")
dataset_dir = Path('./chest_xray')
if dataset_dir.exists():
train_dir = dataset_dir / 'train'
test_dir = dataset_dir / 'test'
if train_dir.exists() and test_dir.exists():
print(f" ✓ Dataset found at: {dataset_dir}")
# Count images
normal_train = len(list((train_dir / 'NORMAL').glob('*.jpeg'))) if (train_dir / 'NORMAL').exists() else 0
pneumonia_train = len(list((train_dir / 'PNEUMONIA').glob('*.jpeg'))) if (train_dir / 'PNEUMONIA').exists() else 0
normal_test = len(list((test_dir / 'NORMAL').glob('*.jpeg'))) if (test_dir / 'NORMAL').exists() else 0
pneumonia_test = len(list((test_dir / 'PNEUMONIA').glob('*.jpeg'))) if (test_dir / 'PNEUMONIA').exists() else 0
print(f" Training images: {normal_train + pneumonia_train}")
print(f" - NORMAL: {normal_train}")
print(f" - PNEUMONIA: {pneumonia_train}")
print(f" Test images: {normal_test + pneumonia_test}")
print(f" - NORMAL: {normal_test}")
print(f" - PNEUMONIA: {pneumonia_test}")
else:
print(f" ⚠️ Dataset structure incomplete")
all_good = False
else:
print(f" ✗ Dataset not found at: {dataset_dir}")
print(f" Run: python download_chest_xray_dataset.py")
all_good = False
# Check for trained model
print("\n🤖 Checking for Trained Model...")
model_files = ['pneumonia_model.h5', 'pneumonia_model_best.h5']
model_found = False
for model_file in model_files:
if Path(model_file).exists():
size = Path(model_file).stat().st_size / (1024*1024)
print(f" ✓ Model found: {model_file} ({size:.1f}MB)")
model_found = True
else:
print(f" ○ Model not yet trained: {model_file}")
if not model_found:
print(f" To train: python train_model.py")
print(f" Or run the Jupyter notebook")
# Final summary
print("\n" + "="*70)
if all_good and model_found:
print("✅ SETUP COMPLETE - EVERYTHING READY!")
print("="*70)
print("\nYou can now:")
print(" 1. Open the notebook: jupyter notebook pneumonia_detection_ml.ipynb")
print(" 2. Make predictions: python predict.py --image xray.jpeg")
print(" 3. Review documentation: README_PNEUMONIA_DETECTION.md")
elif all_good:
print("✅ SETUP READY - NEEDS TRAINING")
print("="*70)
print("\nNext steps:")
print(" 1. Download dataset: python download_chest_xray_dataset.py")
print(" 2. Train model: python train_model.py")
print(" 3. Or open notebook: jupyter notebook pneumonia_detection_ml.ipynb")
else:
print("⚠️ SETUP INCOMPLETE")
print("="*70)
print("\nPlease fix the issues above:")
print(" 1. Install missing packages: pip install -r requirements.txt")
print(" 2. Download dataset: python download_chest_xray_dataset.py")
print(" 3. Then run this script again")
print("="*70)
return 0 if all_good else 1
if __name__ == "__main__":
sys.exit(main())