Skip to content
Advertisement

Tag: deep-learning

What’s the difference between torch.stack() and torch.cat() functions?

OpenAI’s REINFORCE and actor-critic example for reinforcement learning has the following code: REINFORCE: actor-critic: One is using torch.cat, the other uses torch.stack, for similar use cases. As far as my understanding goes, the doc doesn’t give any clear distinction between them. I would be happy to know the differences between the functions. Answer stack Concatenates sequence of tensors along a

Why do we need to call zero_grad() in PyTorch?

Why does zero_grad() need to be called during training? Answer In PyTorch, for every mini-batch during the training phase, we typically want to explicitly set the gradients to zero before starting to do backpropragation (i.e., updating the Weights and biases) because PyTorch accumulates the gradients on subsequent backward passes. This accumulating behaviour is convenient while training RNNs or when we

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

Keras confusion about number of layers

I’m a bit confused about the number of layers that are used in Keras models. The documentation is rather opaque on the matter. According to Jason Brownlee the first layer technically consists of two layers, the input layer, specified by input_dim and a hidden layer. See the first questions on his blog. In all of the Keras documentation the first

Advertisement