PyTorch extensions for fast R&D prototyping and Kaggle farming
All encoders & decoders & heads are now inherit from HasOutputFeaturesSpecification
interface to query number of output channels and strides this module outputs.
New loss class QualityFocalLoss
from https://arxiv.org/abs/2006.04388
New function pad_tensor_to_size
-A generic padding function for N-dimensional tensors [B,C, ...] shape.
Added DropPath
layer (aka DropConnect)
Pretrained weights for SegFormer backbones
first_class_background_init
for initializing last output convolution/linear block to have zeros in weights and bias layer set to [logit(bg_prob), logit(1-bg_prob), ...]
New function instantiate_normalization_block
to create normalization layer by name. This is used in some decoder layers / heads.
Improve numeric accuracy of focal_loss_with_logits
function by explicitly disabling AMP autocast for this function and casting preds & targets to float32
.
MultiscaleTTA
now allows setting interpolation mode
and align_corners
for resizing input and predictions.
BinaryFocalLoss
now has __repr__
name_for_stride
now accepts stride
argument to be None. In this case the function is noop and returns input argument name
.
RandomSubsetDataset
now takes optional weights
argument to select samples with given probability.
get_collate_fn
for RandomSubsetDataset
is not correct and returns collate function instead of calling itSignature of decoders changes to require first argument input_spec
to be of type FeatureMapsSpecification
.
Rewritten BiFPN decoder to support arbitrary number of input feature maps, user-defined normalization & activation & BiFPN block.
Rewritten UNetDecoder to allow setting upsample block as string type
WeightedLoss
and JointLoss
classes has been removed. If your code was using these classes here they are - copy paste them to your project and live happily, but I strongly suggest to use modern deep learning frameworks that support defining losses from configuration files.
class WeightedLoss(_Loss):
"""Wrapper class around loss function that applies weighted with fixed factor.
This class helps to balance multiple losses if they have different scales
"""
def __init__(self, loss, weight=1.0):
super().__init__()
self.loss = loss
self.weight = weight
def forward(self, *input):
return self.loss(*input) * self.weight
class JointLoss(_Loss):
"""
Wrap two loss functions into one. This class computes a weighted sum of two losses.
"""
def __init__(self, first: nn.Module, second: nn.Module, first_weight=1.0, second_weight=1.0):
super().__init__()
self.first = WeightedLoss(first, first_weight)
self.second = WeightedLoss(second, second_weight)
def forward(self, *input):
return self.first(*input) + self.second(*input)
All catalyst-related callbacks are moved to fork of the Catalyst library
get_collate_for_dataset
function to get collate fn if a dataset instance (argument) exposes get_collate_fn
method. Works also for ConcatDataset.DatasetMeanStdCalculator
supports dtype
to specify accumulator type (float64 by default)ApplySoftmaxTo
and ApplySigmoidTo
modules that could lead to activations not applied to input when it was a stringfs.find_images_in_dir_recursive
utils.describe_outputs
to return a human-friendly representation of complex (dict, nested list, etc) outputs to see shape, mean/std of each tensor.More MyPy fixes & type annotations
fs.find_subdirectories_in_dir
to retrieve list of subdirectories (non-recursive) in the given directory.logodd
averaging of TTA predictions and counterpart logodd_mean
function.plot_confusion_matrix
one can disable plotting scores in each cell using show_scores
argument (True
by default).freeze_model
method now returns input module
argument.This is the major release update of Pytorch Toolbelt. It's been a long time since the last update and there are many improvements & updates since 0.4.4:
pytorch_toolbelt.datasets.DatasetMeanStdCalculator
to compute mean & std of the dataset that does not fit entirely in memory.BiFPNDecoder
SwinTransformer
, SwinB
, SwinL
, SwinT
, SwinS
broadcast_from_master
function to distributed utils. This method allows scattering a tensor from the master node to all nodes.reduce_dict_sum
to gather & concatenate dictionary of lists from all nodes in DDP.master_print
as a drop-in replacement to print
that prints to stdout only on the zero-rank node.match_bboxes
and match_bboxes_hungarian
. The first method uses scores of predicted bboxes and matches most confident predictions first, while the match_bboxes_hungarian
matches bboxes to maximize overall IoU.set_manual_seed
now sets random seed for Numpy.to_numpy
now correctly works for None and all iterables (Not only tuple & list)dim
argument to ApplySoftmaxTo
to specify channel for softmax operator (default value is 1, which was hardcoded previously)ApplySigmoidTo
now applies in-place sigmoid (Purely performance optimization)TileMerger
now supports specifying a device
(Torch semantics) for storing intermediate tensors of accumulated tiles.MultiscaleTTA
now supports a model that returns a single Tensor (Key-Value outputs still works as before)balanced_binary_cross_entropy_with_logits
and BalancedBCEWithLogitsLoss
now supports ignore_index
argument.BiTemperedLogisticLoss
& BinaryBiTemperedLogisticLoss
also got support of ignore_index
argument.focal_loss_with_logits
now also supports ignore_index
. Computation of ignored values has been moved from BinaryFocalLoss
to this function.timm
. Now GenericTimmEncoder
queries output strides & feature maps directly from the timm
's encoder instance.use_incre_features
argument to specify whether output feature maps should have an increased number of features.change_extension
, read_rgb_image
, read_image_as_is
functions now supports Path
as input argument. Return type (str) remains unchanged.count_parameters
now accepts human_friendly
argument to print parameters count in human-friendly form 21.1M
instead 21123123.plot_confusion_matrix
now has format_string
argument (None by default) to specify custom format string for values in confusion matrix.RocAucMetricCallback
for Catalyst got fix_nans
argument to fix NaN
outputs, which caused roc_auc
to raise an exception and break the training.BestWorstMinerCallbac
now additionally logs batch with NaN
value in monitored metricVolumeSlicer
and VolumeMerger
. Designed similarly to ImageSlicer
. Not you can run 3D segmentation on huge volumes without risk of OOM.BalancedBCEWithLogitsLoss
)SelectByIndex
helper module to pick named output of the model (For use in nn.Sequential
)MobileNetV3Large
, MobileNetV3Small
from torchvision
.timm
package (HRNets, ResNetD, EfficientNetV2 and others).PyTorch
-based implementation for bbox matching (match_bboxes
) that supports both CPU/GPU matching using hungarian algorithm.ignore
renamed to ignore_index
in BinaryLovaszLoss
class.fpn_channels
argument in constructor of FPNSumDecoder
and FPNCatDecoder
to channels
.argument in constructor of
HRNetSegmentationDecoder to 'channels
.conv1x1
not set bias to zero by defaultEnsembler
class not correctly works with torch.jit.tracing
sigmoid
activation support to get_activation_block
timm
(They named with prefix Timm
)rgb_image_from_tensor
now clip valuesEnsembler
now supports arithmetic, geometric & harmonic averaging via reduction
parameter.read_binary_mask
SegmentationDataset
to support strided masks for deep supervisionRandomSubsetDataset
and RandomSubsetWithMaskDataset
to sample dataset based on some condition (E.g. sample only samples of particular class)As usual, more tests, better type annotations & comments