Struct SmoothL1LossImpl

Inheritance Relationships

Base Type

Struct Documentation

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

Creates a criterion that uses a squared term if the absolute element-wise error falls below beta and an L1 term otherwise.

It is less sensitive to outliers than the MSELoss and in some cases prevents exploding gradients (e.g. see the paper Fast R-CNN by Ross Girshick). See to learn about the exact behavior of this module.

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


SmoothL1Loss model(SmoothL1LossOptions().reduction(torch::kNone).beta(0.5));

Public Functions

SmoothL1LossImpl(const SmoothL1LossOptions &options_ = {})
void reset() override

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

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

Pretty prints the L1Loss module into the given stream.

Tensor forward(const Tensor &input, const Tensor &target)

Public Members

SmoothL1LossOptions 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