1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #27809 from abhishek-gola:softmax_cross_entropy

Added support for SCE and NLL losses #27809

This pull request adds the support for Negative Log-Likelihood loss and Softmax Cross-Entropy loss in new DNN engine.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Abhishek Gola
2025-10-11 15:15:17 +05:30
committed by GitHub
parent f79f193a10
commit 91768f9a27
8 changed files with 889 additions and 202 deletions
@@ -1311,6 +1311,33 @@ CV__DNN_INLINE_NS_BEGIN
static Ptr<Resize2Layer> create(const LayerParams& params);
};
// Shared reduction enum for DNN loss layers
enum LossReduction
{
LOSS_REDUCTION_NONE = 0,
LOSS_REDUCTION_MEAN = 1,
LOSS_REDUCTION_SUM = 2
};
class CV_EXPORTS NegativeLogLikelihoodLossLayer : public Layer
{
public:
LossReduction reduction;
int ignoreIndex;
static Ptr<NegativeLogLikelihoodLossLayer> create(const LayerParams& params);
};
class CV_EXPORTS SoftmaxCrossEntropyLossLayer : public Layer
{
public:
static Ptr<SoftmaxCrossEntropyLossLayer> create(const LayerParams& params);
LossReduction reduction;
int ignoreIndex;
float labelSmoothing;
bool softLabel;
};
/**
* @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public-ver2
*