Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fry_bisenetv2-0.1.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fry_bisenetv2-0.1.1-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file fry_bisenetv2-0.1.1.tar.gz.

File metadata

  • Download URL: fry_bisenetv2-0.1.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for fry_bisenetv2-0.1.1.tar.gz
Algorithm Hash digest
SHA256 1e72f7bde723192581536107f4c1005a58c2d78fddb285ad4414dbc87e978288
MD5 2b7f51b8ea71f5da9907c3124eb4afcf
BLAKE2b-256 bb45462c4d66a18632ade2625319d8b4203ea737a892903f7f7251728cbbe3c9

See more details on using hashes here.

File details

Details for the file fry_bisenetv2-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fry_bisenetv2-0.1.1-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.11.9

File hashes

Hashes for fry_bisenetv2-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30959aebbb73741030f2b324c4142fa6195fbaede03faba25096fcdbf55d1779
MD5 62002660385ce9b71d9125ca148ff2f0
BLAKE2b-256 cc43cf1aae6cd047fe54c3396ec1af9b949e06021ad634e8607ad0f906e0e830

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page