support 'numpy' and more general data conversions in 'loading' module
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
numpyimdecode_backend, change boolean parameterto_float32to string parameterto_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
- [x] Pre-commit or other linting tools are used to fix the potential lint issues.
- [x] The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
- [x] If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
- [x] The documentation has been modified accordingly, like docstring or example tutorials.
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.
Hi, thanks for your warm-hearted PR!
We would review it ASAP!
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.
@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.
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