|
Download predict_guide.md from leeduckgo/dim-sum-semi-round: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/datasets/leeduckgo/dim-sum-semi-round/resolve/main/predict_guide.md
- Command line
-
hf download hf://datasets/leeduckgo/dim-sum-semi-round/predict_guide.md
-
curl -L -o predict_guide.md https://huggingface.co/datasets/leeduckgo/dim-sum-semi-round/resolve/main/predict_guide.md
2.04 kB
| # 推理脚本使用说明 | |
| > **使用限制:本脚本只能在“生产过程”中使用。** | |
| ## 启动 | |
| 脚本不需要传入参数: | |
| ```bash | |
| python predict.py | |
| ``` | |
| ## 使用 FlyData 读写数据 | |
| > `flydata` 库仅在比赛运行环境中可用。本地运行时需自行提供兼容实现或调整数据读写方式。 | |
| 脚本通过 `FlyData` 加载数据资源: | |
| ```python | |
| handler = FlyData() | |
| handler.load_file(INPUT_DATA_ID) | |
| data_path = Path(handler.path_root(INPUT_DATA_ID)) / DATA_FILE_NAME | |
| ``` | |
| 输入文件和音频目录位于: | |
| ```text | |
| data_path/input.jsonl | |
| data_path/audio/ | |
| ``` | |
| 脚本从 `input.jsonl` 读取 `audio_path`,将其解析为 `audio` 目录中的实际音频路径。预测结果写入: | |
| ```python | |
| Path(handler.output_path()) / "output.jsonl" | |
| ``` | |
| ## `audio_path` 的作用 | |
| `audio_path` 同时有两个作用: | |
| 1. **样本标识**:用于标识每条预测对应的输入样本。写入 `output.jsonl` 时,每条记录的 `audio_path` 必须与 `input.jsonl` 中对应记录的值一致;输出记录的顺序可以与输入不同。 | |
| 2. **音频读取路径**:用于定位需要送入模型的实际音频文件。 | |
| FlyData 数据目录为: | |
| ```python | |
| data_path = Path(handler.path_root(INPUT_DATA_ID)) / DATA_FILE_NAME | |
| audio_dir = data_path / "audio" | |
| ``` | |
| 对于相对路径,脚本会结合 `audio_dir` 得到实际路径。输入中常见的路径格式为: | |
| ```text | |
| ./audio/4377.wav | |
| ``` | |
| 由于 `audio_dir` 已经指向 `data_path/audio`,解析时会去掉相对路径中重复的首级 `audio/`,最终实际路径为: | |
| ```text | |
| data_path/audio/4377.wav | |
| ``` | |
| 如果 `audio_path` 是绝对路径,则直接使用该路径,不再拼接 `audio_dir`。 | |
| ## 替换为自己的模型 | |
| 在 `predict.py` 中替换以下两个函数: | |
| - `load_model(records)`:加载并返回自己的模型。 | |
| - `transcribe(model, audio_path)`:读取音频、调用模型推理,并返回预测文本。 | |
| 其他 FlyData 路径解析、输入读取和结果写入逻辑可以保持不变。 | |