CellProfiling / HPA-Cell-Segmentation

Apache License 2.0
95 stars 26 forks source link

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. #16

Closed NTNguyen13 closed 3 years ago

NTNguyen13 commented 3 years ago

Hi, I'm currently using this package for segmentation of multichannel confocal microscopy cell image. The package works well for most of the case, except when image size is (1728, 1728). I have tried it with different size such as (2048, 2048) and (3072, 3072), it's still good.

To reproduce the problem:

NUC_MODEL = '~/HPA_image/segmentation_weight/dpn_unet_nuclei_v1.pth'
CELL_MODEL = ~/HPA_image/segmentation_weight/dpn_unet_cell_3ch_v1.pth'

segmentator = cellsegmentator.CellSegmentator(NUC_MODEL,
                                              CELL_MODEL,
                                              scale_factor=0.25,
                                              device='cpu',
                                              padding=False,
                                              multi_channel_model=True
                                              )

nuc_segmentations = segmentator.pred_nuclei(path_nu)
cell_segmentations = segmentator.pred_cells(path_3channel)

I have tried with multiple images, it always return the same error: RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 1. Got 28 and 27 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:612

if the image size is (1728, 1728).

Could you please help me with this? Thank you

Linsho commented 3 years ago

I think that problem can be solved by setting the value of padding to True.

cwinsnes commented 3 years ago

Yes, if you set padding to True this should be fixed. Could you verify that's the case?

NTNguyen13 commented 3 years ago

yes, it's fixed using padding=True