What's with the numpy hostility?

I like to do all my data transforms in numpy. E.g. random crops of very large images/arrays is very simple and fast when using the mmap mode of np.load (no need to load entire array into memory). Who honestly likes PIL?? And anyway it’s useless outside of 2D.

Also not being able to multiply numpy types (e.g. np.log(2)) with torch tensors is a nuisance… yes, I can import math but who actually uses that instead of numpy??

There’s just so much good stuff in numpy and scipy!

I don’t understand your first point. What prevents you from using NumPy to do your data transformations? You can convert between PyTorch tensors and NumPy arrays without having to copy the data using Tensor.numpy() and torch.from_numpy.

We plan to improve operations that mix PyTorch tensors and NumPy types (especially scalars), but it’s probably a month or two away.

1 Like

As colesbury said, you can do it. You can build your own data loader using the torch.utils.data.Dataset class. You can change the getitem and add your own data transformation using Numpy or any other library. You have more information of how to do it here:

1 Like

Sure, and that’s what I’ve been doing (apologies for being unclear). It’s just a shame that the built in transforms are all PIL (but I guess that’s just torchvision, not core pytorch?).

Anyway, that was just my late night ranting… I love PyTorch! :slight_smile: