Introducing the TorchSample package for comprehensive data transforms and sampling

(Nick) #1

Hi all,

As a new pytorch user, I found the data sampling and transforms code lacking for my personal use-case. It’s understandable, since the core developers are busy working on the more important stuff. Still, I wanted to quickly build up the available sampling code to the same level as tensorflow, keras, etc and I think I’ve accomplished that with the torchsample package.

The torchsample package is a 3rd-party library that includes code for comprehensive sampling from both in-memory and out-of-memory data, and includes a ton of useful augmentation transforms that apply directly on arbitrary torch tensors (rather than just PIL images).

It also has great support for situations where both the input and target tensors are images (e.g. segmentation datasets). It also supports arbitrary data types. It supersedes the currently available sampling code in the main torchvision/torch codebase.

Take a look here:

I’ve also wrote a fairly long tutorial showing how it works for a ton of common scenarios which can be found in the tutorials folder of the above repository.

It’s my hope that this will kick-start the community-driven development of the sampling code in the main torch and torchvision packages, and serve as reliable and flexible sampling code in the meantime.

NOTE: This package is in no way endorsed by, affiliated with, or otherwise associated with the official Pytorch ecosystem or team.


This is good stuff. I’m going to start focusing more on torchvision while sam and paszke focus on core, and will use parts of your package as inspiration.

(Nick) #3

Cool! I think there’s a huge need for this stuff… and no framework has quite converged on the optimal solution yet (see tensorflow is planning to clean up their disaster of an input pipeline now: Pytorch has a good opportunity to improve on everyone else’s mistakes from the start…

Another benefit of a common api for sampling is that you would remove the need to create a new data.Dataset subclass for each public dataset and instead would just need to download and pre-process the data… Would greatly increase your productivity in that area and allow for easily augmenting those datasets.

PS: the ImageFolder class seems kinda on an island in torchvision with the rest of the relevant sampling code (e.g. TensorDataset) in the main repo. I love the idea of torchvision for loading public datasets and pre-trained models… but maybe it would make more sense to separate the general purpose sampling code into a third torchvision folder (e.g. models, datasets, sampling) or develop the sampling solely in the main repo… just my very humble opinion of course.

(S) #4

Could you please give me some details on how to install this package? I have conda installed and have created an virtualenv for it. Thanks!