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

[Feature] Add Rgb2Gray transform #227

Merged
merged 9 commits into from
Nov 9, 2020
Merged

[Feature] Add Rgb2Gray transform #227

merged 9 commits into from
Nov 9, 2020

Conversation

yamengxi
Copy link
Collaborator

@yamengxi yamengxi commented Nov 4, 2020

No description provided.

@codecov
Copy link

codecov bot commented Nov 4, 2020

Codecov Report

Merging #227 (728f075) into master (3d18775) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
+ Coverage   84.26%   84.35%   +0.09%     
==========================================
  Files          90       90              
  Lines        4315     4340      +25     
  Branches      684      687       +3     
==========================================
+ Hits         3636     3661      +25     
  Misses        537      537              
  Partials      142      142              
Flag Coverage Δ
unittests 84.35% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/datasets/pipelines/transforms.py 96.61% <100.00%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d18775...cc46163. Read the comment docs.

Comment on lines 211 to 212
# print(results)
print(results, results['img'].shape)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Delete these.


This transform calculate the weighted mean of input image channels with
``weights`` and then expand the channels to ``out_channels``. When
``out_channels`` equals 0, the number of output channels is the same as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use None instead of 0.

@@ -463,6 +465,61 @@ def __repr__(self):
return self.__class__.__name__ + f'(crop_size={self.crop_size})'


@PIPELINES.register_module()
class Rgb2Gray(object):
Copy link
Collaborator

Choose a reason for hiding this comment

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

RGB2Gray

Default: (0.299, 0.587, 0.114).
"""

def __init__(self, out_channels, weights=(0.299, 0.587, 0.114)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why using weighted sum instead of direct mmcv.rgb2gray.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By this method, we can use the weights defined by us instead of fixed weights.

assert len(img.shape) == 3
assert img.shape[2] == len(self.weights)
weights = np.array(self.weights).reshape((1, 1, -1))
img = (img * weights).sum(2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may use keep_dim=True. In this way, we don't need to expand dim.

@hellock
Copy link
Member

hellock commented Nov 9, 2020

Task linked: CU-fjrgpn Data preprocessing

@xvjiarui xvjiarui merged commit 7c68bca into open-mmlab:master Nov 9, 2020
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* add transformer Rgb2Gray

* restore

* fix self.weights

* restore

* fix code

* restore

* fix syntax error

* restore
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this pull request Dec 3, 2023
wipe out the extra gpu memony cost by set the default map_location as 'cpu'
sibozhang pushed a commit to sibozhang/mmsegmentation that referenced this pull request Mar 22, 2024
* init commit

* fix download annotations

* parse hvu tags

* add downloading & trimming scripts

* add file list generation

* finish hvu datatools

* resolve comments

* init commit

* fix download annotations

* parse hvu tags

* add downloading & trimming scripts

* add file list generation

* finish hvu datatools

* resolve comments

* update changelog

* Update data_preparation.md

Co-authored-by: Jintao Lin <528557675@qq.com>
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.

3 participants