Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mmdet/datasets/pipelines/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,14 @@ def __call__(self, results):
else:
results['masks'] = [mask for mask in results['masks'].masks]

# Convert to RGB since Albumentations works with RGB images
results['image'] = cv2.cvtColor(results['image'], cv2.COLOR_BGR2RGB)
Copy link
Collaborator

@BIGWangYuDong BIGWangYuDong Mar 18, 2023

Choose a reason for hiding this comment

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

This fixing may have some potential errors.

As show in Loading Image:

The image may be rgb, and this option may convert the image to BGR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add a channel_order parameter as in the loading init?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

sorry for the late reply, we need to discuss it. Kindly ping @RangiLyu and @hhaAndroid have a look

Copy link
Contributor Author

Choose a reason for hiding this comment

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


results = self.aug(**results)

# Convert back to BGR
results['image'] = cv2.cvtColor(results['image'], cv2.COLOR_RGB2BGR)

if 'bboxes' in results:
if isinstance(results['bboxes'], list):
results['bboxes'] = np.array(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_data/test_pipelines/test_transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,42 @@ def test_albu_transform():
assert results['img'].dtype == np.float32


def test_albu_channel_order():
results = dict(
img_prefix=osp.join(osp.dirname(__file__), '../../../data'),
img_info=dict(filename='color.jpg'))

# Define simple pipeline
load = dict(type='LoadImageFromFile')
load = build_from_cfg(load, PIPELINES)

# Transform is modifying B channel
albu_transform = dict(
type='Albu',
transforms=[
dict(
type='RGBShift',
r_shift_limit=0,
g_shift_limit=0,
b_shift_limit=200,
p=1)
])
albu_transform = build_from_cfg(albu_transform, PIPELINES)

# Execute transforms
results_load = load(results)
results_albu = albu_transform(results_load)

# assert only Green and Red channel are not modified
np.testing.assert_array_equal(results_albu['img'][..., 1:],
results_load['img'][..., 1:])

# assert Blue channel is modified
with pytest.raises(AssertionError):
np.testing.assert_array_equal(results_albu['img'][..., 0],
results_load['img'][..., 0])


def test_random_center_crop_pad():
# test assertion for invalid crop_size while test_mode=False
with pytest.raises(AssertionError):
Expand Down