ValueError: operands could not be broadcast together with shapes (320,320,4) (3,) (320,320,4)

problem:

ValueError: operands could not be broadcast together with shapes (320,320,4) (3,) (320,320,4)

​​​​​​​

solution:

数据集中JPEGImages应该是jpg文件,image mode=RGB

SegmentationClass中应该是png文件,image  mode=P

将自己数据集的图片改为正确格式即可

模式
1             1位像素,黑和白,存成8位的像素
L             8位像素,黑白
P             8位像素,使用调色板映射到任何其他模式
RGB           3×8位像素,真彩
RGBA          4×8位像素,真彩+透明通道
CMYK          4×8位像素,颜色隔离
YCbCr         3×8位像素,彩色视频格式
I             32位整型像素
F             32位浮点型像素

def get_seg(img_list):
    # img_list保存了train.txt中的数据
    folder_path = '/home/vision/users/hhu/datasets/old_lib_dateset/SegmentationClass'
    for img in img_list:
        src_path = osp.join(folder_path,img+'.png')
        img1 = PIL.Image.open(src_path)
        P_img = img1.convert('P')
        print(P_img)
        end_img_path = osp.join('/home/vision/users/hhu/datasets/lib_dateset/SegmentationClass',img+'.png')
        P_img.save(end_img_path)

猜你喜欢

转载自blog.csdn.net/weixin_48262500/article/details/121285618