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.
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
Fix proposition
Add
.contiguous()
call in wrappers to avoid this situation.