返回模型
说明文档
Kelp-RGB: 面向RGB无人机图像的海带分割模型
模型类型: ONNX语义分割
应用场景: 高分辨率RGB航空影像中的海带森林检测
输入: 3波段RGB图像(红、绿、蓝)
输出: 二值分割掩膜(海带 vs. 非海带)
模型描述
Kelp-RGB模型是一个专门用于检测RGB无人机影像中海带森林的深度学习语义分割模型。该模型处理标准RGB图像,为海洋栖息地监测和研究提供准确的海带分割功能,使其能够适用于普通消费级无人机和相机。
主要特性:
- 针对无人机标准RGB图像优化
- 使用ImageNet预训练归一化统计参数
- 高效的ONNX格式,支持跨平台部署
- 专为高分辨率航空摄影设计(约3-7厘米分辨率)
模型详情
- 版本: 20250728
- 输入通道: 3 (RGB)
- 输入尺寸: 动态分块(推荐: 2048x2048 分块)
- 归一化: 标准ImageNet统计参数
- 输出: 多类别分割(0: 背景, 1: 巨型海带, 2: 牛海带)
- 格式: 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 kelp-rgb \
--input /path/to/rgb_drone_image.tif \
--output /path/to/kelp_species_segmentation.tif \
--batch-size 8 \
--crop-size 2048 \
--blur-kernel 5 \
--morph-kernel 3
# 使用特定模型版本
kom segment \
--model kelp-rgb \
--version 20250728 \
--input image.tif \
--output result.tif
# 对于高分辨率图像,使用更大的分块
kom segment \
--model kelp-rgb \
--input high_res_drone_image.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[\"kelp-rgb\"]
# 处理大型航空图像,支持自动分块
model.process(
input_path=\"path/to/your/rgb_drone_image.tif\",
output_path=\"path/to/output/kelp_species_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(\"drone_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=巨型海带, 2=牛皮海带
3. 直接使用ONNX Runtime
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/kelp-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(\"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=巨型海带, 2=牛皮海带
4. 使用HuggingFace Hub集成
from huggingface_hub import hf_hub_download
import onnxruntime as ort
# 下载并加载模型
model_path = hf_hub_download(
repo_id=\"HakaiInstitute/kelp-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: Macrocystis pyrifera(巨型海带)
- 2: Nereocystis luetkeana(牛皮海带)
- 格式: 与输入栅格格式和投影一致
- 空间分辨率: 与输入相同
注意: 模型输出类别概率,但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仓库。
相关资源
- 文档: kelp-o-matic.readthedocs.io
- 源代码: github.com/HakaiInstitute/kelp-o-matic
- 其他模型: 查看Hakai Institute HuggingFace组织获取更多海带分割模型
联系方式
如有问题或反馈:
- 在GitHub仓库提交issue
- 联系: Hakai Institute
HakaiInstitute/kelp-rgb
作者 HakaiInstitute
image-segmentation
↓ 0
♥ 0
创建时间: 2025-07-28 19:33:50+00:00
更新时间: 2025-09-03 20:04:36+00:00
在 Hugging Face 上查看文件 (3)
.gitattributes
README.md
model.onnx
ONNX