mindspore-minist数据集使用c_vision.Decode()报错

参考社区的这篇链接:华为云论坛_云计算论坛_开发者论坛_技术论坛-华为云

想把minist数据集换成3通道(ds.MnistDataset()加载的数据集是1通道)

但是在decode的时候报错

Traceback (most recent call last):
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/transforms/py_transforms_util.py", line 185, in __call__
    result = self.transform(*args)
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/transforms/validators.py", line 259, in new_method
    return method(self, *args, **kwargs)
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/transforms/py_transforms.py", line 194, in __call__
    return util.compose(self.transforms, *args)
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/transforms/py_transforms_util.py", line 52, in compose
    result.reraise()
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/core/py_util_helpers.py", line 62, in reraise
    raise self.except_type(err_msg)
ValueError: Caught ValueError in map(or batch) worker and execute Python function.
Original Traceback (most recent call last):
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/vision/py_transforms_util.py", line 106, in decode
    img = Image.open(data)
  File "/home/coco2/.local/lib/python3.9/site-packages/PIL/Image.py", line 3030, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f537913c180>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/transforms/py_transforms_util.py", line 49, in compose
    args = transform(*args)
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/vision/py_transforms.py", line 245, in __call__
    return util.decode(img)
  File "/home/coco2/.local/lib/python3.9/site-packages/mindspore/dataset/vision/py_transforms_util.py", line 109, in decode
    raise ValueError("{0}\n: Failed to decode given image.".format(e))
ValueError: cannot identify image file <_io.BytesIO object at 0x7f537913c180>
: Failed to decode given image.

【操作步骤&问题现象】

【截图信息】

核心代码:

【日志信息】(可选,上传日志内容或者附件)

报错信息:

*******************************************************************************************************************

mnist数据集本身是单通道的,即黑白图片,直接通过加载上来是没法做Decode操作的: > 找了个介绍,也能看到是黑白图片 > https://zhuanlan.zhihu.com/p/36592188 - MnistDataset的UT如下,可以看下怎么使用,在下面这一行加一下`print("data:", _)`打印,可以看到其shape是: > image: shape为[28, 28, 1] label: 单个整数 https://gitee.com/mindspore/mindspore/blob/master/tests/ut/python/dataset/test_datasets_mnist.py#L87 - Decode本身是:将1维的数据Decode成3通道的,mnist的输入不是一维的,不能进行Decode(黑白的也不能变成彩色的来着) > 注:通常未进行Decode的时候是一维的,即类似python 中的一维list, 如下,其shape 为[N], 单通道的是多维度的,其shape为:[H, W, 1] >> data = [124, 223, 128, 147, 123, 15, 167... 135, 119, 255] --- 1. 上面提及的主要是读取官方的数据集,其本身就是黑白即单通道的,应该没法直接变成3通道即RGB数据集 2. 看着有些博客提及需要mnist 彩色数据集怎么办,可以分析下, 有些只是自己读上来知会加个颜色再保存出来,这可能变成一个新的数据集,针对这个数据集读取可以采用GeneratorDataset实现自定义读取

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值