Pytorch-UNet icon indicating copy to clipboard operation
Pytorch-UNet copied to clipboard

predict.py - i image.jpg - o output.jpg code; 输出图片却是一张纯黑的图片。

Open seeyouwlx opened this issue 2 years ago • 6 comments

Run the Python predict.py - i image.jpg - o output.jpg code; There is a problem now, which is importing the image I want to test, but the output image is a pure black image. I hope someone can give me some g 3 2 1 uidance!

seeyouwlx avatar May 18 '23 03:05 seeyouwlx

Hello, have you resolved it. I would like to ask for advice.

zrz1018 avatar Jun 03 '23 14:06 zrz1018

emmm, mask图后面要加_mask后缀,或者修改utils/data_loading.py中的CarvanaDataset,把mask_suffix设为空 image

714273725 avatar Jun 06 '23 08:06 714273725

you may change the function as

def mask_to_image(mask: np.ndarray, mask_values):
    if isinstance(mask_values[0], list):
        out = np.zeros(
            (mask.shape[-2], mask.shape[-1], len(mask_values[0])), dtype=np.uint8
        )
    elif mask_values == [0, 1]:
        out = np.zeros((mask.shape[-2], mask.shape[-1]), dtype=bool)
    else:
        # out = np.zeros((mask.shape[-2], mask.shape[-1]), dtype=np.uint8)
        out = np.zeros((mask.shape[-2], mask.shape[-1], 3), dtype=np.uint8)
    print(mask.shape)

    if mask.ndim == 3:
        mask = np.argmax(mask, axis=0)

    if mask_values == [0, 1]:
        for i, v in enumerate(mask_values):
            out[mask == i] = v
        return Image.fromarray(out)
    else:
        for i, _ in enumerate(mask_values):
            out[mask == i] = list(np.random.choice(range(256), size=3))
        return Image.fromarray(out, "RGB")

Note that if you would like to have a desired color list, instead of using random as shown in the example. Just define your color list to replace list(np.random.choice(range(256), size=3))

tomcattiger1230 avatar Nov 21 '23 07:11 tomcattiger1230

emmm, mask图后面要加_mask后缀,或者修改utils/data_loading.py中的CarvanaDataset,把mask_suffix设为空 image

改了没用啊?

FRC1221 avatar Mar 08 '24 09:03 FRC1221

@seeyouwlx Hello, have you resolved it?

XxUpUp avatar May 11 '24 10:05 XxUpUp

emmm, mask图后面要加_mask后缀,或者修改utils/data_loading.py中的CarvanaDataset,把mask_suffix设为空 image

改了没用啊?

加了之后需要重新训练

714273725 avatar Jun 24 '24 05:06 714273725