File size: 2,644 Bytes
5b86813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
## Changes: Remove tqdm, Add Custom Pip-Style Progress Bar

### Summary
Removed dependency on `tqdm` library and implemented a custom pip-style training progress bar using only standard Python libraries (`sys`, `time`, `threading`).

### Files Modified
- [train_road_anomaly_model.py](train_road_anomaly_model.py#L1-L30)

### Changes Made

#### 1. Removed Imports (Line 1-30)
**Before:**
```python
from rich.progress import (...)
from tqdm import tqdm
```

**After:**
```python
import threading
import time
```

#### 2. Custom Progress Bar Implementation (Line 386-462)
Replaced tqdm-based progress rendering with custom `_render_progress()` function that:

- **Displays real-time progress** with visual bar:
  ```
  training: 45.0%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘| 45/100 [00:30<00:40, 1.37 epoch/s] loss=0.3421 24.50img/s
  ```

- **Components**:
  - Percentage: `45.0%`
  - Visual progress bar: `β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘` (30 char width)
  - Completed/Total: `45/100`
  - Time: `[elapsed<remaining, rate]`
  - Training stats: `loss` and `speed` (img/s)

- **Features**:
  - ETA calculation based on per-epoch timing
  - 500ms update interval (smooth without excessive output)
  - Time formatting: `MM:SS` or `HH:MM:SS`
  - Final progress line includes newline for clean finish

### Benefits
βœ… **Zero external dependencies** - no tqdm, rich, or other progress bar libraries  
βœ… **Lightweight** - uses only standard library  
βœ… **Pip-style format** - familiar to Python developers  
βœ… **Real-time stats** - displays loss and speed alongside progress  
βœ… **ETA calculation** - estimates remaining time  
βœ… **Threading-safe** - background thread updates don't block training  

### Example Output
```
training:  0.0%|β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘| 0/100 [00:00<00:40, 0.00 epoch/s] loss=0.5000 24.50img/s
training: 10.0%|β–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘| 10/100 [00:10<00:35, 1.00 epoch/s] loss=0.4700 24.50img/s
training: 20.0%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘| 20/100 [00:20<00:30, 1.00 epoch/s] loss=0.4400 24.50img/s
...
training:100.0%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 100/100 [00:50<00:00, 2.00 epoch/s] loss=0.2000 24.50img/s
```

### Usage
No changes needed - progress bar appears automatically during training via background thread.

### Testing
Demo script created: `demo_progress_bar.py` demonstrates the progress bar output format.