/ Модель

Характеристики

Лицензия
Apache 2.0
Архитектура
segformer · dense
Библиотека
transformers
Опубликована
7 мар 2025

segformer-b2-finetuned-coralscapes-1024-1024

Сегментация изображенийИзображение → mask3 профессии

SegFormer MiT-B2, дообученная на Coralscapes для семантической сегментации изображений коралловых рифов.

219скачиваний за 30 дней0лайковвеса обновлены24 апр 2026

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

SegFormer с энкодером MiT-B2, разработанный авторами проекта Coralscapes и дообученный на датасете Coralscapes для семантической сегментации изображений коралловых рифов. Модель принимает изображения и присваивает пикселям классы, помогая анализировать подводные сцены и состав рифовых экосистем.

Модель основана на предварительно обученном энкодере nvidia/mit-b2 и реализована для библиотеки Transformers. Обучение и оценка проводились с изображениями, случайно обрезанными до 1024×1024 пикселей; при оценке использовалась скользящая обработка окнами того же размера. В README приведены тестовая точность 80,904 и средний IoU 54,682.

Модель ориентирована на изображения коралловых рифов и может хуже работать на сценах, отличающихся от обучающего датасета. Распространяется по лицензии Apache-2.0.

Сценарии применения

  • семантическая сегментация подводных фотографий рифов
  • разметка классов объектов на изображениях коралловых экосистем
  • анализ состава сцен коралловых рифов
  • подготовка карт пиксельной разметки для экологических исследований

Ограничения

Модель обучена на Coralscapes и предназначена для сцен коралловых рифов; качество на других типах изображений может снижаться. Оценка в README составляет 80,904 точности и 54,682 среднего IoU.

Для каких профессий подходит3

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

Model Card for Model ID

SegFormer model with a MiT-B2 backbone fine-tuned on Coralscapes at resolution 1024x1024, as introduced in The Coralscapes Dataset: Semantic Scene Understanding in Coral Reefs.

Model Details

Model Description

Model Sources

How to Get Started with the Model

The simplest way to use this model to segment an image of the Coralscapes dataset is as follows:

from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
from PIL import Image
from datasets import load_dataset

# Load an image from the coralscapes dataset or load your own image 
dataset = load_dataset("EPFL-ECEO/coralscapes") 
image = dataset["test"][42]["image"]

preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b2-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b2-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()

While using the above approach should still work for images of different sizes and scales, for images that are not close to the training size of the model (1024x1024), we recommend using the following approach using a sliding window to achieve better results:

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):
    """
    Used to resize the image such that the smaller side equals 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):
    """
    Finds an optimal stride based on the image size and aspect ratio to create
    overlapping sliding windows of size 1024x1024 which are then fed into the model.  
    """ 
    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

# Load an image from the coralscapes dataset or load your own image 
dataset = load_dataset("EPFL-ECEO/coralscapes") 
image = dataset["test"][42]["image"]

preprocessor = SegformerImageProcessor.from_pretrained("EPFL-ECEO/segformer-b2-finetuned-coralscapes-1024-1024")
model = SegformerForSemanticSegmentation.from_pretrained("EPFL-ECEO/segformer-b2-finetuned-coralscapes-1024-1024")

label_pred = segment_image(image, preprocessor, model)

Training & Evaluation Details

Data

The model is trained and evaluated on the Coralscapes dataset which is a general-purpose dense semantic segmentation dataset for coral reefs.

Procedure

Training is conducted following the Segformer original implementation, using a batch size of 8 for 265 epochs, using the AdamW optimizer with an initial learning rate of 6e-5, weight decay of 1e-2 and polynomial learning rate scheduler with a power of 1. During training, images are randomly scaled within a range of 1 and 2, flipped horizontally with a 0.5 probability and randomly cropped to 1024×1024 pixels. Input images are normalized using the ImageNet mean and standard deviation. For evaluation, a non-overlapping sliding window strategy is employed, using a window size of 1024x1024.

Results

  • Test Accuracy: 80.904
  • Test Mean IoU: 54.682

Citation

If you find this project useful, please consider citing:

@inproceedings{sauder2025coralscapes,
  title={The Coralscapes Dataset: Semantic Scene Understanding in Coral Reefs},
  author={Sauder, Jonathan and Domazetoski, Viktor and Banc-Prandi, Guilhem and Perna, Gabriela and Meibom, Anders and Tuia, Devis},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision: Joint Workshop on Marine Vision},
  pages={2115--2122},
  year={2025}
}

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · transformers · image-segmentation

Можно запустить

Подбираем GPU…

Класс архитектуры
SegformerForSemanticSegmentation
Ревизия весов
c4bf10d

0 моделей