ONNX 模型库
返回模型

说明文档

Mussel-RGB:用于RGB无人机图像的贻贝分割模型

模型类型: ONNX语义分割
应用: 高分辨率RGB航空影像中的贻贝检测
输入: 3波段RGB影像(红、绿、蓝)
输出: 二值分割掩膜(贻贝 vs 非贻贝)

模型描述

Mussel-RGB模型是一个专门为检测RGB无人机影像中的贻贝而训练的深度学习语义分割模型。该模型可实现精确的贻贝床测绘和监测,适用于海洋栖息地评估、水产养殖应用和潮间带生态研究。

主要特点:

  • 专为RGB影像中的贻贝检测而设计
  • 针对无人机标准RGB影像进行了优化
  • 使用ImageNet预训练归一化统计参数
  • 高效的ONNX格式,支持跨平台部署
  • 专为潮间带和潮下带贻贝监测而设计

模型详情

  • 版本: 20250711
  • 输入通道: 3(RGB)
  • 输入尺寸: 动态分块(推荐:2048x2048分块)
  • 归一化: 标准ImageNet统计参数
  • 输出: 二值分割(0:背景,1:贻贝)
  • 格式: ONNX

归一化参数

模型期望输入图像使用ImageNet统计参数进行归一化:

{
  \"mean\": [0.485, 0.456, 0.406],
  \"std\": [0.229, 0.224, 0.225],
  \"max_pixel_value\": 255.0
}

使用方法

1. 使用kelp-o-matic命令行工具(推荐)

命令行使用方法:

# 安装kelp-o-matic
pip install git+https://github.com/HakaiInstitute/kelp-o-matic@dev

# 列出可用模型
kom list-models

# 对贻贝RGB无人机影像运行分割
kom segment \
    --model mussel-rgb \
    --input /path/to/mussel_rgb_image.tif \
    --output /path/to/mussel_segmentation.tif \
    --batch-size 8 \
    --crop-size 2048 \
    --blur-kernel 5 \
    --morph-kernel 3

# 使用特定模型版本
kom segment \
    --model mussel-rgb \
    --version 20250711 \
    --input image.tif \
    --output result.tif

# 用于高分辨率贻贝调查
kom segment \
    --model mussel-rgb \
    --input high_res_mussel_survey.tif \
    --output result.tif \
    --batch-size 4 \
    --crop-size 1024

2. 使用kelp-o-matic Python API

使用此模型最简单的方法是通过kelp-o-matic包:

from kelp_o_matic import model_registry

