Category Archives: PyTorch
How to deactivate dropout layers while evaluation and prediction mode in Keras?
Forcing your network to learn redundant representations might sound very inefficient. But in practice, it makes things more robust and prevents overfitting. It also makes your network act as if taking the consensus over an ensemble of networks.
Create DataLoader with collate_fn() for variable-length input in PyTorch.
A custom collate_fn can be used to customize collation, e.g., padding sequential data to a max length of a batch.collate_fn is called with a list of data samples at each time. It is expected to collate the input samples into a batch for yielding from the data loader iterator.
Micro and Macro Averages for imbalance multiclass classification
A macro-average will compute the metric independently for each class and then take the average hence treating all classes equally, whereas a micro-average will aggregate the contributions of all classes to compute the average metric.
How to change the learning rate in the PyTorch using Learning Rate Scheduler?
The optimal learning rate will be dependent on both your model architecture and your dataset. While using a default learning rate may provide decent results, you can often improve the performance or speed up training by searching for an optimal learning rate.
How to deal with an imbalanced dataset using WeightedRandomSampler in PyTorch.
We use something called samplers for OverSampling. Though we did not use samplers exclusively, PyTorch used it for us internally. When we say shuffle=False, PyTorch ended up using SequentialSampler it gives an index from zero to the length of the dataset. When shuffle=True it ends up using a RandomSampler.
How to modify pre-train PyTorch model for Finetuning and Feature Extraction?
classification layer of the pre-trained model is specific to the original classification task, and subsequently specific to the set of classes on which the model was trained. You simply add a new classifier layer, which will be trained from scratch.