Pytorch Toolbelt Versions Save

PyTorch extensions for fast R&D prototyping and Kaggle farming

0.7.0

8 months ago

New stuff

  • 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.

  • Improvements

  • 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.

Bugfixes

  • Implementation of get_collate_fn for RandomSubsetDataset is not correct and returns collate function instead of calling it

Breaking Changes

  • Signature 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)

0.6.2

1 year ago

0.6.1

1 year ago

Pytorch Toolbelt 0.6.1

  • Fixes to CI actions
  • Adding support for python 3.10
  • Bugfix in DatasetMeanStdCalculator when mask argument was used

0.6.0

1 year ago

Breaking Changes

All catalyst-related callbacks are moved to fork of the Catalyst library

0.5.3

1 year ago

Bugfixes

New Stuff

  • InriaAerialImageDataset for working with Inria Aerial Dataset
  • get_collate_for_dataset function to get collate fn if a dataset instance (argument) exposes get_collate_fn method. Works also for ConcatDataset.

Improvements

  • DatasetMeanStdCalculator supports dtype to specify accumulator type (float64 by default)

0.5.2

1 year ago

BugFixes

  • Fixed bug in ApplySoftmaxTo and ApplySigmoidTo modules that could lead to activations not applied to input when it was a string

New API

  • Added fs.find_images_in_dir_recursive
  • Added utils.describe_outputs to return a human-friendly representation of complex (dict, nested list, etc) outputs to see shape, mean/std of each tensor.

Other

More MyPy fixes & type annotations

0.5.1

1 year ago

New API

  • Added fs.find_subdirectories_in_dir to retrieve list of subdirectories (non-recursive) in the given directory.
  • Added logodd averaging of TTA predictions and counterpart logodd_mean function.

Improvements

  • In 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.

0.5.0

2 years ago

Version 0.5.0

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:

New features

  • Added class pytorch_toolbelt.datasets.DatasetMeanStdCalculator to compute mean & std of the dataset that does not fit entirely in memory.
  • New decoder module: BiFPNDecoder
  • New encoders: SwinTransformer, SwinB, SwinL, SwinT, SwinS
  • Added broadcast_from_master function to distributed utils. This method allows scattering a tensor from the master node to all nodes.
  • Added reduce_dict_sum to gather & concatenate dictionary of lists from all nodes in DDP.
  • Added master_print as a drop-in replacement to print that prints to stdout only on the zero-rank node.

Bug Fixes

Breaking changes

  • Bounding boxes matching method has been divided into two: 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)

Fixes & Improvements (NO BC)

  • Added 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.
  • All TTA functions supports PyTorch Tracing
  • 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.
  • Reduced number of boilerplates & hardcoded code for encoders from timm. Now GenericTimmEncoder queries output strides & feature maps directly from the timm's encoder instance.
  • HRNet-based encoders now have a 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 metric

0.4.4

2 years ago

New features

  • New tiled processing classes for 3D data - VolumeSlicer and VolumeMerger. Designed similarly to ImageSlicer. Not you can run 3D segmentation on huge volumes without risk of OOM.
  • Support of labels (scalar or 1D vector) augmentation/deaugmentation in D2, D4 and flip-style TTA.
  • Balanced BCE loss (BalancedBCEWithLogitsLoss)
  • Bi-Tempered loss 'BiTemperedLogisticLoss'
  • SelectByIndex helper module to pick named output of the model (For use in nn.Sequential)
  • New encoders MobileNetV3Large, MobileNetV3Small from torchvision.
  • New encoders from timm package (HRNets, ResNetD, EfficientNetV2 and others).
  • DeepLabV3 & DeepLabV3+ Decoders
  • Pure PyTorch-based implementation for bbox matching (match_bboxes) that supports both CPU/GPU matching using hungarian algorithm.

Bugfixes

  • Fix bug in Lovasz Loss (#62), thanks @seefun

Breaking Changes

  • Parameter ignore renamed to ignore_index in BinaryLovaszLoss class.
  • Renamed fpn_channels argument in constructor of FPNSumDecoder and FPNCatDecoder to channels.
  • Renamed 'output_channelsargument in constructor ofHRNetSegmentationDecoder to 'channels.
  • conv1x1 not set bias to zero by default
  • Bumped up minimal pytorch version to 1.8.1

Other Improvements

  • Ensembler class not correctly works with torch.jit.tracing
  • Numerous docstrings & type annotations enchancements

0.4.3

3 years ago

PyTorch Toolbelt 0.4.3

Modules

  • Added missing sigmoid activation support to get_activation_block
  • Make Encoders support JIT & Tracing
  • Better support for encoders from timm (They named with prefix Timm)

Utils

  • rgb_image_from_tensor now clip values

TTA & Ensembling

  • Ensembler now supports arithmetic, geometric & harmonic averaging via reduction parameter.
  • Bring geometric & harmonic averaging to all TTA functions as well

Datasets

  • read_binary_mask
  • Refactor SegmentationDataset to support strided masks for deep supervision
  • Added RandomSubsetDataset and RandomSubsetWithMaskDataset to sample dataset based on some condition (E.g. sample only samples of particular class)

Other

As usual, more tests, better type annotations & comments