OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
cv::ml::SVMSGD 類參考abstract

隨機梯度下降 SVM 分類器。 更多...

#include <opencv2/ml.hpp>

cv::ml::SVMSGD 協作圖

公共型別

列舉  裕度型別 {
  SOFT_MARGIN ,
  HARD_MARGIN
}
 
列舉  Svmsgd型別 {
  SGD ,
  ASGD
}
 
- 從 cv::ml::StatModel 繼承的公共型別
列舉  標誌 {
  UPDATE_MODEL = 1 ,
  RAW_OUTPUT =1 ,
  COMPRESSED_INPUT =2 ,
  PREPROCESSED_INPUT =4
}
 

公共成員函式

virtual float getInitialStepSize () const =0
 SVMSGD 最佳化問題的 initialStepSize 引數。
 
virtual float getMarginRegularization () const =0
 SVMSGD 最佳化問題的 marginRegularization 引數。
 
virtual int getMarginType () const =0
 裕度型別,SVMSGD::MarginType 之一。
 
virtual float getShift ()=0
 
virtual float getStepDecreasingPower () const =0
 SVMSGD 最佳化問題的 stepDecreasingPower 引數。
 
virtual int getSvmsgdType () const =0
 演算法型別,SVMSGD::SvmsgdType 之一。
 
virtual TermCriteria getTermCriteria () const =0
 訓練演算法的終止條件。您可以指定最大迭代次數 (maxCount) 和/或迭代之間錯誤變化的程度,以使演算法繼續執行 (epsilon)。
 
virtual Mat getWeights ()=0
 
virtual void setInitialStepSize (float InitialStepSize)=0
 SVMSGD 最佳化問題的 initialStepSize 引數。
 
virtual void setMarginRegularization (float marginRegularization)=0
 SVMSGD 最佳化問題的 marginRegularization 引數。
 
virtual void setMarginType (int marginType)=0
 裕度型別,SVMSGD::MarginType 之一。
 
virtual void setOptimalParameters (int svmsgdType=SVMSGD::ASGD, int marginType=SVMSGD::SOFT_MARGIN)=0
 此函式為所選的 SVM SGD 模型設定最佳引數值。
 
virtual void setStepDecreasingPower (float stepDecreasingPower)=0
 SVMSGD 最佳化問題的 stepDecreasingPower 引數。
 
virtual void setSvmsgdType (int svmsgdType)=0
 演算法型別,SVMSGD::SvmsgdType 之一。
 
virtual void setTermCriteria (const cv::TermCriteria &val)=0
 訓練演算法的終止條件。您可以指定最大迭代次數 (maxCount) 和/或迭代之間錯誤變化的程度,以使演算法繼續執行 (epsilon)。
 
- 從 cv::ml::StatModel 繼承的公共成員函式
virtual float calcError (const Ptr< TrainData > &data, bool test, OutputArray resp) const
 計算訓練或測試資料集上的誤差。
 
virtual bool empty () const CV_OVERRIDE
 如果演算法為空(例如,在開始時或讀取不成功後),則返回 true。
 
virtual int getVarCount () const =0
 返回訓練樣本中變數的數量。
 
virtual bool isClassifier () const =0
 如果模型是分類器,則返回 true。
 
virtual bool isTrained () const =0
 如果模型已訓練,則返回 true。
 
virtual float predict (InputArray samples, OutputArray results=noArray(), int flags=0) const =0
 預測提供的樣本的響應
 
virtual bool train (const Ptr< TrainData > &trainData, int flags=0)
 訓練統計模型。
 
virtual bool train (InputArray samples, int layout, InputArray responses)
 訓練統計模型。
 
- 從 cv::Algorithm 繼承的公共成員函式
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 清除演算法狀態。
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 從檔案儲存中讀取演算法引數。
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 將演算法引數儲存到檔案儲存中。
 
void write (FileStorage &fs, const String &name) const
 

靜態公共成員函式

static Ptr< SVMSGDcreate ()
 建立空模型。使用 StatModel::train 訓練模型。由於 SVMSGD 有多個引數,您可能需要為問題找到最佳引數,或使用 setOptimalParameters() 設定一些預設引數。
 
static Ptr< SVMSGDload (const String &filepath, const String &nodeName=String())
 從檔案中載入並建立一個序列化的 SVMSGD
 
- 從 cv::ml::StatModel 繼承的靜態公共成員函式
template<typename _Tp >
static Ptr< _Tptrain (const Ptr< TrainData > &data, int flags=0)
 使用預設引數建立並訓練模型。
 
- 從 cv::Algorithm 繼承的靜態公共成員函式
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 從檔案中載入演算法。
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 從字串載入演算法。
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 從檔案節點讀取演算法。
 

