Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmseg/datasets/transforms/loading.py中的LoadImageFromNpyFile函数不能适用npz格式的文件 #3642

Open
chizhiwei opened this issue Apr 18, 2024 · 0 comments

Comments

@chizhiwei
Copy link

从741行开始,如下

    try:
        if Path(filename).suffix in ['.npy', '.npz']:
            img = np.load(filename)    # 问题:当读取的文件为npz格式时,包含了多项array数据,需要根据关键字进行指定
        else:
            if self.file_client_args is not None:
                file_client = fileio.FileClient.infer_client(
                    self.file_client_args, filename)
                img_bytes = file_client.get(filename)
            else:
                img_bytes = fileio.get(
                    filename, backend_args=self.backend_args)
            img = mmcv.imfrombytes(
                img_bytes,
                flag=self.color_type,
                backend=self.imdecode_backend)
    except Exception as e:
        if self.ignore_empty:
            return None
        else:
            raise e

    # in some cases, images are not read successfully, the img would be
    # `None`, refer to https://github.com/open-mmlab/mmpretrain/issues/1427
    assert img is not None, f'failed to load image: {filename}'
    if self.to_float32:
        img = img.astype(np.float32)

    results['img'] = img
    results['img_shape'] = img.shape[:2]   # 在这里会报出错误,因为此时的img变量是一个包含多项array的npz数据
    results['ori_shape'] = img.shape[:2]
    return results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant