Different Results using Transforms and Albumentations

Hello everyone!

I noticed I was getting different results during training when using transforms once and albumentations on the other.

So I decided to remove all kind of transformations I’m doing on the images, and just resize and normalize using Albumentations once and Transforms as the other print the tensors.

Surpsingly they were different, however I do not understand why I’m using same interpolation and normalization values?

For example here is one row from the first channel,

  • Albumentations= [-1.4843, -1.4843, -1.5357, -1.5528, -1.5357, -1.4672, -1.5357, -1.5014,
    -1.4843, -1.5185]

  • torchvision transforms: [-1.4843, -1.5014, -1.5185, -1.5528, -1.5357, -1.4843, -1.5185, -1.5014,
    -1.4843, -1.5185]

EDIT: So I tested with resizing only, with same interpolation for each, and it appears that image and mask tensors using Albumentations are not exactly the same as when using Transforms. Secondly, I removed resizing and kept normalization, since the masks are not normalized, they are the same using both methods, but the images are still slightly off using both methods. Could the difference be because transforms uses PIL and Albumentations uses cv2?

Here is the code I used to test.

import albumentations as A
import cv2
from PIL import Image
import numpy as np
from torchvision import transforms

img_path = "./data/oxford-iiit-pet/images/Abyssinian_2.jpg"
seg_path = "./data/oxford-iiit-pet/annotations/trimaps/Abyssinian_2.png"

tf = transforms.ToTensor()

O_img = Image.open(img_path).convert("RGB")

temp_img = np.array(O_img)
album_t = A.Compose([A.Resize(256, 256,interpolation=cv2.INTER_LINEAR,always_apply=True),
                     A.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225],always_apply=True)])
preprocess_A = album_t(image=temp_img)
Album_img = preprocess_A["image"]
A_img = tf(Album_img )

img_transform = transforms.Compose([ transforms.Resize((256, 256)),
                                    transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                                            std=[0.229, 0.224, 0.225])])

tf_img = img_transform(O_img)