Skip to main content
Filter by
Sorted by
Tagged with
640 votes
21 answers
1.5m views

How do I check if PyTorch is using the GPU? The nvidia-smi command can detect GPU activity, but I want to check it directly from inside a Python script.
vvvvv's user avatar
  • 32.9k
385 votes
9 answers
320k views

Why does zero_grad() need to be called during training? | zero_grad(self) | Sets gradients of all model parameters to zero.
user1424739's user avatar
  • 14.1k
352 votes
9 answers
281k views

What does view() do to the tensor x? What do negative values mean? x = x.view(-1, 16 * 5 * 5)
Wasi Ahmad's user avatar
  • 38.1k
280 votes
11 answers
524k views

How do I initialize weights and biases of a network (via e.g. He or Xavier initialization)?
Fábio Perez's user avatar
  • 26.5k
252 votes
8 answers
175k views

What does x.contiguous() do for a tensor x?
MBT's user avatar
  • 24.6k
211 votes
12 answers
192k views

How do I count the total number of parameters in a PyTorch model? Something similar to model.count_params() in Keras.
Fábio Perez's user avatar
  • 26.5k
199 votes
8 answers
376k views

This: device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model.to(device) for data in dataloader: inputs, labels = data outputs = model(inputs) Gives ...
Guillermina's user avatar
  • 3,717
193 votes
24 answers
814k views

I think it's a pretty common message for PyTorch users with low GPU memory: RuntimeError: CUDA out of memory. Tried to allocate X MiB (GPU X; X GiB total capacity; X GiB already allocated; X MiB free; ...
voilalex's user avatar
  • 2,695
188 votes
8 answers
611k views

I have a pytorch Tensor of shape [4, 3, 966, 1296]. I want to convert it to numpy array using the following code: imgs = imgs.numpy()[:, ::-1, :, :] How does that code work?
DukeLover's user avatar
  • 2,497
143 votes
7 answers
156k views

The PyTorch documentation says: Returns a new tensor with a dimension of size one inserted at the specified position. [...] >>> x = torch.tensor([1, 2, 3, 4]) >>> torch.unsqueeze(x, ...
user avatar
142 votes
8 answers
230k views

Consider: import torch import torch.nn as nn import torch.optim as optim import torch.utils.data as data import torchvision.models as models import torchvision.datasets as dset import torchvision....
raaj's user avatar
  • 3,479
137 votes
3 answers
191k views

How does torch.nn.Parameter() work?
Vineet Pandey's user avatar
132 votes
9 answers
280k views

How do I add L1/L2 regularization in PyTorch without manually computing it?
Wasi Ahmad's user avatar
  • 38.1k
126 votes
9 answers
278k views

I'm trying to train a classifier via PyTorch. However, I am experiencing problems with training when I feed the model with training data. I get this error on y_pred = model(X_trainTensor): ...
Shawn Zhang's user avatar
  • 1,779
121 votes
5 answers
201k views

What is the correct way to perform gradient clipping in pytorch? I have an exploding gradients problem.
Gulzar's user avatar
  • 28.7k
118 votes
1 answer
147k views

If num_workers is 2, Does that mean that it will put 2 batches in the RAM and send 1 of them to the GPU or Does it put 3 batches in the RAM then sends 1 of them to the GPU? What does actually happen ...
Bassel's user avatar
  • 1,763
115 votes
3 answers
226k views

How do I convert a PyTorch Tensor into a python list? I want to convert a tensor of size [1, 2048, 1, 1] into a list of 2048 elements. My tensor has floating point values. Is there a solution which ...
Tom Hale's user avatar
  • 48.1k
115 votes
11 answers
386k views

I saved a checkpoint while training on gpu. After reloading the checkpoint and continue training I get the following error: Traceback (most recent call last): File "main.py", line 140, in &...
Ido Do's user avatar
  • 1,151
105 votes
3 answers
134k views

I have a huge list of numpy arrays, where each array represents an image and I want to load it using torch.utils.data.Dataloader object. But the documentation of torch.utils.data.Dataloader mentions ...
deepayan das's user avatar
  • 1,677
102 votes
16 answers
481k views

I figured out this is a popular question, but still I couldn't find a solution for that. I'm trying to run a simple repository here which uses PyTorch. Although I just upgraded my PyTorch to the ...
angel_30's user avatar
  • 5,697
101 votes
26 answers
851k views

I successfully installed pytorch via conda: conda install pytorch-cpu torchvision-cpu -c pytorch I also successfully installed pytorch via pip: pip3 install https://download.pytorch.org/whl/cpu/torch-...
RedCrayon's user avatar
  • 1,103
100 votes
7 answers
193k views

I use this command to use a GPU. device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") But, I want to use two GPUs in jupyter, like this: device = torch.device(&...
ML Xu's user avatar
  • 1,141
96 votes
2 answers
125k views

Is it possible in PyTorch to change the learning rate of the optimizer in the middle of training dynamically (I don't want to define a learning rate schedule beforehand)? So let's say I have an ...
patapouf_ai's user avatar
  • 18.9k
94 votes
18 answers
377k views

I am trying to initialize a tensor on Google Colab with GPU enabled. device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') t = torch.tensor([1,2], device=device) But I am getting ...
3nomis's user avatar
  • 1,652
89 votes
9 answers
203k views

How do I display a PyTorch Tensor of shape (3, 224, 224) representing a 224x224 RGB image? Using plt.imshow(image) gives the error: TypeError: Invalid dimensions for image data
Tom Hale's user avatar
  • 48.1k

1
2 3 4 5
480