Skip to content

Tag: pytorch

Is there an efficient way to create a random bit mask in Pytorch?

I want to have a random bit mask that has some specified percent of 0s. The function I devised is: To illustrate: The main issue I have with this method is it requires the rate to divide the shape. I want a function that accepts an arbitrary decimal and gives approximately rate percent of 0s in the bitmask. F…

Pytorch softmax: What dimension to use?

The function torch.nn.functional.softmax takes two parameters: input and dim. According to its documentation, the softmax operation is applied to all slices of input along the specified dim, and will rescale them so that the elements lie in the range (0, 1) and sum to 1. Let input be: Suppose I want the follo…

What does .contiguous() do in PyTorch?

What does x.contiguous() do for a tensor x? Answer There are a few operations on Tensors in PyTorch that do not change the contents of a tensor, but change the way the data is organized. These operations include: narrow(), view(), expand() and transpose() For example: when you call transpose(), PyTorch doesn&…

NumPy/PyTorch extract subsets of images

In Numpy, given a stack of large images A of size(N,hl,wl), and coordinates x of size(N) and y of size(N) I want to get smaller images of size (N,16,16) In a for loop it would look like this: But can I do this just with indexing? Bonus question: Will this indexing also work in pytorch? If not how can I