OpenCV 4.13.0
開源計算機視覺庫 (Open Source Computer Vision)
正在載入...
正在搜尋...
未找到匹配項
cv::ml::SVMSGD 類引用抽象

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

#include <opencv2/ml.hpp>

cv::ml::SVMSGD 的協作圖

公開型別

enum  MarginType {
  SOFT_MARGIN ,
  HARD_MARGIN
}
 
enum  SvmsgdType {
  SGD ,
  ASGD
}
 
- 從 cv::ml::StatModel 繼承的公共型別
enum  標誌 {
  UPDATE_MODEL = 1 ,
  RAW_OUTPUT =1 ,
  COMPRESSED_INPUT =2 ,
  PREPROCESSED_INPUT =4
}
 

公開成員函式

virtual float getInitialStepSize () const =0
 SVMSGD 最佳化問題的初始步長引數。
 
virtual float getMarginRegularization () const =0
 SVMSGD 最佳化問題的邊距正則化引數。
 
virtual int getMarginType () const =0
 邊距型別,是 SVMSGD::MarginType 之一。
 
virtual float getShift ()=0
 
virtual float getStepDecreasingPower () const =0
 SVMSGD 最佳化問題的步長遞減冪引數。
 
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 最佳化問題的初始步長引數。
 
virtual void setMarginRegularization (float marginRegularization)=0
 SVMSGD 最佳化問題的邊距正則化引數。
 
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 最佳化問題的步長遞減冪引數。
 
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
 如果 Algorithm 為空(例如,在最開始或讀取不成功後),則返回 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 分類器實現,採用了隨機梯度下降方法,如 [37] 所述。

該分類器具有以下引數

  • 模型型別,
  • 邊距型別,
  • 邊距正則化( \(\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\) 是第 \(i\) 個樣本的 SVM 任務的目標函式,該樣本在演算法的每一步被隨機選擇。
  • ASGD 是平均隨機梯度下降 SVM 分類器。ASGD 分類器透過公式 \(\widehat{w}_{t+1} = \frac{t}{1+t}\widehat{w}_{t} + \frac{1}{1+t}w_{t+1}\) 對演算法每一步的權重向量進行平均。

推薦的模型型別為 ASGD(遵循 [37])。

邊距型別可以具有以下值之一: 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
定義 cvstd_wrapper.hpp:23

成員列舉文件

◆ MarginType

邊距型別。

列舉值 (Enumerator)
SOFT_MARGIN 

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

HARD_MARGIN 

對於線性可分資料集更準確。

◆ SvmsgdType

SVMSGD 型別。ASGD 通常是更優的選擇。

列舉值 (Enumerator)
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 最佳化問題的初始步長引數。

另請參閱
setInitialStepSize

◆ getMarginRegularization()

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

SVMSGD 最佳化問題的邊距正則化引數。

另請參閱
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) = weights * x + shift)的偏移量。

◆ getStepDecreasingPower()

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

SVMSGD 最佳化問題的步長遞減冪引數。

另請參閱
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) = weights * x + shift)的權重。

◆ 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) -> None

SVMSGD 最佳化問題的初始步長引數。

另請參閱
getInitialStepSize

◆ setMarginRegularization()

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

SVMSGD 最佳化問題的邊距正則化引數。

另請參閱
getMarginRegularization

◆ setMarginType()

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

邊距型別,是 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]]) -> None

該函式為選定的 SVM SGD 模型設定最優引數值。

引數
svmsgdTypeSVMSGD 分類器的型別。
marginType是邊距約束的型別。

◆ setStepDecreasingPower()

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

SVMSGD 最佳化問題的步長遞減冪引數。

另請參閱
getStepDecreasingPower

◆ setSvmsgdType()

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

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

另請參閱
getSvmsgdType

◆ setTermCriteria()

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

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

另請參閱
getTermCriteria

該類的文件由以下檔案生成: