-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
200 lines (165 loc) Β· 6.19 KB
/
Copy pathsetup.py
File metadata and controls
200 lines (165 loc) Β· 6.19 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
#!/usr/bin/env python3
"""
Setup script for YOLOv8 Space Station Object Detection
Installs dependencies and prepares environment
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
def run_command(command, description):
"""Run a command and handle errors."""
print(f"π {description}...")
try:
result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
print(f"β
{description} completed successfully")
return True
except subprocess.CalledProcessError as e:
print(f"β {description} failed: {e}")
print(f"Error output: {e.stderr}")
return False
def check_python_version():
"""Check if Python version is compatible."""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print(f"β Python {version.major}.{version.minor} is not supported. Please use Python 3.8+")
return False
print(f"β
Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def create_conda_environment():
"""Create and activate conda environment."""
print("π Setting up YOLOv8 Space Station Object Detection Environment")
# Check if conda is available
if not run_command("conda --version", "Checking conda availability"):
print("β Conda not found. Please install Anaconda or Miniconda first.")
return False
# Create environment
if not run_command("conda env create -f environment.yml", "Creating conda environment"):
print("β Failed to create conda environment")
return False
print("β
Conda environment 'EDU' created successfully")
return True
def install_additional_dependencies():
"""Install additional dependencies not in environment.yml."""
additional_packages = [
"tensorboard",
"wandb",
"albumentations"
]
for package in additional_packages:
if not run_command(f"pip install {package}", f"Installing {package}"):
print(f"β οΈ Warning: Failed to install {package}")
return True
def create_project_structure():
"""Create necessary project directories."""
directories = [
"dataset/train/images",
"dataset/train/labels",
"dataset/val/images",
"dataset/val/labels",
"dataset/test/images",
"dataset/test/labels",
"runs/train",
"runs/val",
"logs",
"models",
"results"
]
for directory in directories:
Path(directory).mkdir(parents=True, exist_ok=True)
print(f"β
Created directory: {directory}")
return True
def download_yolov8_models():
"""Download pre-trained YOLOv8 models."""
models = ["yolov8n.pt", "yolov8s.pt", "yolov8m.pt"]
for model in models:
model_path = Path(f"models/{model}")
if not model_path.exists():
print(f"π₯ Downloading {model}...")
# This will be handled by ultralytics when needed
print(f"β
{model} will be downloaded automatically when training starts")
else:
print(f"β
{model} already exists")
return True
def create_sample_data_yaml():
"""Create a sample data.yaml file."""
data_yaml_content = """# YOLOv8 Dataset Configuration
# Space Station Object Detection Dataset
path: ./dataset # Dataset root directory
train: train/images # Train images (relative to 'path')
val: val/images # Val images (relative to 'path')
test: test/images # Test images (relative to 'path')
# Classes
names:
0: Toolbox
1: Oxygen Tank
2: Fire Extinguisher
"""
with open("data.yaml", "w") as f:
f.write(data_yaml_content)
print("β
Created data.yaml configuration file")
return True
def test_installation():
"""Test if the installation is working correctly."""
print("π§ͺ Testing installation...")
test_script = """
import sys
import torch
import ultralytics
import cv2
import numpy as np
import matplotlib.pyplot as plt
import yaml
print("β
All required packages imported successfully")
print(f"PyTorch version: {torch.__version__}")
print(f"Ultralytics version: {ultralytics.__version__}")
print(f"OpenCV version: {cv2.__version__}")
"""
try:
result = subprocess.run([sys.executable, "-c", test_script],
capture_output=True, text=True, check=True)
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"β Installation test failed: {e.stderr}")
return False
def main():
"""Main setup function."""
print("=" * 60)
print("π YOLOv8 Space Station Object Detection Setup")
print("=" * 60)
# Check Python version
if not check_python_version():
return False
# Create conda environment
if not create_conda_environment():
return False
# Install additional dependencies
install_additional_dependencies()
# Create project structure
create_project_structure()
# Download models
download_yolov8_models()
# Create sample data.yaml
create_sample_data_yaml()
# Test installation
if test_installation():
print("\n" + "=" * 60)
print("π Setup completed successfully!")
print("=" * 60)
print("\nNext steps:")
print("1. Activate the environment: conda activate EDU")
print("2. Prepare your dataset in the dataset/ directory")
print("3. Update config.yaml with your settings")
print("4. Run training: python train.py")
print("5. Run evaluation: python predict.py --model runs/train/yolov8_training/weights/best.pt")
print("6. Launch web app: streamlit run app.py")
print("\nFor more information, see README.md")
else:
print("\nβ Setup failed. Please check the error messages above.")
return False
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)