如何为segformer准备数据集?

发布于 2025-02-07 04:23:35 字数 870 浏览 3 评论 0原文

我正在尝试训练Segformer进行一些医学图像,因此,按照微调教程尽可能接近 lnk

数据集由一些fMRI图像和要分割的特定病变组成,这些图像的大小

dataset = Dataset.from_dict({"image": img, 'label': mask}).cast_column("image", Image()).cast_column("label", Image())
dataset[0]
{'image': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=562x471>,
 'label': <PIL.PngImagePlugin.PngImageFile image mode=1 size=562x471>}

我尝试使用该功能的semantic_bitmap的

def convert_segmentation_bitmap(example):
    return {
        "label.segmentation_bitmap":
            get_semantic_bitmap(
                example["image"],
                example["label"],
                id_increment=0,
            )
    }

与 ?

原始fMRIS相同获得该图像的语义图是我所缺少的吗

谢谢

I'm trying to train a segformer for some medical images and therefore following the Fine tuning tutorial as close as possible lnk.

The dataset consists of some FMRI images and the specific lesion to segment out, these images are of the same size of the original FMRIs

dataset = Dataset.from_dict({"image": img, 'label': mask}).cast_column("image", Image()).cast_column("label", Image())
dataset[0]
{'image': <PIL.PngImagePlugin.PngImageFile image mode=RGB size=562x471>,
 'label': <PIL.PngImagePlugin.PngImageFile image mode=1 size=562x471>}

I've tried to use get_semantic_bitmap from segments-ai.utils with this function

def convert_segmentation_bitmap(example):
    return {
        "label.segmentation_bitmap":
            get_semantic_bitmap(
                example["image"],
                example["label"],
                id_increment=0,
            )
    }

But this throws a TypeError Exception since PNG are not iterable

What am I missing to obtain the semantic map of this images?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年慕年 2025-02-14 04:23:35

您的地面真相语义分割图应为2D阵列,其中包含每个像素的标签。这意味着,如果您将“标签”功能(类型映像)转换为numpy阵列,则获得一个2D数组:

import numpy as np

np.array(dataset[0]['label'])

这可能看起来如下:

[[1, 2], [2,2]]

这里有四个像素,其中三个被标记注释2和一个标签1注释。

Your ground truth semantic segmentation map should be a 2D array, that contains a label for each pixel. This means that if you would convert your "label" feature (which is of type Image) to a NumPy array, you obtain a 2D array:

import numpy as np

np.array(dataset[0]['label'])

This could look like the following:

[[1, 2], [2,2]]

Here we have four pixels, three of them being annotated with label 2 and one being annotated with label 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文