FLImaging 7.8.25.3
TensorLabels.h
1#pragma once
2
3#if _MSC_VER >= 1900 && defined(_M_X64)
4
5#include "TensorImages.h"
6
7#include <atomic>
8
9namespace FLImaging
10{
11 namespace AI
12 {
13 class FL_EXPORT CValidationImageExtractorDL;
14
15 template <typename T>
16 class FL_EXPORT CTensorLabels : public CTensorImages<T>
17 {
18 public:
19 CTensorLabels();
20
21 CTensorLabels(const CTensorLabels<T>& tsr, bool bDeepCopy = true);
22
23 virtual ~CTensorLabels();
24
25 virtual const CResult GetBinaryData(Base::CFLData& fldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
26 virtual const CResult GetBinaryData(Base::CFLData* pFldBinary, bool bSuperClass = false, int32_t i32Version = -1, bool bDumpMode = false) const override;
27
28 virtual const CResult SetBinaryData(const Base::CFLData& fldBinary, int64_t* pI64Offset = nullptr) override;
29 virtual const CResult SetBinaryData(const Base::CFLData* pFldBinary, int64_t* pI64Offset = nullptr) override;
30
31 virtual const CResult Create(const std::vector<int64_t>& vctShape, bool bOrderByDesc = true, bool bCudaAllocation = true) override;
32 virtual const CResult Create(const std::initializer_list<int64_t>& ilShape, bool bOrderByDesc = true, bool bCudaAllocation = true) override;
33 virtual const CResult Create(const Base::CFLImage& fli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod, bool bROIExtraction, bool bNormalize, const Base::CMultiVar<T>& mvBlankColor, ImageProcessing::EInterpolationMethod eInterpolationMethod, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex, bool* pBAbort) override;
34 virtual const CResult Create(const Base::CFLImage* pFli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod, bool bROIExtraction, bool bNormalize, const Base::CMultiVar<T>& mvBlankColor, ImageProcessing::EInterpolationMethod eInterpolationMethod, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex, bool* pBAbort) override;
35 virtual const CResult Create(const Base::CFLImage& fli, bool bNormalize = true, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
36 virtual const CResult Create(const Base::CFLImage* pFli, bool bNormalize = true, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
37 virtual const CResult Create(const Base::CFLImage& fli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
38 virtual const CResult Create(const Base::CFLImage* pFli, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
39
40
41 virtual const CResult Create(const wchar_t* pWcFilePath, const std::vector<int64_t>& vctNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., bool bRecursive = false, ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear);
42 virtual const CResult Create(const wchar_t* pWcFilePath, const std::initializer_list<int64_t>& ilNewSize, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., bool bRecursive = false, ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear);
43
44 virtual const CResult Assign(const CTensor<T>* pTsr, bool bDeepCopy = true) override;
45 virtual const CResult Assign(const CTensorImages<T>* pTsr, bool bDeepCopy = true) override;
46
47 virtual const CResult Assign(const CTensorLabels<T>& tsr, bool bDeepCopy = true);
48 virtual const CResult Assign(const CTensorLabels<T>* pTsr, bool bDeepCopy = true);
49
50 virtual const CResult Append(const Base::CFLImage* pFli, EResizeMethod eResizeMethod = EResizeMethod_ScaleAllAxises, bool bROIExtraction = false, bool bNormalize = true, const Base::CMultiVar<T>& mvBlankColor = 0., ImageProcessing::EInterpolationMethod eInterpolationMethod = ImageProcessing::EInterpolationMethod_Bilinear, std::atomic<int32_t>* pI32CurrentPreparingTensorIndex = nullptr, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
51
52 virtual const CResult Append(const wchar_t* pWcFilePath, bool bRecursive = false) override;
53
54 virtual const CResult Initialize() override;
55 virtual const CResult Clear() override;
56
57 virtual const CResult SetBatchParameters(const CTensorImages<T>& tsr) override;
58 virtual const CResult SetBatchParameters(const CTensorLabels<T>& tsr);
59 virtual const CResult EnableTrainingMode(bool bMode, bool bRecursively = true) override;
60
61 virtual CTensorLabels<T>& Evaluate() override;
62 virtual CComputationalBase<T>* Clone() const override;
63
64 virtual const CResult Swap(CComputationalBase<T>& cbSwap) override;
65
66 virtual const CResult LoadTensor(const std::vector<int64_t>& vctBatchIndices) override;
67
68 virtual const CResult ConvertClassNumToLabel(bool bIncludingClassName = true) override;
69 virtual const CResult ConvertLabelToClassNum(bool bIncludingClassName = true) override;
70
71
72 static const CResult ExtractClassNumClassName(const Base::CFLImage& fliSrc, Base::CFLArray<Base::CFLArray<int32_t>>& fla2ClassNum, Base::CFLArray<Base::CFLArray<Base::CFLString<wchar_t>>>& fla2ClassName);
73 static const CResult ExtractClassNumClassName(const Base::CFLImage* pFliSrc, Base::CFLArray<Base::CFLArray<int32_t>>& fla2ClassNum, Base::CFLArray<Base::CFLArray<Base::CFLString<wchar_t>>>& fla2ClassName);
74
75 DeclareGetClassType();
76 SupportToDuplicateObject(CTensorLabels, *this);
77 protected:
78 virtual const CResult IsValidImageFormat(EImageType eImageType) const override;
79 virtual const CResult DecodeLabels(const wchar_t* pWcsImagePath, Base::CFLImage* pFli = nullptr) override;
80 virtual const CResult CropImage(const Base::CFLImage* pFliSrc, Base::CFLImage* pFliDst, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
81 virtual const CResult InternalCropImage(const std::vector<int64_t>& vctBatchIndices, const Base::CFLImage* pFliSrc, Base::CFLImage* pFliDst, std::atomic<int32_t>* pI32CurrentPreparingLabelIndex = nullptr, bool* pBAbort = nullptr);
82
83 protected:
84 Foundation::CFLFigureArray m_flfaCroppedLabels;
85 std::vector<std::pair<int64_t, std::vector<int32_t>>>& m_vctLabelCount;
86 std::vector<std::pair<int64_t, std::vector<int32_t>>>& m_vctCumulativeLabelCount;
87
88 private:
89 friend class CValidationImageExtractorDL;
90 public:
91 DeclareGetSignletonObject(CTensorLabels);
92 };
93
94 #define CCGFTensorLabels(...) (*(new CTensorLabels<float>(__VA_ARGS__)))
95 #define CCGDTensorLabels(...) (*(new CTensorLabels<double>(__VA_ARGS__)))
96
97 typedef CTensorLabels<float> CTensorLabelsF;
98 typedef CTensorLabels<double> CTensorLabelsD;
99 }
100}
101
102#endif
Validation Image Extractor class.
Definition ValidationImageExtractorDL.h:23
Definition AlgorithmAIBase.h:18
@ Assign
Set the value of CGUIPropertyItemView3DFigure to the specified figure.
Definition DefinitionsGUIView3D.h:3531
@ Clear
Clear all the figure objects.
Definition DefinitionsGUI.h:5083
@ Append
Load and append.
Definition DefinitionsGUI.h:58