es-ude / es-ude/OnDeviceTraining
examples/kws: replace module-level assert KWS_CLASSES validation with explicit raise
- Dominant language
- C
- Stars
- 1
- Forks
- 3
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 8
Description
## Nit
The KWS examples validate the `KWS_CLASSES` env knob with a module-level `assert`:
```python
NUM_CLASSES = int(os.environ.get("KWS_CLASSES", "6"))
assert NUM_CLASSES in (6, 35), NUM_CLASSES
```
`assert` is stripped under `python -O` / `PYTHONOPTIMIZE`, so the validation silently vanishes in optimized runs (an invalid `KWS_CLASSES` would then fail later with a confusing error).
## Fix
Replace with an explicit guard that always runs:
```python
if NUM_CLASSES not in (6, 35):
raise ValueError(f"KWS_CLASSES must be 6 or 35, got {NUM_CLASSES}")
```
## Affected files
- `examples/kws_mfcc/{prepare_data,train_pytorch,compare}.py`
- `examples/kws_raw/{prepare_data,train_pytorch,compare}.py`
(The C trainers already use an explicit `if … fprintf … return default` in `readNumClasses()`, so only the Python side needs this.)
Low priority — CI does not pass `-O`, so this is robustness/hygiene, not a live bug. Surfaced in the PR #256 final review.
Contributor guide
Research direction
Inspect the six listed Python files under examples/kws_mfcc/ and examples/kws_raw/, starting at the KWS_CLASSES and NUM_CLASSES definitions. Replace each module-level assertion with the specified explicit validation, then run the affected KWS examples or their available checks and confirm invalid values produce the stated ValueError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100