Struct TripletMarginLossImpl

Inheritance Relationships

Base Type

Struct Documentation

struct TripletMarginLossImpl : public torch::nn::Cloneable<TripletMarginLossImpl>

Creates a criterion that measures the triplet loss given an input tensors :math:x1, :math:x2, :math:x3 and a margin with a value greater than :math:0.

This is used for measuring a relative similarity between samples. A triplet is composed by a, p and n (i.e., anchor, positive examples and negative examples respectively). The shapes of all input tensors should be :math:(N, D). See to learn about the exact behavior of this module.

See the documentation for torch::nn::TripletMarginLossOptions class to learn what constructor arguments are supported for this module.



Public Functions

explicit TripletMarginLossImpl(TripletMarginLossOptions options_ = {})
virtual void reset() override

reset() must perform initialization of all members with reference semantics, most importantly parameters, buffers and submodules.

virtual void pretty_print(std::ostream &stream) const override

Pretty prints the TripletMarginLoss module into the given stream.

Tensor forward(const Tensor &anchor, const Tensor &positive, const Tensor &negative)

Public Members

TripletMarginLossOptions options

The options with which this Module was constructed.


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