Struct TripletMarginWithDistanceLossOptions

Page Contents

Struct Documentation

struct torch::nn::TripletMarginWithDistanceLossOptions

Options for the TripletMarginWithDistanceLoss module.


TripletMarginWithDistanceLoss model(TripletMarginWithDistanceLossOptions().margin(3).swap(false));

Public Types

typedef c10::variant<enumtype::kNone, enumtype::kMean, enumtype::kSum> reduction_t
typedef std::function<Tensor(const Tensor&, const Tensor&)> distance_function_t

Public Functions

auto distance_function(const c10::optional<distance_function_t> &new_distance_function) -> decltype(*this)

Specifies a nonnegative, real-valued function that quantifies the closeness of two tensors.

If not specified, F::pairwise_distance will be used. Default: nullopt

auto distance_function(c10::optional<distance_function_t> &&new_distance_function) -> decltype(*this)
const c10::optional<distance_function_t> &distance_function() const noexcept
c10::optional<distance_function_t> &distance_function() noexcept
auto margin(const double &new_margin) -> decltype(*this)

Specifies a nonnegative margin representing the minimum difference between the positive and negative distances required for the loss to be 0.

Larger margins penalize cases where the negative examples are not distance enough from the anchors, relative to the positives. Default: 1

auto margin(double &&new_margin) -> decltype(*this)
const double &margin() const noexcept
double &margin() noexcept
auto swap(const bool &new_swap) -> decltype(*this)

Whether to use the distance swap described in the paper Learning shallow convolutional feature descriptors with triplet losses by V.

Balntas, E. Riba et al. If True, and if the positive example is closer to the negative example than the anchor is, swaps the positive example and the anchor in the loss computation. Default: False

auto swap(bool &&new_swap) -> decltype(*this)
const bool &swap() const noexcept
bool &swap() noexcept
auto reduction(const reduction_t &new_reduction) -> decltype(*this)

Specifies the reduction to apply to the output. Default: Mean.

auto reduction(reduction_t &&new_reduction) -> decltype(*this)
const reduction_t &reduction() const noexcept
reduction_t &reduction() noexcept


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources