Skip to content

Commit

Permalink
Fix albu versions >= 1.4.11 (open-mmlab#11770)
Browse files Browse the repository at this point in the history
This commit introduces very basic version parsing for albumentations in order to know whether the strict parameter for albu.Compose is supported, and passes strict=False if it is. If it isn't supported, fall back to not passing the strict parameter, which only works on albu <= 1.4.6.
  • Loading branch information
Theelx authored Jul 22, 2024
1 parent cfd5d3a commit 79e35f8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mmdet/datasets/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@
try:
import albumentations
from albumentations import Compose
# This assumes albumentations' versions are just ints separated by
# periods, e.g. 1.4.11, allowing us to avoid a new dependency.
ALBU_VERSION = list(map(int, albumentations.__version__.split(".")))[:3]
except ImportError:
albumentations = None
Compose = None
ALBU_VERSION = None

Number = Union[int, float]

Expand Down Expand Up @@ -1627,8 +1631,11 @@ def __init__(self,

self.bbox_params = (
self.albu_builder(bbox_params) if bbox_params else None)
self.aug = Compose([self.albu_builder(t) for t in self.transforms],
bbox_params=self.bbox_params)
if ALBU_VERSION is not None and ALBU_VERSION >= (1, 4, 11):
self.aug = Compose([self.albu_builder(t) for t in self.transforms],
bbox_params=self.bbox_params, strict=False)
else:
self.aug = Compose([self.albu_builder(t) for t in self.transforms])

if not keymap:
self.keymap_to_albu = {
Expand Down

0 comments on commit 79e35f8

Please sign in to comment.