Model Pipeline - Albumentations integration
This pipeline shows how Albumentations helps to change images before training a PyTorch model. It makes images look different each time to help the model learn better.
This pipeline shows how Albumentations helps to change images before training a PyTorch model. It makes images look different each time to help the model learn better.
Loss
1.2 |*****
0.9 |****
0.7 |***
0.55|**
0.45|*
+------------
1 2 3 4 5 Epochs| Epoch | Loss ↓ | Accuracy ↑ | Observation |
|---|---|---|---|
| 1 | 1.2 | 0.45 | Model starts learning with random weights |
| 2 | 0.9 | 0.60 | Loss decreases and accuracy improves due to augmentation |
| 3 | 0.7 | 0.72 | Model learns better features from augmented images |
| 4 | 0.55 | 0.80 | Training stabilizes with good accuracy |
| 5 | 0.45 | 0.85 | Model converges with low loss and high accuracy |
Compose to combine multiple transformations into one pipeline.A.Compose is the correct method; others like Sequential, Transforms, Pipeline do not exist in Albumentations.import albumentations as A
from albumentations.pytorch import ToTensorV2
transform = A.Compose([
A.Resize(64, 64),
A.HorizontalFlip(p=1.0),
ToTensorV2()
])
image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
transformed = transform(image=image)
tensor = transformed['image']
print(tensor.shape)transform = A.Compose([
A.Resize(128, 128),
A.RandomBrightnessContrast(),
ToTensorV2
])ToTensorV2() to create the transform instance.Pass the test and this pattern moves unknown