-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
199 lines (150 loc) · 5.69 KB
/
install.py
File metadata and controls
199 lines (150 loc) · 5.69 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
#!/usr/bin/env python3
"""
Installation script for the Image Classifier project
Automatically sets up the environment and installs dependencies
"""
import os
import sys
import subprocess
import platform
import logging
from pathlib import Path
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
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):
logger.error(f"Python {version.major}.{version.minor} is not supported. Please use Python 3.8 or higher.")
return False
logger.info(f"Python {version.major}.{version.minor}.{version.micro} is compatible")
return True
def check_pip():
"""Check if pip is available"""
try:
subprocess.run([sys.executable, "-m", "pip", "--version"],
check=True, capture_output=True)
logger.info("pip is available")
return True
except subprocess.CalledProcessError:
logger.error("pip is not available")
return False
def create_virtual_environment():
"""Create a virtual environment"""
venv_name = "venv"
if os.path.exists(venv_name):
logger.info(f"Virtual environment '{venv_name}' already exists")
return True
try:
logger.info("Creating virtual environment...")
subprocess.run([sys.executable, "-m", "venv", venv_name], check=True)
logger.info(f"Virtual environment '{venv_name}' created successfully")
return True
except subprocess.CalledProcessError as e:
logger.error(f"Failed to create virtual environment: {e}")
return False
def get_activate_command():
"""Get the appropriate activate command for the OS"""
system = platform.system().lower()
if system == "windows":
return "venv\\Scripts\\activate"
else:
return "source venv/bin/activate"
def install_dependencies():
"""Install project dependencies"""
try:
logger.info("Installing dependencies...")
# Upgrade pip first
subprocess.run([sys.executable, "-m", "pip", "install", "--upgrade", "pip"],
check=True, capture_output=True)
# Install requirements
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
check=True, capture_output=True)
logger.info("Dependencies installed successfully!")
return True
except subprocess.CalledProcessError as e:
logger.error(f"Failed to install dependencies: {e}")
return False
def create_directories():
"""Create necessary project directories"""
directories = ["data", "models", "logs", "test_images"]
for directory in directories:
os.makedirs(directory, exist_ok=True)
logger.info(f"Created directory: {directory}")
def run_tests():
"""Run basic tests to verify installation"""
try:
logger.info("Running basic tests...")
# Test imports
test_imports = [
"import tensorflow as tf",
"import numpy as np",
"import cv2",
"import matplotlib.pyplot as plt",
"from src.image_classifier import ImageClassifier",
"from src.utils import create_sample_dataset"
]
for import_statement in test_imports:
try:
exec(import_statement)
logger.info(f"✓ {import_statement}")
except ImportError as e:
logger.error(f"✗ {import_statement} - {e}")
return False
logger.info("All imports successful!")
return True
except Exception as e:
logger.error(f"Test failed: {e}")
return False
def print_next_steps():
"""Print next steps for the user"""
activate_cmd = get_activate_command()
next_steps = f"""
╔══════════════════════════════════════════════════════════════╗
║ Installation Complete! ║
╚══════════════════════════════════════════════════════════════╝
Next Steps:
1. Activate the virtual environment:
{activate_cmd}
2. Run the demo to test the installation:
python demo.py
3. Or start training with sample data:
python scripts/run_training.py --create-sample
4. Explore the project:
- README.md - Complete documentation
- examples/ - Example scripts
- src/ - Source code
- tests/ - Unit tests
5. For help with commands:
make help
Happy coding! 🚀
"""
print(next_steps)
def main():
"""Main installation function"""
logger.info("Starting Image Classifier project installation...")
# Check Python version
if not check_python_version():
return False
# Check pip
if not check_pip():
return False
# Create virtual environment
if not create_virtual_environment():
return False
# Install dependencies
if not install_dependencies():
return False
# Create directories
create_directories()
# Run tests
if not run_tests():
logger.warning("Some tests failed, but installation may still work")
# Print next steps
print_next_steps()
logger.info("Installation completed!")
return True
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)