Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

in place operations only breaks FiveCrop. #17

Open
xvdp opened this issue Mar 28, 2019 · 1 comment
Open

in place operations only breaks FiveCrop. #17

xvdp opened this issue Mar 28, 2019 · 1 comment

Comments

@xvdp
Copy link

xvdp commented Mar 28, 2019

Hi, I was writing some augmentation transforms and I noticed that all operations are done in place.
I forked and added a .copy() method for my use, but I wonder if this is the correct way of doing it.
I like accimage quite as it is 4 to 6 times faster in my profiling than either going thru opencv or PIL to tensor.
I like, as well, that accimage operates in place by default, but as it stands, accimage breaks transformations that rely on data copies, such as FiveCrop. PIL default behaviour always returns a copy.
On my augmentation library Im changing the FiveCrop to bypass accimage by running Image.copy() if accimage.

img = ...
import PIL
import accimage
import torchvision.transforms as ttrans
fcrop = ttrans.Compose([ttrans.FiveCrop(100),
         ttrans.Lambda(lambda crops: torch.stack([ttrans.ToTensor()(crop) for crop in crops]))])
aim = PIL.Image.open(img)
f = fcrop(aim)
# OK

fcrop = ttrans.Compose([ttrans.FiveCrop(100),
         ttrans.Lambda(lambda crops: torch.stack([ttrans.ToTensor()(crop) for crop in crops]))])
aim = accimage.Image(img)
f = fcrop(aim)
# Fails 

If you are interested you can look at my forked solution. BUT it is a half way solution since it requires a fix to torvision.transforms.

@xvdp
Copy link
Author

xvdp commented Mar 28, 2019

Writing the transform with the .copy() op I realized that it makes no sense to have torchvision transformations see accimage and PIL as the same when their behaviour is different, so I added a kwarg, in_place=[False] so that default behaviour is the same in PIL and accimage, but accimage can be run leaner with the in_place key on. This fixes the disparity whilst keeping the ability to go lean.
If you want, I do a pull request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant