juliendenize / torchaug

Library to perform efficient vision data augmentations for CPU/GPU per-sample/batched data.
https://torchaug.readthedocs.io/en/latest/
Other
24 stars 2 forks source link

Inplace error after expand #10

Closed juliendenize closed 1 year ago

juliendenize commented 1 year ago

Description

When an operation is performed with an expand and is followed by an in-place operation it raises an error. This raises an error in BatchWrapper if no copies are made (for example when the probability of making the first operation is 1).

Minimal bug reproduction

import torch
from torchaug.batch_transforms import BatchImageWrapper, BatchRandomGrayScale
from torchaug.transforms import Normalize

transform = BatchImageWrapper([
    BatchRandomGrayScale(1.), # Call expand
    Normalize(225, 225)
])

transform(torch.randn(4, 3, 224, 224))

>>> RuntimeError: unsupported operation: more than one element of the written-to tensor refers to a single memory location. Please clone() the tensor before performing the operation.

Fix proposition

Add .contiguous() call in wrappers to avoid this situation.

juliendenize commented 1 year ago

Fixed by d9ad37b64405fa54cf6e8e19809417256f029ebb.