Segformer B5 Finetuned Coralscapes 1024 1024
針對珊瑚礁語義分割任務優化的SegFormer模型,在1024x1024分辨率下對Coralscapes數據集進行微調
下載量 821
發布時間 : 3/21/2025
模型概述
該模型是基於SegFormer架構的語義分割模型,專門用於珊瑚礁生態系統的場景理解,能夠準確識別和分割珊瑚礁圖像中的不同語義類別。
模型特點
高分辨率處理能力
支持1024x1024高分辨率圖像輸入,適合珊瑚礁場景的精細分割
數據增強優化
訓練時採用多種數據增強策略,包括隨機縮放、旋轉和色彩抖動,提高模型魯棒性
滑動窗口預測
提供滑動窗口預測功能,可處理任意尺寸的輸入圖像
模型能力
珊瑚礁圖像語義分割
高分辨率圖像處理
生態場景理解
使用案例
生態監測
珊瑚礁健康評估
通過分割珊瑚礁圖像中的不同生物類別,評估珊瑚礁生態系統健康狀況
可識別40種不同珊瑚和海洋生物類別
水下生態調查
自動分析水下攝影或視頻中的珊瑚覆蓋率和分佈情況
測試集平均交併比達57.8%
🚀 珊瑚礁圖像分割模型
本項目基於SegFormer模型,使用MiT - B5骨幹網絡在Coralscapes數據集上進行微調,可用於珊瑚礁圖像的語義分割,為珊瑚礁生態研究提供了有效的工具。
🚀 快速開始
使用此模型對Coralscapes數據集中的圖像進行分割的最簡單方法如下:
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
from datasets import load_dataset
# 從coralscapes數據集中加載圖像或加載您自己的圖像
dataset = load_dataset("EPFL-ECEO/coralscapes")
image = dataset["test"][42]["image"]
preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
inputs = preprocessor(image, return_tensors = "pt")
outputs = model(**inputs)
outputs = preprocessor.post_process_semantic_segmentation(outputs, target_sizes=[(image.size[1], image.size[0])])
label_pred = outputs[0].numpy()
雖然上述方法對於不同大小和比例的圖像仍然有效,但對於與模型訓練大小(1024x1024)相差較大的圖像,我們建議使用以下滑動窗口方法以獲得更好的結果:
import torch
import torch.nn.functional as F
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
import numpy as np
from datasets import load_dataset
device = 'cuda' if torch.cuda.is_available() else 'cpu'
def resize_image(image, target_size=1024):
"""
用於調整圖像大小,使較小的邊等於1024
"""
h_img, w_img = image.size
if h_img < w_img:
new_h, new_w = target_size, int(w_img * (target_size / h_img))
else:
new_h, new_w = int(h_img * (target_size / w_img)), target_size
resized_img = image.resize((new_h, new_w))
return resized_img
def segment_image(image, preprocessor, model, crop_size = (1024, 1024), num_classes = 40, transform=None):
"""
根據圖像大小和寬高比找到最佳步長,創建大小為1024x1024的重疊滑動窗口,然後將其輸入到模型中。
"""
h_crop, w_crop = crop_size
img = torch.Tensor(np.array(resize_image(image, target_size=1024)).transpose(2, 0, 1)).unsqueeze(0)
batch_size, _, h_img, w_img = img.size()
if transform:
img = torch.Tensor(transform(image = img.numpy())["image"]).to(device)
h_grids = int(np.round(3/2*h_img/h_crop)) if h_img > h_crop else 1
w_grids = int(np.round(3/2*w_img/w_crop)) if w_img > w_crop else 1
h_stride = int((h_img - h_crop + h_grids -1)/(h_grids -1)) if h_grids > 1 else h_crop
w_stride = int((w_img - w_crop + w_grids -1)/(w_grids -1)) if w_grids > 1 else w_crop
preds = img.new_zeros((batch_size, num_classes, h_img, w_img))
count_mat = img.new_zeros((batch_size, 1, h_img, w_img))
for h_idx in range(h_grids):
for w_idx in range(w_grids):
y1 = h_idx * h_stride
x1 = w_idx * w_stride
y2 = min(y1 + h_crop, h_img)
x2 = min(x1 + w_crop, w_img)
y1 = max(y2 - h_crop, 0)
x1 = max(x2 - w_crop, 0)
crop_img = img[:, :, y1:y2, x1:x2]
with torch.no_grad():
if(preprocessor):
inputs = preprocessor(crop_img, return_tensors = "pt")
inputs["pixel_values"] = inputs["pixel_values"].to(device)
else:
inputs = crop_img.to(device)
outputs = model(**inputs)
resized_logits = F.interpolate(
outputs.logits[0].unsqueeze(dim=0), size=crop_img.shape[-2:], mode="bilinear", align_corners=False
)
preds += F.pad(resized_logits,
(int(x1), int(preds.shape[3] - x2), int(y1),
int(preds.shape[2] - y2))).cpu()
count_mat[:, :, y1:y2, x1:x2] += 1
assert (count_mat == 0).sum() == 0
preds = preds / count_mat
preds = preds.argmax(dim=1)
preds = F.interpolate(preds.unsqueeze(0).type(torch.uint8), size=image.size[::-1], mode='nearest')
label_pred = preds.squeeze().cpu().numpy()
return label_pred
# 從coralscapes數據集中加載圖像或加載您自己的圖像
dataset = load_dataset("EPFL-ECEO/coralscapes")
image = dataset["test"][42]["image"]
preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
label_pred = segment_image(image, preprocessor, model)
✨ 主要特性
- 基於SegFormer模型,在珊瑚礁圖像分割任務上表現出色。
- 使用MiT - B5骨幹網絡,具有強大的特徵提取能力。
- 在Coralscapes數據集上進行微調,適用於珊瑚礁生態研究。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
from datasets import load_dataset
# 從coralscapes數據集中加載圖像或加載您自己的圖像
dataset = load_dataset("EPFL-ECEO/coralscapes")
image = dataset["test"][42]["image"]
preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
inputs = preprocessor(image, return_tensors = "pt")
outputs = model(**inputs)
outputs = preprocessor.post_process_semantic_segmentation(outputs, target_sizes=[(image.size[1], image.size[0])])
label_pred = outputs[0].numpy()
高級用法
import torch
import torch.nn.functional as F
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
import numpy as np
from datasets import load_dataset
device = 'cuda' if torch.cuda.is_available() else 'cpu'
def resize_image(image, target_size=1024):
"""
用於調整圖像大小,使較小的邊等於1024
"""
h_img, w_img = image.size
if h_img < w_img:
new_h, new_w = target_size, int(w_img * (target_size / h_img))
else:
new_h, new_w = int(h_img * (target_size / w_img)), target_size
resized_img = image.resize((new_h, new_w))
return resized_img
def segment_image(image, preprocessor, model, crop_size = (1024, 1024), num_classes = 40, transform=None):
"""
根據圖像大小和寬高比找到最佳步長,創建大小為1024x1024的重疊滑動窗口,然後將其輸入到模型中。
"""
h_crop, w_crop = crop_size
img = torch.Tensor(np.array(resize_image(image, target_size=1024)).transpose(2, 0, 1)).unsqueeze(0)
batch_size, _, h_img, w_img = img.size()
if transform:
img = torch.Tensor(transform(image = img.numpy())["image"]).to(device)
h_grids = int(np.round(3/2*h_img/h_crop)) if h_img > h_crop else 1
w_grids = int(np.round(3/2*w_img/w_crop)) if w_img > w_crop else 1
h_stride = int((h_img - h_crop + h_grids -1)/(h_grids -1)) if h_grids > 1 else h_crop
w_stride = int((w_img - w_crop + w_grids -1)/(w_grids -1)) if w_grids > 1 else w_crop
preds = img.new_zeros((batch_size, num_classes, h_img, w_img))
count_mat = img.new_zeros((batch_size, 1, h_img, w_img))
for h_idx in range(h_grids):
for w_idx in range(w_grids):
y1 = h_idx * h_stride
x1 = w_idx * w_stride
y2 = min(y1 + h_crop, h_img)
x2 = min(x1 + w_crop, w_img)
y1 = max(y2 - h_crop, 0)
x1 = max(x2 - w_crop, 0)
crop_img = img[:, :, y1:y2, x1:x2]
with torch.no_grad():
if(preprocessor):
inputs = preprocessor(crop_img, return_tensors = "pt")
inputs["pixel_values"] = inputs["pixel_values"].to(device)
else:
inputs = crop_img.to(device)
outputs = model(**inputs)
resized_logits = F.interpolate(
outputs.logits[0].unsqueeze(dim=0), size=crop_img.shape[-2:], mode="bilinear", align_corners=False
)
preds += F.pad(resized_logits,
(int(x1), int(preds.shape[3] - x2), int(y1),
int(preds.shape[2] - y2))).cpu()
count_mat[:, :, y1:y2, x1:x2] += 1
assert (count_mat == 0).sum() == 0
preds = preds / count_mat
preds = preds.argmax(dim=1)
preds = F.interpolate(preds.unsqueeze(0).type(torch.uint8), size=image.size[::-1], mode='nearest')
label_pred = preds.squeeze().cpu().numpy()
return label_pred
# 從coralscapes數據集中加載圖像或加載您自己的圖像
dataset = load_dataset("EPFL-ECEO/coralscapes")
image = dataset["test"][42]["image"]
preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b5-finetuned-coralscapes-1024-1024")
label_pred = segment_image(image, preprocessor, model)
📚 詳細文檔
模型詳情
模型描述
屬性 | 詳情 |
---|---|
模型類型 | SegFormer |
微調基礎模型 | SegFormer (b5-sized) encoder pre-trained-only (nvidia/mit-b5 ) |
模型來源
訓練與評估詳情
數據
模型在Coralscapes數據集上進行訓練和評估,該數據集是一個用於珊瑚礁的通用密集語義分割數據集。
過程
訓練主要遵循Segformer的原始實現,只是在訓練期間使用了更強的增強方法。 我們使用批量大小為4,訓練100個週期,使用AdamW優化器,初始學習率為6e - 5,權重衰減為1e - 2,並使用冪為1的多項式學習率調度器。 在訓練期間,圖像在1.02到2的範圍內隨機縮放,寬高比為3/4到4/3,包括最多15度的隨機旋轉(裁剪以排除非圖像區域), 以及對比度、飽和度和亮度在0.8到1.2之間的隨機顏色抖動,色調變化在 - 0.05到0.05之間。 輸入圖像使用ImageNet的均值和標準差進行歸一化。在評估時,採用非重疊滑動窗口策略,窗口大小為1024x1024。
結果
- 測試準確率:82.761
- 測試平均IoU:57.800
🔧 技術細節
文檔未提及技術細節相關內容,故跳過此章節。
📄 許可證
本項目使用apache - 2.0
許可證。
📚 引用
如果您發現此項目有用,請考慮引用:
@misc{sauder2025coralscapesdatasetsemanticscene,
title={The Coralscapes Dataset: Semantic Scene Understanding in Coral Reefs},
author={Jonathan Sauder and Viktor Domazetoski and Guilhem Banc-Prandi and Gabriela Perna and Anders Meibom and Devis Tuia},
year={2025},
eprint={2503.20000},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2503.20000},
}
Clipseg Rd64 Refined
Apache-2.0
CLIPSeg是一種基於文本與圖像提示的圖像分割模型,支持零樣本和單樣本圖像分割任務。
圖像分割
Transformers

