pythontensorflowkerasgoogle-colaboratoryalbumentations

Albumentations on Google Colab : module 'albumentations' has no attribute 'SomeOf'


Originally, I posted this in Albumentation's Github issues listing

I used Albumentations on my local machine to do data augmentation using the latest version 1.1.0 through a regular pip install into my local virtual environment. Everything is working fine in the lcoal machine. When I upload my backend code to Google Colaboratory. Up until now, I can't find the SomeOf attribute. It says : module 'albumentations' has no attribute 'SomeOf'.

I upgraded my OpenCV to fit the requirement, just in case! I performed some upgrades, force reinstalls and compiled from source installations on albumentations. The pip is saying that the installed version is truly 1.1.0 but the print(albumentations.__version__) is giving me version 0.1.12 instead.

To Reproduce

Steps to reproduce the behavior: on Google Colab Pro

  1. !pip install -q -U albumentations (tried other methods as mentioned above)
  2. !echo "$(pip freeze | grep albumentations) is successfully installed"
  3. import albumentations as A
  4. print(A.version)

Expected behavior

To have version 1.1.0 from the print at step 5 instead of 0.1.12

Additional context

Here's the transform composition that I've defined in my backend code.

TRANSFORM = A.Compose(
        [
            # Geometric transforms 30%
            A.OneOf(
                [
                    A.HorizontalFlip(),
                    A.Rotate(limit=90+45, border_mode=BORDER_CONSTANT),
                ], p=0.3
            ),
            # Color related transforms 60%
            A.SomeOf(
                [
                    A.RandomBrightness(limit=0.5),
                    A.HueSaturationValue(
                        hue_shift_limit=0,
                        sat_shift_limit=35,
                        val_shift_limit=0
                    ),
                    A.RandomBrightnessContrast(
                        brightness_limit=0.4,
                        contrast_limit=0.25,
                        p=0.2
                    ),
                    # Weather related transforms
                    A.OneOf(
                            [
                                A.RandomRain(p=0.05),
                                A.RandomShadow(p=0.1),
                                A.RandomSunFlare(p=0.1)
                            ], p=0.5
                        ),
                ], 2, p=0.6
            ),
            # Camera related transforms 10%
            A.SomeOf(
                [
                    # Noise related transforms
                    A.OneOf(
                        [
                            A.GaussNoise(),
                            A.MultiplicativeNoise()
                        ], p=0.5
                    ),
                    # Blur related transforms
                    A.OneOf(
                        [
                            A.Blur(blur_limit=3, p=0.25),
                            A.MedianBlur(blur_limit=3, p=0.25),
                            A.GaussianBlur(p=0.25),
                            A.MotionBlur(p=0.25),
                        ], p=0.5
                    ),
                ], 2, p=0.1
            ),
        ]
    )

I stumbled on this notebook by @benihime91 tensorflow-example.ipynb and issues are also appearing in the same context as mine appart that the error is related to OpenCV dependencies that I already upgraded to the latest version.


Solution

  • I've tried changing the version installation and it worked

    !pip install -q opencv-python==4.5.5.64

    !pip install -q --force-reinstall albumentations==1.0.3

    It is also recommended to update Pillow to a recent version.