Skip to content

Knowledge Transfer

  • PyTorch
  • Keras
  • Flutter
  • TensorFlow
  • Pandas
  • Android
  • Contact Us
June 26, 2022

PyTorch Confusion Matrix for multi-class image classification

PyTorchadmin

Confusion matrix lets us see not only where the model was wrong, but also how it was wrong. That is, we can look at patterns of misclassification. For example, our model had an easy time differentiating ‘truck and dog’, but a much more difficult time classifying ‘dog and cat’. 

June 22, 2022

What does model.evaluate() return in keras?

Kerasadmin

Keras library provides a way to calculate standard metrics when training and evaluating deep learning models. In Keras, metrics are passed during the compile stage as shown below. You can pass several metrics by comma separating them

June 15, 2022

Create NumPy array from PyTorch Tensor using detach().numpy()

PyTorchadmin

When creating an np.array from torch.tensor or vice versa, both object reference the same underlying storage in memory. Since np.ndarray does not store the computational graph associated with the array, this graph should be explicitly removed using detach() when sharing both numpy and torch wish to reference the same tensor.

May 20, 2022

How to use optimizer.zero_grad() in PyTorch

PyTorchadmin

If backward is called again as in any training loop then the loss is evaluated again, and the gradient at each leaf is accumulated on top.

May 11, 2022

Use of ‘model.eval()’ and ‘with torch.no_grad()’ in PyTorch model evaluate

PyTorchPragati

Using the designated settings for training model.train() and evaluation model.eval() will automatically set the mode for the dropout layer and batch normalization layers and rescale appropriately so that we do not have to worry about that at all.

May 6, 2022

Iterating through DataLoader using iter() and next() in PyTorch

PyTorchPragati

Access an individual batch from the DataLoader, we first pass the DataLoader object to Python’s iter() built-in function, which returns an object representing a stream of data.

April 29, 2022

Difference between BCELoss and BCEWithLogitsLoss in PyTorch

PyTorchadmin

Computing the binary loss by providing the logits, and not the class probabilities is usually preferred due to numerical stability.

April 22, 2022

How to calculate running loss using loss.item() in PyTorch?

PyTorchadmin

you could just sum it and calculate the mean after the epoch finishes or at the end of the epoch, we divide by the number of steps(dataset size). It gives you the correct average sample loss for this particular epoch. This training loss is used to see, “how well your model performs on the training dataset”.

April 14, 2022

Advantage of using LogSoftmax vs Softmax vs Crossentropyloss in PyTorch

PyTorchadmin

The workaround is to use log probability instead of probability, which takes care to make the calculation numerically stable. The reformulated version allows us to evaluate softmax with only small numerical errors even when z contains extremely large or extremely negative numbers.

April 8, 2022

How to create a Contiguous tensor in Pytorch?

PyTorchadmin

Contiguous tensors are convenient because we can visit them efficiently in order without jumping around in the storage. It improves data locality and improves performance because of the way memory access works on modern CPUs. This advantage of course depends on the way algorithms visit.

Posts navigation

1 2 … 21 Next

Recent Posts

  • PyTorch Confusion Matrix for multi-class image classification
  • What does model.evaluate() return in keras?
  • Create NumPy array from PyTorch Tensor using detach().numpy()
  • How to use optimizer.zero_grad() in PyTorch
  • Use of ‘model.eval()’ and ‘with torch.no_grad()’ in PyTorch model evaluate
  • Privacy Policy
Copyright © 2022 Knowledge Transfer All Rights Reserved.