C
CIDAS
10.0M
122
RMBG 1.4
其他
BRIA RMBG v1.4 是一款先進的背景移除模型,專為高效分離各類圖像的前景與背景而設計,適用於非商業用途。
圖像分割
Transformers

R
briaai
874.12k
1,771
RMBG 2.0
其他
BRIA AI開發的最新背景移除模型,能有效分離各類圖像的前景與背景,適合大規模商業內容創作場景。
圖像分割
Transformers

R
briaai
703.33k
741
Segformer B2 Clothes
MIT
基於ATR數據集微調的SegFormer模型,用於服裝和人體分割
圖像分割
Transformers

S
mattmdjaga
666.39k
410
Sam Vit Base
Apache-2.0
SAM是一個能夠通過輸入提示(如點或框)生成高質量對象掩碼的視覺模型,支持零樣本分割任務
圖像分割
Transformers 其他

S
facebook
635.09k
137
Birefnet
MIT
BiRefNet是一個用於高分辨率二分圖像分割的深度學習模型,通過雙邊參考網絡實現精確的圖像分割。
圖像分割
Transformers

B
ZhengPeng7
626.54k
365
Segformer B1 Finetuned Ade 512 512
其他
SegFormer是一種基於Transformer的語義分割模型,在ADE20K數據集上進行了微調,適用於圖像分割任務。
圖像分割
Transformers

S
nvidia
560.79k
6
Sam Vit Large
Apache-2.0
SAM是一個能夠通過輸入提示點或邊界框生成高質量物體掩膜的視覺模型,具備零樣本遷移能力。
圖像分割
Transformers 其他

S
facebook
455.43k
28
Face Parsing
基於nvidia/mit-b5微調的語義分割模型,用於面部解析任務
圖像分割
Transformers 英語

F
jonathandinu
398.59k
157
Sam Vit Huge
Apache-2.0
SAM是一個能夠根據輸入提示生成高質量對象掩碼的視覺模型,支持零樣本遷移到新任務
圖像分割
Transformers 其他

S
facebook
324.78k
163
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98