附加繼承成員

- 從 cv::Algorithm 繼承的保護成員函式
void writeFormat (FileStorage &fs) const
 

詳細描述

隨機梯度下降 SVM 分類器。

SVMSGD 提供了使用隨機梯度下降方法實現 SVM 分類器的快速易用實現,如 [36] 中所述。

該分類器具有以下引數

  • 模型型別,
  • 裕度型別,
  • 裕度正則化 ( \(\lambda\)),
  • 初始步長 ( \(\gamma_0\)),
  • 步長遞減冪 ( \(c\)),
  • 和終止條件。

模型型別可以具有以下值之一: SGDASGD

  • SGDSVMSGD 分類器的經典版本:每個後續步驟透過以下公式計算

    \[w_{t+1} = w_t - \gamma(t) \frac{dQ_i}{dw} |_{w = w_t}\]

    其中
    • \(w_t\) 是步驟 \(t\) 處決策函式的權重向量,
    • \(\gamma(t)\) 是迭代 \(t\) 時模型引數的步長,它在每個步驟中透過公式 \(\gamma(t) = \gamma_0 (1 + \lambda \gamma_0 t) ^ {-c}\) 遞減
    • \(Q_i\) 是 SVM 任務中編號為 \(i\) 的樣本的目標函式,該樣本在演算法的每個步驟中隨機選擇。
  • ASGD 是平均隨機梯度下降 SVM 分類器。ASGD 分類器在演算法的每個步驟中透過公式 \(\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\) 平均權重向量

推薦的模型型別是 ASGD(參見 [36])。

裕度型別可以具有以下值之一: SOFT_MARGINHARD_MARGIN

  • 如果您有線性可分離集,則應使用 HARD_MARGIN 型別。
  • 如果您有非線性可分離集或含有異常值的集,則應使用 SOFT_MARGIN 型別。
  • 在一般情況下(如果您對集合的線性可分離性一無所知),請使用 SOFT_MARGIN。

其他引數可描述如下

  • 裕度正則化引數負責每一步的權重遞減以及對異常值的限制強度(引數越小,異常值被忽略的可能性越小)。SGD 模型的推薦值為 0.0001,ASGD 模型的推薦值為 0.00001。
  • 初始步長引數是步長 \(\gamma(t)\) 的初始值。您需要為您的問題找到最佳初始步長。
  • 步長遞減冪是根據上述公式遞減 \(\gamma(t)\) 的冪引數。SGD 模型的推薦值為 1,ASGD 模型的推薦值為 0.75。
  • 終止條件可以是 TermCriteria::COUNTTermCriteria::EPSTermCriteria::COUNT + TermCriteria::EPS。您需要為您的問題找到最佳終止條件。

請注意,引數裕度正則化、初始步長和步長遞減冪應為正值。

要使用 SVMSGD 演算法,請按以下步驟操作

// 建立空物件
// 訓練隨機梯度下降 SVM
svmsgd->train(trainData);
// 預測新樣本的標籤
svmsgd->predict(samples, responses);
static Ptr< SVMSGD > create()
建立空模型。使用 StatModel::train 訓練模型。由於 SVMSGD 有多個引數,...
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23

成員列舉文件

◆ 裕度型別

裕度型別。

列舉器
SOFT_MARGIN 

一般情況,適用於非線性可分離集的情況,允許異常值。

HARD_MARGIN 

對於線性可分離集的情況更準確。

◆ Svmsgd型別

SVMSGD 型別。ASGD 通常是首選。

列舉器
SGD 

隨機梯度下降。

ASGD 

平均隨機梯度下降。

成員函式文件

◆ create()

static Ptr< SVMSGD > cv::ml::SVMSGD::create ( )
static
Python
cv.ml.SVMSGD.create() -> retval
cv.ml.SVMSGD_create() -> retval

建立空模型。使用 StatModel::train 訓練模型。由於 SVMSGD 有多個引數,您可能需要為問題找到最佳引數,或使用 setOptimalParameters() 設定一些預設引數。

◆ getInitialStepSize()

virtual float cv::ml::SVMSGD::getInitialStepSize ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getInitialStepSize() -> retval

SVMSGD 最佳化問題的 initialStepSize 引數。

另請參見
setInitialStepSize

◆ getMarginRegularization()

virtual float cv::ml::SVMSGD::getMarginRegularization ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getMarginRegularization() -> retval

SVMSGD 最佳化問題的 marginRegularization 引數。

另請參見
setMarginRegularization

◆ getMarginType()

virtual int cv::ml::SVMSGD::getMarginType ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getMarginType() -> retval

裕度型別,SVMSGD::MarginType 之一。

另請參見
setMarginType

◆ getShift()

