FLImaging 6.5.16.1
BackendSoftmaxWithCrossEntropy.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "BackendBase.h"
6
7namespace FLImaging
8{
9 namespace AI
10 {
11 #ifdef CUDNN_MODE
12 template<typename T>
13 class CCuda_ComputationalGraphSoftmax_CudnnWithCrossEntropy;
14 #endif
15
16 template <typename T>
17 class FL_EXPORT CTensor;
18
19 template <typename T>
20 class FL_EXPORT CBackendSoftmaxWithCrossEntropy : public CBackendBase<T>
21 {
22 public:
23 CBackendSoftmaxWithCrossEntropy();
24 CBackendSoftmaxWithCrossEntropy(const CBackendSoftmaxWithCrossEntropy<T>& bl);
25 virtual ~CBackendSoftmaxWithCrossEntropy();
26
27 virtual const CResult SoftmaxWithCrossEntropy_Forward(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, CTensor<T>& tsrSoftmaxBuffer, CTensor<T>& pTsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull = nullptr, EReductionType eReductionType = EReductionType_Mean, T tLabelSmoothingValue = 0, int64_t i64IgnoreIndex = -1);
28 virtual const CResult SoftmaxWithCrossEntropy_Backward(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, const CTensor<T>* pTsrDy, CTensor<T>* pTsrDx, const CTensor<T>& tsrSoftmaxBuffer, const CTensor<T>& pTsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull = nullptr, EReductionType eReductionType = EReductionType_Mean, T tLabelSmoothingValue = 0, int64_t i64IgnoreIndex = -1);
29
30 protected:
31 virtual const CResult SoftmaxWithCrossEntropy(const CTensor<T>* pTsrX, const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, CTensor<T>& tsrSoftmaxBuffer, CTensor<T>& tsrTargetBuffer, const CTensor<T>* pTsrWeightOrNull, EReductionType eReductionType, T tLabelSmoothingValue, int64_t i64IgnoreIndex, T tDominatorValue);
32 virtual const CResult OneHotEncoding(const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, int64_t i64Ch, int64_t i64IgnoreIndex);
33 virtual const CResult LabelSmoothing(const CTensor<T>* pTsrTarget, CTensor<T>* pTsrResult, const T tSmoothingVal);
34 virtual T CalculateDominatorValue(const CTensor<T>* pTsrOperand, const CTensor<T>* pTsrTarget, const CTensor<T>* pTsrWeightOrNull, EReductionType eReducntionType, int64_t i64IgnoreIndex);
35 virtual const CResult ApplyIgnoreIndex(const CTensor<T>* pTsrTargetLongType, CTensor<T>* pTsrTargetOneHotEncoded, int64_t i64IgnoreIndex);
36
37 DeclareGetClassType();
38 SupportToDuplicateObjectWithoutCreateNewObject(CBackendSoftmaxWithCrossEntropy<T>, *this);
39 protected:
40 #ifdef CUDNN_MODE
41 CCuda_ComputationalGraphSoftmax_CudnnWithCrossEntropy<T>* m_pCudnn;
42 #endif
43
44 };
45 }
46}
47
48#endif