# 加载模型(如果需要会自动下载)
model = model_registry[\"mussel-rgb\"]

# 使用自动分块处理大型贻贝调查图像
model.process(
    input_path=\"path/to/your/mussel_rgb_image.tif\",
    output_path=\"path/to/output/mussel_segmentation.tif\",
    batch_size=8,  # RGB可使用更高的批大小
    crop_size=2048,
    blur_kernel_size=5,  # 后处理中值模糊
    morph_kernel_size=3,  # 形态学操作
)

# 如需更多控制,可直接使用predict方法
import rasterio
import numpy as np

with rasterio.open(\"mussel_survey_image.tif\") as src:
    # 读取2048x2048分块(3个波段:RGB)
    tile = src.read(window=((0, 2048), (0, 2048)))  # 形状:(3, 2048, 2048)
    tile = np.transpose(tile, (1, 2, 0))  # 转换为HWC格式
    
    # 添加批次维度并预测
    batch = np.expand_dims(tile, axis=0)  # 形状:(1, 2048, 2048, 3)
    batch = np.transpose(batch, (0, 3, 1, 2))  # 转换为BCHW格式
    
    # 运行推理(自动处理预处理)
    predictions = model.predict(batch)
    
    # 后处理以获得最终分割结果
    segmentation = model.postprocess(predictions)
    # 结果:0=背景,1=贻贝

3. 直接使用ONNX运行时

import numpy as np
import onnxruntime as ort
from huggingface_hub import hf_hub_download
from PIL import Image

# 下载模型
model_path = hf_hub_download(repo_id=\"HakaiInstitute/mussel-rgb\", filename=\"model.onnx\")

# 加载模型
session = ort.InferenceSession(model_path)

# ImageNet归一化参数
mean = np.array([0.485, 0.456, 0.406])
std = np.array([0.229, 0.224, 0.225])

# 预处理RGB图像
def preprocess(image):
    \"\"\"
    预处理RGB图像用于模型输入
    image: 形状为[height, width, 3]的numpy数组,像素值范围0-255
    \"\"\"
    # 归一化到0-1
    image = image.astype(np.float32) / 255.0
    
    # 应用ImageNet归一化
    image = (image - mean) / std
    
    # 重塑为模型输入格式[batch, channels, height, width]
    image = np.transpose(image, (2, 0, 1))  # HWC转CHW
    image = np.expand_dims(image, axis=0)  # 添加批次维度
    
    return image

# 加载并预处理图像
image = np.array(Image.open(\"mussel_bed_drone_image.jpg\"))
preprocessed = preprocess(image)

# 运行推理
input_name = session.get_inputs()[0].name
output = session.run(None, {input_name: preprocessed})

# 后处理以获得二值掩膜
logits = output[0]
prediction = np.argmax(logits, axis=1).squeeze(0).astype(np.uint8)
# 结果:0=背景,1=贻贝

4. 使用HuggingFace Hub集成

from huggingface_hub import hf_hub_download
import onnxruntime as ort

# 下载并加载模型
model_path = hf_hub_download(
    repo_id=\"HakaiInstitute/mussel-rgb\",
    filename=\"model.onnx\",
    cache_dir=\"./models\"
)

session = ort.InferenceSession(model_path)
# ... 继续进行预处理和推理,如上所述

安装

使用kelp-o-matic:

# 通过pip安装
pip install git+https://github.com/HakaiInstitute/kelp-o-matic@dev

直接使用ONNX:

pip install onnxruntime huggingface-hub numpy pillow
# 如需GPU支持:
pip install onnxruntime-gpu

输入要求

  • 图像格式: 3波段RGB栅格(JPEG、PNG、GeoTIFF)
  • 波段顺序: 红、绿、蓝
  • 像素值: 标准8位(0-255范围)
  • 空间分辨率: 针对高分辨率无人机影像进行了优化(厘米级)
  • 场景类型: 潮间带区域、浅潮下带、有贻贝床的水产养殖场

输出格式

  • 类型: 单波段栅格,包含类别标签
  • 值:
    • 0:背景(水、岩石、其他底质、非贻贝生物)
    • 1:贻贝(通常为蓝贻贝,Mytilus spp.)
  • 格式: 与输入栅格格式和投影一致
  • 空间分辨率: 与输入相同

注意: 模型输出类别概率,但kelp-o-matic会自动应用argmax将其转换为离散类别标签。

性能说明

  • 动态分块尺寸: 支持灵活的分块尺寸(推荐:2048x2048或1024x1024)
  • 批大小: 从4开始,根据可用GPU内存进行调整

大图像处理

对于处理大型地理空间图像,kelp-o-matic包会处理:

  • 自动分块: 将大图像分割成可管理的分块
  • 重叠处理: 使用重叠分块以避免边缘伪影
  • 内存管理: 批量处理分块以管理内存使用
  • 地理空间元数据: 保留坐标参考系统和地理变换
  • 后处理: 可选的中值滤波和形态学操作

引用

如果您在研究中使用此模型,请引用:

@software{Denouden_Kelp-O-Matic,
  author = {Denouden, Taylor and Reshitnyk, Luba},
  doi = {10.5281/zenodo.7672166},
  title = {{Kelp-O-Matic}},
  url = {https://github.com/HakaiInstitute/kelp-o-matic}
}

许可证

MIT许可证 - 详情请参阅kelp-o-matic仓库

相关资源

联系方式

如有问题或疑问:

HakaiInstitute/mussel-rgb

作者 HakaiInstitute

image-segmentation
↓ 0 ♥ 1

创建时间: 2025-07-28 21:17:07+00:00

更新时间: 2025-07-28 22:51:59+00:00

在 Hugging Face 上查看

文件 (3)

.gitattributes
README.md
model.onnx ONNX