virtual float cv::ml::SVMSGD::getShift ( )
純虛擬函式
Python
cv.ml.SVMSGD.getShift() -> retval
返回
訓練模型的偏移量(決策函式 f(x) = 權重 * x + 偏移)。

◆ getStepDecreasingPower()

virtual float cv::ml::SVMSGD::getStepDecreasingPower ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getStepDecreasingPower() -> retval

SVMSGD 最佳化問題的 stepDecreasingPower 引數。

另請參見
setStepDecreasingPower

◆ getSvmsgdType()

virtual int cv::ml::SVMSGD::getSvmsgdType ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getSvmsgdType() -> retval

演算法型別,SVMSGD::SvmsgdType 之一。

另請參見
setSvmsgdType

◆ getTermCriteria()

virtual TermCriteria cv::ml::SVMSGD::getTermCriteria ( ) const
純虛擬函式
Python
cv.ml.SVMSGD.getTermCriteria() -> retval

訓練演算法的終止條件。您可以指定最大迭代次數 (maxCount) 和/或迭代之間錯誤變化的程度,以使演算法繼續執行 (epsilon)。

另請參見
setTermCriteria

◆ getWeights()

virtual Mat cv::ml::SVMSGD::getWeights ( )
純虛擬函式
Python
cv.ml.SVMSGD.getWeights() -> retval
返回
訓練模型的權重(決策函式 f(x) = 權重 * x + 偏移)。

◆ load()

static Ptr< SVMSGD > cv::ml::SVMSGD::load ( const String & filepath,
const String & nodeName = String() )
static
Python
cv.ml.SVMSGD.load(filepath[, nodeName]) -> retval
cv.ml.SVMSGD_load(filepath[, nodeName]) -> retval

從檔案中載入並建立一個序列化的 SVMSGD

使用 SVMSGD::saveSVMSGD 序列化並存儲到磁碟。透過使用檔案路徑呼叫此函式,再次從該檔案載入 SVMSGD。可選地指定包含分類器的檔案節點

引數
filepath序列化 SVMSGD 的路徑
nodeName包含分類器的節點的名稱

◆ setInitialStepSize()

virtual void cv::ml::SVMSGD::setInitialStepSize ( float InitialStepSize)
純虛擬函式
Python
cv.ml.SVMSGD.setInitialStepSize(InitialStepSize) ->

SVMSGD 最佳化問題的 initialStepSize 引數。

另請參見
getInitialStepSize

◆ setMarginRegularization()

virtual void cv::ml::SVMSGD::setMarginRegularization ( float marginRegularization)
純虛擬函式
Python
cv.ml.SVMSGD.setMarginRegularization(marginRegularization) ->

SVMSGD 最佳化問題的 marginRegularization 引數。

另請參見
getMarginRegularization

◆ setMarginType()

virtual void cv::ml::SVMSGD::setMarginType ( int marginType)
純虛擬函式
Python
cv.ml.SVMSGD.setMarginType(marginType) ->

裕度型別,SVMSGD::MarginType 之一。

另請參見
getMarginType

◆ setOptimalParameters()

virtual void cv::ml::SVMSGD::setOptimalParameters ( int svmsgdType = SVMSGD::ASGD,
int marginType = SVMSGD::SOFT_MARGIN )
純虛擬函式
Python
cv.ml.SVMSGD.setOptimalParameters([, svmsgdType[, marginType]]) ->

此函式為所選的 SVM SGD 模型設定最佳引數值。

引數
svmsgdTypeSVMSGD 分類器的型別。
marginType是裕度約束的型別。

◆ setStepDecreasingPower()

virtual void cv::ml::SVMSGD::setStepDecreasingPower ( float stepDecreasingPower)
純虛擬函式
Python
cv.ml.SVMSGD.setStepDecreasingPower(stepDecreasingPower) ->

SVMSGD 最佳化問題的 stepDecreasingPower 引數。

另請參見
getStepDecreasingPower

◆ setSvmsgdType()

virtual void cv::ml::SVMSGD::setSvmsgdType ( int svmsgdType)
純虛擬函式
Python
cv.ml.SVMSGD.setSvmsgdType(svmsgdType) ->

演算法型別,SVMSGD::SvmsgdType 之一。

另請參見
getSvmsgdType

◆ setTermCriteria()

virtual void cv::ml::SVMSGD::setTermCriteria ( const cv::TermCriteria & val)
純虛擬函式
Python
cv.ml.SVMSGD.setTermCriteria(val) ->

訓練演算法的終止條件。您可以指定最大迭代次數 (maxCount) 和/或迭代之間錯誤變化的程度,以使演算法繼續執行 (epsilon)。

另請參見
getTermCriteria

此類的文件是從以下檔案生成的