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

Fix Albu Transform in transforms.py #3770

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions mmseg/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2424,31 +2424,38 @@ def transform(self, results):
# dict to albumentations format
results = self.mapper(results, self.keymap_to_albu)

albumentations_results = {
k: results.pop(k) for k in ['image', 'mask'] if k in results
}

# Convert to RGB since Albumentations works with RGB images
if self.bgr_to_rgb:
results['image'] = cv2.cvtColor(results['image'],
albumentations_results['image'] = cv2.cvtColor(albumentations_results['image'],
cv2.COLOR_BGR2RGB)
if self.additional_targets:
for key, value in self.additional_targets.items():
if value == 'image':
results[key] = cv2.cvtColor(results[key],
albumentations_results[key] = cv2.cvtColor(albumentations_results[key],
cv2.COLOR_BGR2RGB)

# Apply Transform
results = self.aug(**results)
albumentations_results = self.aug(**albumentations_results)

# Convert back to BGR
if self.bgr_to_rgb:
results['image'] = cv2.cvtColor(results['image'],
albumentations_results['image'] = cv2.cvtColor(albumentations_results['image'],
cv2.COLOR_RGB2BGR)
if self.additional_targets:
for key, value in self.additional_targets.items():
if value == 'image':
results[key] = cv2.cvtColor(results['image2'],
albumentations_results[key] = cv2.cvtColor(albumentations_results['image2'],
cv2.COLOR_RGB2BGR)

# back to the original format
results = self.mapper(results, self.keymap_back)
albumentations_results = self.mapper(albumentations_results, self.keymap_back)

# Update corresponding keys in the original `results`
results.update(albumentations_results)

# update final shape
if self.update_pad_shape:
Expand Down