-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·309 lines (269 loc) · 8.23 KB
/
setup.sh
File metadata and controls
executable file
·309 lines (269 loc) · 8.23 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#!/bin/bash
# Angle Grinder Detection - Robust Setup Script
# Uses staged installation to avoid dependency resolution issues
set -e # Exit on error
echo "=========================================="
echo "BikeAI v5 - Angle Grinder Detection Setup"
echo "Staged Installation Method"
echo "=========================================="
echo ""
# Get project root
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_ROOT"
echo "Project root: $PROJECT_ROOT"
echo ""
# ============================================================================
# 1. CREATE DIRECTORY STRUCTURE (safe - won't overwrite existing)
# ============================================================================
echo "Step 1/7: Creating directory structure..."
mkdir -p data/raw/{grinder,background,tools}
mkdir -p data/processed/universal
mkdir -p data/features/{classical,neural}
mkdir -p models/{classical,neural,quantized}
mkdir -p config
mkdir -p results/{figures,tables}
mkdir -p notebooks
mkdir -p logs
mkdir -p .dvc
echo "✓ Directory structure ready"
echo ""
# ============================================================================
# 2. VIRTUAL ENVIRONMENT
# ============================================================================
echo "Step 2/7: Setting up virtual environment..."
if [ ! -d "venv" ]; then
python3 -m venv venv
echo "✓ Virtual environment created"
else
echo "✓ Virtual environment exists"
fi
source venv/bin/activate
echo "✓ Virtual environment activated"
echo ""
# ============================================================================
# 3. UPGRADE CORE TOOLS
# ============================================================================
echo "Step 3/7: Upgrading pip, setuptools, wheel..."
pip install --upgrade pip setuptools wheel
echo "✓ Core tools upgraded"
echo ""
# ============================================================================
# 4. STAGED PACKAGE INSTALLATION (avoids resolution-too-deep)
# ============================================================================
echo "Step 4/7: Installing packages in stages..."
echo "This approach installs compatible package groups sequentially"
echo "to avoid overwhelming pip's dependency resolver."
echo ""
# STAGE 1: Core scientific computing
echo " [Stage 1/5] Core scientific stack..."
pip install \
"numpy>=1.24.0,<2.0.0" \
"scipy>=1.10.0,<1.14.0" \
"pandas>=2.0.0,<2.3.0" \
"scikit-learn>=1.3.0,<1.6.0"
echo " ✓ Scientific computing installed"
echo ""
# STAGE 2: Audio processing
echo " [Stage 2/5] Audio processing libraries..."
pip install \
"librosa>=0.10.0,<0.11.0" \
"soundfile>=0.12.0" \
"audioread>=3.0.0" \
"resampy>=0.4.0"
echo " ✓ Audio libraries installed"
echo ""
# STAGE 3: Machine learning frameworks
echo " [Stage 3/5] ML frameworks (TensorFlow, XGBoost)..."
pip install \
"tensorflow>=2.15.0,<2.18.0" \
"tensorflow-hub>=0.15.0" \
"xgboost>=2.0.0,<2.2.0"
echo " ✓ ML frameworks installed"
echo ""
# STAGE 4: MLOps tools
echo " [Stage 4/5] MLOps (DVC, MLflow)..."
pip install \
"dvc>=3.0.0" \
"mlflow>=2.9.0,<2.20.0"
echo " ✓ MLOps tools installed"
echo ""
# STAGE 5: Additional dependencies
echo " [Stage 5/5] Supporting packages..."
pip install \
"imbalanced-learn>=0.11.0" \
"spafe>=0.3.2" \
"shap>=0.44.0" \
"matplotlib>=3.7.0,<3.10.0" \
"seaborn>=0.12.0,<0.14.0" \
"pyyaml>=6.0" \
"joblib>=1.3.0" \
"tqdm>=4.65.0"
echo " ✓ Supporting packages installed"
echo ""
# STAGE 6: Jupyter environment
echo " [Stage 6/6] Jupyter notebook environment..."
pip install \
"jupyter>=1.0.0" \
"ipykernel>=6.25.0" \
"ipywidgets>=8.0.0"
echo " ✓ Jupyter environment installed"
echo ""
echo "✓ All packages installed successfully!"
echo ""
# ============================================================================
# 5. INITIALIZE DVC
# ============================================================================
echo "Step 5/7: Initializing DVC..."
if [ ! -f ".dvc/config" ]; then
dvc init
echo "✓ DVC initialized"
# Configure local remote storage
DVC_REMOTE="../BikeAI_dvc_storage"
mkdir -p "$DVC_REMOTE"
dvc remote add -d local_storage "$DVC_REMOTE"
echo "✓ DVC remote configured: $DVC_REMOTE"
else
echo "✓ DVC already initialized"
fi
echo ""
# ============================================================================
# 6. SETUP MLFLOW
# ============================================================================
echo "Step 6/7: Setting up MLflow..."
mkdir -p logs/mlruns
# Create MLflow configuration note
cat > logs/MLFLOW_INFO.txt << 'EOF'
MLflow Tracking Setup
=====================
To view your experiments:
1. Open terminal in BikeAIv5 directory
2. Activate environment: source venv/bin/activate
3. Run: mlflow ui --backend-store-uri logs/mlruns
4. Open browser: http://localhost:5000
The experiment 'angle_grinder_pipeline' will be created
automatically when you run Notebook 00.
EOF
echo "✓ MLflow directories created"
echo " View experiments: mlflow ui --backend-store-uri logs/mlruns"
echo ""
# ============================================================================
# 7. VERIFY INSTALLATION
# ============================================================================
echo "Step 7/7: Verifying installation..."
echo ""
python3 << 'VERIFY_PYTHON'
import sys
print(f"Python version: {sys.version.split()[0]}")
# Check key packages
packages = [
"numpy", "scipy", "pandas", "sklearn",
"librosa", "tensorflow", "xgboost",
"dvc", "mlflow", "imblearn", "spafe", "shap",
"matplotlib", "seaborn", "yaml", "joblib"
]
print("\nInstalled packages:")
for pkg in packages:
try:
if pkg == "sklearn":
import sklearn
version = sklearn.__version__
elif pkg == "yaml":
import yaml
version = yaml.__version__
else:
mod = __import__(pkg)
version = getattr(mod, "__version__", "✓")
print(f" ✓ {pkg:20s} {version}")
except ImportError:
print(f" ✗ {pkg:20s} MISSING")
sys.exit(1)
print("\n✓ All packages verified!")
VERIFY_PYTHON
echo ""
# ============================================================================
# 8. CREATE/UPDATE .gitignore
# ============================================================================
cat > .gitignore << 'EOF'
# Python
venv/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg-info/
dist/
build/
# Data (managed by DVC)
data/raw/*
data/processed/*
data/features/*
!data/.gitkeep
!data/*/.gitkeep
# Models (managed by DVC)
models/*.pkl
models/*.h5
models/*.tflite
models/*.keras
!models/.gitkeep
# Logs
logs/mlruns/
*.log
# Jupyter
.ipynb_checkpoints/
*.ipynb_checkpoints
# MLflow
mlruns/
# DVC
.dvc/cache
.dvc/tmp
# OS
.DS_Store
Thumbs.db
# IDE
.vscode/
.idea/
*.swp
*.swo
EOF
echo "✓ .gitignore updated"
echo ""
# ============================================================================
# SETUP COMPLETE
# ============================================================================
echo "=========================================="
echo "SETUP COMPLETE!"
echo "=========================================="
echo ""
echo "Environment Info:"
echo " Python: $(python3 --version)"
echo " Pip: $(pip --version | cut -d' ' -f2)"
echo " Virtual env: $PROJECT_ROOT/venv"
echo ""
echo "Next Steps:"
echo ""
echo "1. Add your audio files:"
echo " - Angle grinder recordings → data/raw/grinder/"
echo " - Background/ambient sounds → data/raw/background/"
echo " - Other power tools → data/raw/tools/"
echo ""
echo "2. Launch Jupyter Notebook:"
echo " jupyter notebook notebooks/00_dvc_mlflow_setup.ipynb"
echo ""
echo "3. Run through the notebooks in order:"
echo " 00_dvc_mlflow_setup.ipynb (Setup & verification)"
echo " 01_data_exploration.ipynb (Explore your data)"
echo " 02_universal_preprocessing... (Process audio)"
echo " ... and so on"
echo ""
echo "4. View MLflow experiments anytime:"
echo " mlflow ui --backend-store-uri logs/mlruns"
echo " Then visit: http://localhost:5000"
echo ""
echo "Important: Always activate the environment first:"
echo " source venv/bin/activate"
echo ""
echo "=========================================="
echo "Ready to detect angle grinders! 🔧🚴"
echo "=========================================="