BiSeNetV2 semantic segmentation inference utilities.
Project description
fry-bisenetv2
fry-bisenetv2 是一个 BiSeNetV2 语义分割推理包。安装后可以在 Python 中调用 FryBisenetV2Predictor,也可以用命令行 fry-bisenetv2 对单张图片或图片目录做推理。
模型权重 .pth 不会随 pip 包发布,需要使用者自己提供训练好的权重文件。
安装
本地开发安装:
pip install -e .[dev]
普通安装:
pip install fry-bisenetv2
如果还没有发布到 PyPI,可以先从当前项目目录安装:
pip install .
快速使用
from fry_bisenetv2 import FryBisenetV2Predictor
predictor = FryBisenetV2Predictor(
pth_path="path/to/segmentation_bisenetv2.pth",
real_seg_class_dict={
1: "dinosaur",
2: "obstacle",
3: "bird",
},
imgSize_train_dict={"width": 1024, "height": 1024},
confidence=0.5,
input_channels=3,
)
result = predictor.predict_single_image(
img_path="path/to/input.jpg",
save_visualization=True,
save_json=True,
answer_json_dir="outputs",
input_channels=3,
)
print(result)
旧导入方式仍然兼容:
from bisenetv2_predict import FryBisenetV2Predictor
命令行使用
先准备类别文件,例如 examples/classes.json:
{
"1": "dinosaur",
"2": "obstacle",
"3": "bird"
}
单张图片推理:
fry-bisenetv2 ^
--weights path/to/segmentation_bisenetv2.pth ^
--input path/to/input.jpg ^
--classes examples/classes.json ^
--img-width 1024 ^
--img-height 1024 ^
--output-dir outputs
图片目录批量推理:
fry-bisenetv2 ^
--weights path/to/segmentation_bisenetv2.pth ^
--input path/to/images ^
--classes examples/classes.json ^
--img-width 1024 ^
--img-height 1024 ^
--output-dir outputs
输出结果
predict_single_image() 返回类似下面的字典:
{
"num": 1,
"cls": [1],
"names": ["dinosaur"],
"conf": 0.93,
"shapes": [
{
"class_num": 1,
"label": "dinosaur",
"probability": 0.93,
"points": [[10, 20], [11, 20], [12, 21]]
}
]
}
其中 points 是映射回原图坐标系的轮廓点。
示例
核心说明
类的关键参数、推理流程、输出结构和注意事项见:
测试
pytest
当前测试覆盖:
- 公共导入入口;
- CLI 类别解析和图片路径收集;
- letterbox resize/补边逻辑;
- 分割结果轮廓生成;
- 可视化绘制。
打包
构建 wheel 和 sdist:
python -m build
构建结果会出现在 dist/ 目录。
发布到 PyPI 前建议检查:
python -m twine check dist/*
发布到 TestPyPI:
python -m twine upload --repository testpypi dist/*
发布到正式 PyPI:
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fry_bisenetv2-0.1.0.tar.gz.
File metadata
- Download URL: fry_bisenetv2-0.1.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f9177b4259953e06bcea4853fd48e46f47a8a5061cd092a3e7cf3f9333188e2
|
|
| MD5 |
af7c9cd01635bde2ecc613ba26761874
|
|
| BLAKE2b-256 |
248ef5b952cb54229edac9f9f478b7bd74968e61951b057d784243189fd5f25e
|
File details
Details for the file fry_bisenetv2-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fry_bisenetv2-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
393c5bd4ecd17f94369d095699eb0d22864a70ff3792d78a3ea5a525588e6549
|
|
| MD5 |
c06ea140ff982e1410e4a1ba2e39ff1e
|
|
| BLAKE2b-256 |
fe2c46134e09867e230b160cba001dffaeaeaff8ae4a31e20e83db84240e827d
|