Skip to content

Releases: KevinMusgrave/pytorch-metric-learning

v2.1.1

03 May 11:58
c57ebdd
Compare
Choose a tag to compare

Bug Fixes

  • Fixes bug where BaseDistance.initial_avg_query_norm was not actually being set (#620)

v2.1.0

05 Apr 23:21
03d5192
Compare
Choose a tag to compare

Features

New loss function: PNPLoss. Thanks @interestingzhuo!

v2.0.1

21 Feb 17:34
691a635
Compare
Choose a tag to compare

Bug Fixes

v2.0.0

29 Jan 23:57
Compare
Choose a tag to compare

New features

SelfSupervisedLoss

You don't have to create labels for self-supervised learning anymore:

from pytorch_metric_learning.losses import SelfSupervisedLoss
loss_func = SelfSupervisedLoss(TripletMarginLoss())
embeddings = model(data)
augmented = model(augmented_data)
loss = loss_func(embeddings, augmented)

Thanks @cwkeam!

API changes

AccuracyCalculator.get_accuracy

The order and naming of arguments has changed.

Before:

get_accuracy(
    query, 
    reference, 
    query_labels, 
    reference_labels, 
    embeddings_come_from_same_source=False
)

Now:

get_accuracy(
    query, 
    query_labels,
    reference=None,
    reference_labels=None 
    ref_includes_query=False
)

The benefits of this change are:

  • if query is reference, then you only need to pass in query, query_labels
  • ref_includes_query is shorter and clearer in meaning than embeddings_come_from_same_source

Some example usage of the new format:

# Accuracy of a query set, where the query set is also the reference set:
get_accuracy(query, query_labels)

# Accuracy of a query set with a separate reference set:
get_accuracy(query, query_labels, ref, ref_labels)

# Accuracy of a query set with a reference set that includes the query set:
get_accuracy(query, query_labels, ref, ref_labels, ref_includes_query=True)

BaseMiner instead of BaseTupleMiner

Miners must extend BaseMiner because BaseTupleMiner no longer exists

CrossBatchMemory's enqueue_idx is now enqueue_mask

Before, enqueue_idx specified the indices of embeddings that should be added to the memory bank.

Now, enqueue_mask[i] should be True if embeddings[i] should be added to the memory bank.

The benefit of this change is that it fixed an issue in distributed training.

Here's an example of the new usage:

# enqueue the second half of a batch
enqueue_mask = torch.zeros(batch_size).bool()
enqueue_mask[batch_size/2:] = True

VICRegLoss requires keyword argument

Before:

loss_fn = VICRegLoss()
loss_fn(emb, ref_emb)

Now:

loss_fn = VICRegLoss()
loss_fn(emb, ref_emb=ref_emb)

The reason is that VICRegLoss now uses the forward method of BaseMetricLossFunction, to allow for possible generalizations in the future without causing more breaking changes.

BaseTrainer mining_funcs and dataset have swapped order

This is to allow mining_funcs to be optional.

Before if you didn't want to use miners:

MetricLossOnly(
    models,
    optimizers,
    batch_size,
    loss_funcs,
    mining_funcs = {},
    dataset = dataset,
)

Now:

MetricLossOnly(
    models,
    optimizers,
    batch_size,
    loss_funcs,
    dataset,
)

Deletions

The following classes/functions were removed

  • losses.CentroidTripletLoss (it contained a bug that I don't have time to figure out)
  • miners.BaseTupleMiner (use miners.BaseMiner instead)
  • miners.BaseSubsetBatchMiner (rarely used)
  • miners.MaximumLossMiner (rarely used)
  • trainers.UnsupervisedEmbeddingsUsingAugmentations (rarely used)
  • utils.common_functions.Identity (use torch.nn.Identity instead)

Other minor changes

  • VICRegLoss should now work with DistributedLossWrapper (#535)
  • Dynamic recordable attribute names were removed (#436)
  • AccuracyCalculator now returns NaN instead of 0 when none of the query labels appear in the reference set (#397)

v1.7.3

29 Jan 00:48
f27a8bf
Compare
Choose a tag to compare

Bug fixes and minor improvements

  • Fixed #472, in which enqueue_idx for CrossBatchMemory could not be passed into DistributedLossWrapper
  • Converted CrossBatchMemory's embedding_memory and label_memory to buffers, so they can be saved and loaded as state dicts and transferred to devices use .to(device).

v1.7.2

21 Jan 05:30
368c686
Compare
Choose a tag to compare

Minor improvement

Resolved #565

v1.7.1

17 Jan 01:25
557a7ca
Compare
Choose a tag to compare

Features and bug fixes

  • Added SumReducer
  • Fixed bug where labels were always required for DistributedLossWrapper
  • Removed torchvision as a dependency

v1.7.0

16 Jan 20:03
ef755ab
Compare
Choose a tag to compare

Bug fixes

Fixes an edge case in ArcFaceLoss. Thanks @ElisonSherton!

Relevant links:

v1.6.3

01 Nov 23:07
d3feece
Compare
Choose a tag to compare

Bug Fixes

  • Fixed bug where DistributedMinerWrapper would crash when world_size == 1 (#542)

v1.6.2

20 Sep 20:09
ddccf43
Compare
Choose a tag to compare

Additional fix to v1.6.1

To be consistent with the common definition of mean average precision, the divisor has been changed again:

  • v1.6.1 divisor was min(k, num_relevant)
  • v1.6.2 divisor is num_relevant

Again, this has no effect on mean_average_precision_at_r