Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

questions about image shape #208

Open
JIBSN opened this issue Feb 1, 2024 · 1 comment
Open

questions about image shape #208

JIBSN opened this issue Feb 1, 2024 · 1 comment

Comments

@JIBSN
Copy link

JIBSN commented Feb 1, 2024

Hi,
I am now training micro-sam with a custom dataset. The shape of my raw imags is HxWx3 and the label's shape is HxW. I found an error "File "/home/jovyan/.conda/micro-sam/lib/python3.10/site-packages/torch_em/data/segmentation_dataset.py", line 61, in init
assert shape_raw == shape_label, f"{shape_raw}, {shape_label}"
AssertionError: (2048, 3), (2048, 2048)".
I am confused with this error. Please give me some tips why it happens and how to solve it.

@anwai98
Copy link
Contributor

anwai98 commented Feb 1, 2024

Hi @JIBSN,
From the looks of the error, I am assuming that you are making use of the torch_em.default_segmentation_loader (as for example, here). In this case, the segmentation dataset's expectation is to have channels first for the inputs (i.e. shape of the image should be 3 x H x W). You can use a raw transform to transpose the axes to make use of it, for example:

def custom_raw_transform(raw):
    "Chaning the axes for the input images from H x W X 3 -> 3 x H x W"
    raw = raw.transpose(2, 0, 1)
    return raw

loader = torch_em.default_segmentation_loader(..., raw_transform=custom_raw_transform, ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants