-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Non color images #1976
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
Non color images #1976
Conversation
On branch non-color-images Changes to be committed: modified: mmdet/datasets/pipelines/loading.py
Add 'color_type' parameter to LoadImageFromFile class Change __repr__ method accordingly Since non-color images maybe two dimensional expand image dimensions if necessary in DefaultFormatBundle and ImageToTensor classes Changes to be committed: modified: mmdet/datasets/pipelines/formating.py modified: mmdet/datasets/pipelines/loading.py
|
||
def __call__(self, results): | ||
if results['img_prefix'] is not None: | ||
filename = osp.join(results['img_prefix'], | ||
results['img_info']['filename']) | ||
else: | ||
filename = results['img_info']['filename'] | ||
img = mmcv.imread(filename) | ||
img = mmcv.imread(filename, self.color_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest expanding dims here to simplify the formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this will not work, because opencv will drop a dummy dimension. For example this code
img = np.random.rand(320,320,1)
cv2.resize(img, (300,300)).shape
will output (300,300)
Now I realize that more changes are necessary to accommodate grayscale (single-channel) images. In particular changes should be introduced into at least some of the transforms (I added proposed changes to RandomCrop). In addition the way I handle it, 'image_shape' and 'pad_shape' will be 2-tuples and corresponding changes might be necessary (I made some for 'pad_shape'). Clearly one can convert grayscale images to 3 channel images by simply replicating the image, but I think it would be useful to support single channel images directly. I will be happy to do it if there is an interest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Did you tried training any models with grayscale images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I trained small RetinaNet (retinanet_r50_fpn_1x). It works fine, but I used only Resize, RandomCrop, RandomFlip, Pad and Normalize transforms. I will need to check how other transforms behave with grayscale images.
Changes to be committed: modified: mmdet/datasets/pipelines/transforms.py
This addreses problems with single channel images for which the shape is tuple with 2 values Changes to be committed: modified: mmdet/models/anchor_heads/anchor_head.py modified: mmdet/models/anchor_heads/guided_anchor_head.py modified: mmdet/models/anchor_heads/reppoints_head.py
* origin/viame/master: (28 commits) Fix FPN upscale Extra compiler args VIAME-specific build parameters Bump version to 1.0.0 (open-mmlab#2029) Fix the incompatibility of the latest numpy and pycocotools (open-mmlab#2024) format configs with yapf (open-mmlab#2023) options for FCNMaskHead during testtime (open-mmlab#2013) Enhance AssignResult and SamplingResult (open-mmlab#1995) Fix typo activatation -> activation (open-mmlab#2007) Reorganize requirements, make albumentations optional (open-mmlab#1969) Encapsulate DCN into a ConvModule & Conv_layers (open-mmlab#1894) Code for Paper "Bridging the Gap Between Anchor-based and Anchor-free… (open-mmlab#1872) Non color images (open-mmlab#1976) Fix albu mask format bug (open-mmlab#1818) Fix CI by limiting the version of torchvision (open-mmlab#2005) Add ability to overwite existing module in Registry (open-mmlab#1982) bug for distributed training (open-mmlab#1985) Update Libra RetinaNet config with the latest code (open-mmlab#1975) Fix issue in refine_bboxes and add doctest (open-mmlab#1962) add link to official repo (open-mmlab#1971) ...
* First Draft On branch non-color-images Changes to be committed: modified: mmdet/datasets/pipelines/loading.py * Add option to load non color images Add 'color_type' parameter to LoadImageFromFile class Change __repr__ method accordingly Since non-color images maybe two dimensional expand image dimensions if necessary in DefaultFormatBundle and ImageToTensor classes Changes to be committed: modified: mmdet/datasets/pipelines/formating.py modified: mmdet/datasets/pipelines/loading.py * Fix RandomCrop to work with grayscale images Changes to be committed: modified: mmdet/datasets/pipelines/transforms.py * Modify retrieving w, h of padded image in anchor heads This addreses problems with single channel images for which the shape is tuple with 2 values Changes to be committed: modified: mmdet/models/anchor_heads/anchor_head.py modified: mmdet/models/anchor_heads/guided_anchor_head.py modified: mmdet/models/anchor_heads/reppoints_head.py
* First Draft On branch non-color-images Changes to be committed: modified: mmdet/datasets/pipelines/loading.py * Add option to load non color images Add 'color_type' parameter to LoadImageFromFile class Change __repr__ method accordingly Since non-color images maybe two dimensional expand image dimensions if necessary in DefaultFormatBundle and ImageToTensor classes Changes to be committed: modified: mmdet/datasets/pipelines/formating.py modified: mmdet/datasets/pipelines/loading.py * Fix RandomCrop to work with grayscale images Changes to be committed: modified: mmdet/datasets/pipelines/transforms.py * Modify retrieving w, h of padded image in anchor heads This addreses problems with single channel images for which the shape is tuple with 2 values Changes to be committed: modified: mmdet/models/anchor_heads/anchor_head.py modified: mmdet/models/anchor_heads/guided_anchor_head.py modified: mmdet/models/anchor_heads/reppoints_head.py
* First Draft On branch non-color-images Changes to be committed: modified: mmdet/datasets/pipelines/loading.py * Add option to load non color images Add 'color_type' parameter to LoadImageFromFile class Change __repr__ method accordingly Since non-color images maybe two dimensional expand image dimensions if necessary in DefaultFormatBundle and ImageToTensor classes Changes to be committed: modified: mmdet/datasets/pipelines/formating.py modified: mmdet/datasets/pipelines/loading.py * Fix RandomCrop to work with grayscale images Changes to be committed: modified: mmdet/datasets/pipelines/transforms.py * Modify retrieving w, h of padded image in anchor heads This addreses problems with single channel images for which the shape is tuple with 2 values Changes to be committed: modified: mmdet/models/anchor_heads/anchor_head.py modified: mmdet/models/anchor_heads/guided_anchor_head.py modified: mmdet/models/anchor_heads/reppoints_head.py
Hi,
Thank you for great project. This pull request adds ability to load images that are not 3 channel color images. Since opencv treats 'grayscale' images as 2D matrices an empty third dimension have to be added before converting them to tensors.