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

support 'numpy' and more general data conversions in 'loading' module #1252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Marxlp
Copy link

@Marxlp Marxlp commented Jan 27, 2022

Motivation

The data loaded by LoadImageFromFile and LoadAnnotations may be npy file, besides the file format supported by cv2, Pillow etc. And data range may vary. For more details, see #1240

Modification

  • mmseg/datasets/pipelines/loading.py: add numpy imdecode_backend, change boolean parameter to_float32 to string parameter to_dtype
  • tests/test_data/test_loading.py: Adapt testing script.

BC-breaking

The code setting to_float32 will be affected.

You should change

transform = LoadImageFromFile(to_float32=True)

to

transform = LoadImageFromFile(to_dtype='float32')

For positional format, due the parameter was defined as the last parameter, change

transform = LoadImageFromFile(True)

to

transform = LoadImageFromFile(to_dtype='float32')

Use cases

LoadImageFromFile

results = dict(
            img_prefix = '/path/to/dataset', img_info=dict(filename='image.npy'))
transform = LoadImageFromFile(imdecode_backend='numpy', to_dtype='float32')
results = transform(results)

LoadAnnotations

results = dict(
            seg_prefix='/path/to/dataset',
            ann_info=dict(seg_map='image.npy'),
            seg_fields=[])
transform = LoadAnnotations(imdecode_backend='numpy', to_dtype='int64')
results = transform(results)

Checklist

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  • The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2022

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


liuping seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@MengzhangLI
Copy link
Contributor

Hi, thanks for your warm-hearted PR!

We would review it ASAP!

@JunMa11
Copy link

JunMa11 commented Jan 28, 2022

Hi @Marxlp ,

Thanks for the great contribution.

Does the numpy dataloader support the npy file that contains multiple images?
E.g., the shape is (1000, 256,256,3) where 1000 is the number of images.

@Marxlp
Copy link
Author

Marxlp commented Jan 28, 2022

@JunMa11
According to docstring, LoadImageFromFile loads an image from file., therefore, it will treat the npy file with shape (1000, 256, 256, 3) as one image file directly without considering whether the first dimension indicates the batch size. I think it is reasonable, as it's consistent with other file types.

Copy link
Collaborator

@MeowZheng MeowZheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to add a new backend in imfrombytes of MMCV
https://github.com/open-mmlab/mmcv/blob/7df4ebedb34aa84eee1514a8ca57bf6681f25740/mmcv/image/io.py#L210-L232

As image file might not be from dist, we load bytes and decode them using imfrombytes, but np.load might only load file object.

@OpenMMLab-Assistant003
Copy link

Hi @Marxlp!We are grateful for your efforts in helping improve this open-source project during your personal time.
Welcome to join OpenMMLab Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA
If you have a WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)
Thank you again for your contribution❤ @Marxlp

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

Successfully merging this pull request may close these issues.

None yet

6 participants