-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquick_start.py
More file actions
224 lines (182 loc) Β· 7.16 KB
/
Copy pathquick_start.py
File metadata and controls
224 lines (182 loc) Β· 7.16 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
#!/usr/bin/env python3
"""
Quick Start Script for YOLOv8 Space Station Object Detection
Provides an easy way to get started with the project
"""
import os
import sys
import subprocess
import argparse
from pathlib import Path
def print_banner():
"""Print project banner."""
print("=" * 60)
print("π YOLOv8 Space Station Object Detection")
print("=" * 60)
print("Detecting Toolbox, Oxygen Tank, and Fire Extinguisher")
print("Target: β₯90% mAP@0.5 accuracy")
print("=" * 60)
def check_environment():
"""Check if the environment is properly set up."""
print("π Checking environment...")
# Check Python version
if sys.version_info < (3, 8):
print("β Python 3.8+ required")
return False
# Check if conda environment is activated
if 'EDU' not in os.environ.get('CONDA_DEFAULT_ENV', ''):
print("β οΈ Warning: EDU conda environment not activated")
print(" Run: conda activate EDU")
# Check required files
required_files = ['config.yaml', 'train.py', 'predict.py', 'app.py']
missing_files = []
for file in required_files:
if not Path(file).exists():
missing_files.append(file)
if missing_files:
print(f"β Missing required files: {missing_files}")
return False
print("β
Environment check passed")
return True
def setup_dataset():
"""Set up dataset structure."""
print("π Setting up dataset structure...")
dataset_dirs = [
"dataset/train/images",
"dataset/train/labels",
"dataset/val/images",
"dataset/val/labels",
"dataset/test/images",
"dataset/test/labels"
]
for dir_path in dataset_dirs:
Path(dir_path).mkdir(parents=True, exist_ok=True)
print(f"β
Created: {dir_path}")
print("π Dataset structure ready!")
print(" Place your images and labels in the dataset/ directory")
print(" Images: dataset/{train,val,test}/images/")
print(" Labels: dataset/{train,val,test}/labels/")
def run_training_demo():
"""Run a quick training demo with sample data."""
print("π― Running training demo...")
# Check if dataset has data
train_images = list(Path("dataset/train/images").glob("*.jpg")) + list(Path("dataset/train/images").glob("*.png"))
if not train_images:
print("β οΈ No training images found in dataset/train/images/")
print(" Please add your dataset before training")
return False
print(f"π Found {len(train_images)} training images")
# Run training with nano model for quick demo
cmd = [
sys.executable, "train.py",
"--config", "config.yaml",
"--model-size", "n"
]
print("π Starting training...")
print(f" Command: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, check=True)
print("β
Training completed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Training failed: {e}")
return False
def run_evaluation_demo():
"""Run evaluation on trained model."""
print("π Running evaluation demo...")
model_path = "runs/train/yolov8_training/weights/best.pt"
if not Path(model_path).exists():
print(f"β Trained model not found: {model_path}")
print(" Please run training first")
return False
cmd = [
sys.executable, "predict.py",
"--model", model_path,
"--config", "config.yaml"
]
print("π Starting evaluation...")
print(f" Command: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, check=True)
print("β
Evaluation completed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"β Evaluation failed: {e}")
return False
def launch_web_app():
"""Launch the Streamlit web application."""
print("π Launching web application...")
cmd = ["streamlit", "run", "app.py"]
print("π Starting Streamlit app...")
print(f" Command: {' '.join(cmd)}")
print(" The app will open in your browser")
try:
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"β Failed to launch web app: {e}")
return False
except KeyboardInterrupt:
print("\nπ Web app stopped")
return True
def show_next_steps():
"""Show next steps for the user."""
print("\n" + "=" * 60)
print("π― Next Steps")
print("=" * 60)
print("1. π Prepare your dataset:")
print(" - Add images to dataset/{train,val,test}/images/")
print(" - Add YOLO labels to dataset/{train,val,test}/labels/")
print(" - Run: python data_utils.py --action analyze --dataset-dir dataset")
print()
print("2. π― Train your model:")
print(" - Quick: python train.py --config config.yaml --model-size n")
print(" - Better: python train.py --config config.yaml --model-size m")
print(" - Best: python train.py --config config.yaml --model-size l")
print()
print("3. π Evaluate your model:")
print(" - python predict.py --model runs/train/yolov8_training/weights/best.pt")
print()
print("4. π Use the web app:")
print(" - streamlit run app.py")
print()
print("5. π§ Optimize for β₯90% mAP@0.5:")
print(" - Use larger models (YOLOv8s, YOLOv8m, YOLOv8l)")
print(" - Increase training epochs")
print(" - Add more diverse data")
print(" - Check optimization_recommendations.txt")
print()
print("π For detailed instructions, see README.md")
def main():
"""Main quick start function."""
parser = argparse.ArgumentParser(description='Quick Start for YOLOv8 Space Station Object Detection')
parser.add_argument('--action', type=str, choices=['setup', 'train', 'eval', 'web', 'all'],
default='setup', help='Action to perform')
parser.add_argument('--skip-checks', action='store_true', help='Skip environment checks')
args = parser.parse_args()
print_banner()
# Check environment
if not args.skip_checks and not check_environment():
print("β Environment check failed. Please fix the issues above.")
return False
if args.action == 'setup':
setup_dataset()
show_next_steps()
elif args.action == 'train':
setup_dataset()
if run_training_demo():
show_next_steps()
elif args.action == 'eval':
if run_evaluation_demo():
show_next_steps()
elif args.action == 'web':
launch_web_app()
elif args.action == 'all':
setup_dataset()
if run_training_demo():
if run_evaluation_demo():
launch_web_app()
print("\nπ Quick start completed!")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)