Releases: BloodAxe/pytorch-toolbelt
Pytorch Toolbelt 0.8.0
What's Changed
-
Merge pull request #97 from BloodAxe/develop by @BloodAxe in #98
-
Reduced focal loss implementation is incorrect for binary case by @MrPrajwalB in #102
New Contributors
- @MrPrajwalB made their first contribution in #102
Full Changelog: 0.7.0...0.8.0
Pytorch Toolbelt 0.7.0
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 tofloat32
. -
MultiscaleTTA
now allows setting interpolationmode
andalign_corners
for resizing input and predictions. -
BinaryFocalLoss
now has__repr__
-
name_for_stride
now acceptsstride
argument to be None. In this case the function is noop and returns input argumentname
. -
RandomSubsetDataset
now takes optionalweights
argument to select samples with given probability.
Bugfixes
- Implementation of
get_collate_fn
forRandomSubsetDataset
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 typeFeatureMapsSpecification
. -
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
andJointLoss
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)
Pytorch Toolbelt 0.6.2
Merge pull request #89 from BloodAxe/develop 0.6.2
Pytorch Toolbelt 0.6.1
Pytorch Toolbelt 0.6.1
- Fixes to CI actions
- Adding support for python 3.10
- Bugfix in DatasetMeanStdCalculator when mask argument was used
PyTorch Toolbelt 0.6.0
Breaking Changes
All catalyst-related callbacks are moved to fork of the Catalyst library
PyTorch Toolbelt 0.5.3
Bugfixes
- Fix #78 thanks https://github.com/mehran66 for pointing this out
New Stuff
- InriaAerialImageDataset for working with Inria Aerial Dataset
get_collate_for_dataset
function to get collate fn if a dataset instance (argument) exposesget_collate_fn
method. Works also for ConcatDataset.
Improvements
DatasetMeanStdCalculator
supportsdtype
to specify accumulator type (float64 by default)
PyTorch Toolbelt 0.5.2
BugFixes
- Fixed bug in
ApplySoftmaxTo
andApplySigmoidTo
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
PyTorch Toolbelt 0.5.1
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 counterpartlogodd_mean
function.
Improvements
- In
plot_confusion_matrix
one can disable plotting scores in each cell usingshow_scores
argument (True
by default). freeze_model
method now returns inputmodule
argument.
PyTorch Toolbelt 0.5.0
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 toprint
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
andmatch_bboxes_hungarian
. The first method uses scores of predicted bboxes and matches most confident predictions first, while thematch_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 toApplySoftmaxTo
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 adevice
(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
andBalancedBCEWithLogitsLoss
now supportsignore_index
argument.BiTemperedLogisticLoss
&BinaryBiTemperedLogisticLoss
also got support ofignore_index
argument.focal_loss_with_logits
now also supportsignore_index
. Computation of ignored values has been moved fromBinaryFocalLoss
to this function.- Reduced number of boilerplates & hardcoded code for encoders from
timm
. NowGenericTimmEncoder
queries output strides & feature maps directly from thetimm
'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 supportsPath
as input argument. Return type (str) remains unchanged.count_parameters
now acceptshuman_friendly
argument to print parameters count in human-friendly form21.1M
instead 21123123.plot_confusion_matrix
now hasformat_string
argument (None by default) to specify custom format string for values in confusion matrix.RocAucMetricCallback
for Catalyst gotfix_nans
argument to fixNaN
outputs, which causedroc_auc
to raise an exception and break the training.BestWorstMinerCallbac
now additionally logs batch withNaN
value in monitored metric
PyTorch Toolbelt 0.4.4
New features
- New tiled processing classes for 3D data -
VolumeSlicer
andVolumeMerger
. Designed similarly toImageSlicer
. 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 innn.Sequential
)- New encoders
MobileNetV3Large
,MobileNetV3Small
fromtorchvision
. - 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
Breaking Changes
- Parameter
ignore
renamed toignore_index
inBinaryLovaszLoss
class. - Renamed
fpn_channels
argument in constructor ofFPNSumDecoder
andFPNCatDecoder
tochannels
. - Renamed 'output_channels
argument in constructor of
HRNetSegmentationDecoderto '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 withtorch.jit.tracing
- Numerous docstrings & type annotations enchancements