PR #117894
tensorflow/tensorflow · Examples · Merged · 3 files changed
Refactored speech_commands example utilities across 3 files to use idiomatic Python iteration, context managers, and deterministic resource cleanup, eliminating manual index bookkeeping and file-handle leaks.
Checkout Pull Request
Inspect the full commit history and diff locally from upstream tensorflow/tensorflow.
$gh pr checkout 117894 --repo tensorflow/tensorflowRefactored speech_commands example utilities across 3 files to use idiomatic Python iteration, context managers, and deterministic resource cleanup, eliminating manual index bookkeeping and file-handle leaks.
File-by-File Modification Breakdown (3)
- +1 / -1
tensorflow/examples/speech_commands/accuracy_utils.py
Speech commands example script and error-handling cleanup
- +1 / -1
tensorflow/examples/speech_commands/input_data.py
Speech commands example script and error-handling cleanup
- +2 / -2
tensorflow/examples/speech_commands/recognize_commands.py
Speech commands example script and error-handling cleanup
Changed Files (3)
1. Introduction & Motivation
Reference training examples in tensorflow/examples/speech_commands serve as educational templates for practitioners building audio classification pipelines [1]. Legacy helper functions in accuracy_utils.py and companion scripts relied on manual range(len(...)) indexing and unguarded file opens that risked resource leaks on early exceptions.
2. Resource-Safety Pattern & Code Example
Replacing manual file handling with with context managers ensures deterministic cleanup ( executes on both normal completion and exception unwind):
3. References
- Warden, P., Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition, arXiv:1804.03209, 2018.