FLImaging 6.5.16.1
ComputationalGraphSoftmaxWithCrossEntropy.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "ComputationalGraph.h"
6#include "BackendSoftmaxWithCrossEntropy.h"
7#include "DefinitionsAI.h"
8#include "Tensor.h"
9
10namespace FLImaging
11{
12 namespace AI
13 {
14 template <typename T>
15 class FL_EXPORT CComputationalGraphSoftmaxWithCrossEntropy : public CComputationalGraph<T>
16 {
17
18 private:
19 CComputationalGraphSoftmaxWithCrossEntropy();
20
21 protected:
22 CComputationalGraphSoftmaxWithCrossEntropy(const CComputationalGraphSoftmaxWithCrossEntropy<T>& cg);
23
24 public:
25 CComputationalGraphSoftmaxWithCrossEntropy(const CComputationalBase<T>& cbOperand1, const CComputationalBase<T>& tsrAnswer, CTensor<T>* pTsrWeights = nullptr, EReductionType eReductionType = EReductionType_Mean, T tSmoothingVal = 0., int64_t i64IgnoreIndex = -1);
26 virtual ~CComputationalGraphSoftmaxWithCrossEntropy();
27
28 virtual CTensor<T>& Forward() override;
29 virtual CTensor<T>* Backward() override;
30 virtual CComputationalBase<T>* Clone() const override;
31
32 virtual const std::vector<int64_t>& GetEstimatedShape(bool bRecursive = true) const override;
33 virtual const CResult PrintNodeParamInfo() const override;
34
35 virtual const CResult GetBinaryData(Base::CFLData& fldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
36 virtual const CResult GetBinaryData(Base::CFLData* pFldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
37
38 virtual const CResult SetBinaryData(const Base::CFLData& fldBinary, int64_t* pI64Offset = nullptr) override;
39 virtual const CResult SetBinaryData(const Base::CFLData* pFldBinary, int64_t* pI64Offset = nullptr) override;
40
41 virtual int64_t GetRequiredDedicatedMemory(bool bTraining = false, bool bRecursively = true, int64_t i64BatchSize = 1) const override;
42 virtual int64_t GetRequiredTemporaryMemory(bool bTraining = false, bool bRecursively = true, int64_t i64BatchSize = 1, int64_t i64MemoryIndex = 0) const override;
43
44 virtual int64_t GetIgnoreIndex() const;
45 virtual const CResult SetIgnoreIndex(int64_t i64IgnoreIndex);
46
47 DeclareGetClassType();
48 SupportToDuplicateObjectWithoutCreateNewObject(CComputationalGraphSoftmaxWithCrossEntropy, *this);
49 private:
50 EReductionType m_eReductionType;
51 CTensor<T> m_tsrWeights;
52 CTensor<T> m_tsrSoftmax;
53 CTensor<T> m_tsrTargetBuffer;
54
55 T m_tSmoothingVal;
56 T m_tDominatorVal;
57 int64_t m_i64IgnoreIndex;
58
59 CBackendSoftmaxWithCrossEntropy<T> m_backendCrossEntropy;
60 public:
61 DeclareGetSignletonObject(CComputationalGraphSoftmaxWithCrossEntropy);
62 };
63
64 #define CCGFSoftmaxWithCrossEntropy(...) (*(new CComputationalGraphSoftmaxWithCrossEntropy<float>(__VA_ARGS__)))
65 #define CCGDSoftmaxWithCrossEntropy(...) (*(new CComputationalGraphSoftmaxWithCrossEntropy<double>(__VA_ARGS__)))
66
67 #define CCGTSoftmaxWithCrossEntropy(T, ...) (*(new CComputationalGraphSoftmaxWithCrossEntropy<T>(__VA_ARGS__)))
68 }
69}
70
71#endif