Baixuzx7/P2Sharpen

ValueError: pic should be 2/3 dimensional. Got 4 dimensions.

Opened this issue · 6 comments

Hello, I am doing research on image fusion recently. Your article is very inspiring to me, but I have a problem when I reproduce the code. For the ms 4D image, this position will report an error. How did you deal with it at that time?
image
image

Hello, I think the problem is that the function (self.transform) can only process the image with 2 or 3 dimention (2 for gray scale image with size of H x W, 3 for color image with size of H x W x C), So please check the size of image data (variable image_ms image_ms_label image_pan_label), maybe the file in the path is not a single image format.

Hello, I think the problem is that the function (self.transform) can only process the image with 2 or 3 dimention (2 for gray scale image with size of H x W, 3 for color image with size of H x W x C), So please check the size of image data (variable image_ms image_ms_label image_pan_label), maybe the file in the path is not a single image format.

"image_ms" is a multispectral image, which is indeed R, G, B, and NIR 4 channels, so there should be a problem here. I haven't modified the code. I'm curious, have you done any other processing here before?

We provide a standard image format that can be processed in the Dataset folder, you can unzip the compressed file and try it out. By the way, can you add the following code in this section, let me confirm the image data format you read in?

def __getitem__(self, item):
    image_pan_path = os.path.join(self.root, 'pan', self.images_pan[item])
    image_ms_path = os.path.join(self.root, 'ms', self.images_ms[item])
    image_ms_label_path = os.path.join(self.root, 'ms_label', self.images_ms_label[item])
    image_pan_label_path = os.path.join(self.root, 'pan_label', self.images_pan_label[item])

    image_pan = imageio.imread(image_pan_path) 
    image_ms = imageio.imread(image_ms_path)  # B G R NIR
    image_ms_label = imageio.imread(image_ms_label_path)
    image_pan_label = imageio.imread(image_pan_label_path)

    print(image_pan.shape,image_ms.shape,image_ms_label.shape,image_pan_label.shape)

    if self.transform is not None:
        image_pan = self.transform(image_pan)
        image_ms = self.transform(image_ms)
        image_pan_label = self.transform(image_pan_label)
        image_ms_label = self.transform(image_ms_label)
        pass

    return image_pan, image_ms, image_pan_label, image_ms_label


For example, running the following code, I get these information.
`

if __name__ == '__main__':
    data_transform = {
    'test': torchvision.transforms.Compose(
        [
            torchvision.transforms.ToTensor(),
            torchvision.transforms.Normalize((0.5), (0.5))
        ]
    )}
    test_dataset = PanSharpeningDataset('./Dataset/TestFolder', transform=data_transform['test'])
    print(len(test_dataset))
    image_pan, image_ms, image_pan_label, image_ms_label = test_dataset[0]
    print(image_pan.size(),image_ms.size(),image_pan_label.size(),image_ms_label.size())
    exit(0)

`
image

L-gzy commented

Hello, I think the problem is that the function (self.transform) can only process the image with 2 or 3 dimention (2 for gray scale image with size of H x W, 3 for color image with size of H x W x C), So please check the size of image data (variable image_ms image_ms_label image_pan_label), maybe the file in the path is not a single image format.

"image_ms" is a multispectral image, which is indeed R, G, B, and NIR 4 channels, so there should be a problem here. I haven't modified the code. I'm curious, have you done any other processing here before?

Hello, I also have this situation, have you solved it? Can you share it? Thank you very much

L-gzy commented

您好,我认为问题是函数(self.transform)只能处理2或3尺寸的图像(2用于大小为H x W的灰度图像,3用于大小为H x W x C的彩色图像),因此请检查图像数据的大小(变量image_ms image_ms_label image_pan_label), 也许路径中的文件不是单一的图像格式。

I found that we should in “dataset.py” below
image_pan_label = imageio.imread(image_pan_label_path)
supplement :
image_ms = image_ms[0]
image_pan = image_pan[0]

您好,我认为问题是函数(self.transform)只能处理2或3尺寸的图像(2用于大小为H x W的灰度图像,3用于大小为H x W x C的彩色图像),因此请检查图像数据的大小(变量image_ms image_ms_label image_pan_label), 也许路径中的文件不是单一的图像格式。

我发现我们应该在下面的“dataset.py”中image_pan_label = imageio.imread(image_pan_label_path) 补充:image_ms = image_ms[0] image_pan = image_pan[0]

您好,我目前刚定的研究方向是遥感图像融合,我想请教一下您的咱们这个遥感数据的数据集该如何去制作的?我这有几幅原始数据,但是不知道该如何处理。