【理論】object detection api調參詳解(兼SSD算法參數詳解)


一、引言

使用谷歌提供的object detection api圖像識別框架,我們可以很方便地重新訓練一個預訓練模型,用於自己的具體業務。以我所使用的ssd_mobilenet_v1預訓練模型為例,訓練所需參數都在training文件夾下的ssd_mobilenet_v1_coco.config中預先配置了,只需對少量路徑參數做修改即可。

 

但是這種“傻瓜式”的訓練參數配置方法有很大不足。一是無法理解訓練參數背后的原理,不利於技術積累;二是一旦遇到需要優化的問題時,不知道如何調整訓練參數。例如,我使用默認配置的訓練參數對模型進行長期訓練后,發現模型始終無法收斂,loss值一直在3~5的范圍內波動,沒有繼續下降。但在沒有弄清楚訓練參數如何調整之前,我一直沒能解決該問題。

 

所以,我們必須弄清楚每個訓練參數的出處、含義、數值調整范圍,才能自行對訓練文件做合理配置,從而靈活解決各類訓練問題。

 

本文以ssd_mobilenet_v1預訓練模型為例,詳細解釋其訓練參數的含義及調整范圍。對其它預訓練模型的訓練參數的分析方法類似,不再逐一展開。

 

二、正文

首先簡單解釋一下,object_detection api框架將訓練參數的配置、參數的可配置數值的聲明、參數類的定義,分開放置在不同文件夾里。訓練參數的配置放在了training文件夾下的.config文件中,參數的可配置數值的聲明寫在了protos文件夾下對應參數名的.proto文件中,參數類的定義則放在了object_detection總文件夾下對應參數名的子文件夾里或者是core文件夾里。

 

.config文件里包含5個部分:model, train_config, train_input_reader, eval_config, eval_input_reader。以ssd_mobilenet_v1_pets.config為例,打開該文件,按照從上到下、從外層到內層的順序,依次解釋各訓練參數。

 

2.1  model{ }

包含了ssd{ }。

 

2.1.1  ssd { }

包含了SSD算法使用的各類訓練參數。從2.1.2開始逐個展開解釋。

 

2.1.2  num_classes

分類數目。例如,我要把所有待檢測目標區分成6類,則這里寫6。

 

2.1.3  box_coder、faster_rcnn_box_coder

box_coder {

    faster_rcnn_box_coder {

        y_scale: 10.0

        x_scale: 10.0

        height_scale: 5.0

        width_scale: 5.0

    }

}

 

這部分參數用於設置box編解碼的方式。可選參數值:

    FasterRcnnBoxCoder faster_rcnn_box_coder = 1;

    MeanStddevBoxCoder mean_stddev_box_coder = 2;

    SquareBoxCoder square_box_coder = 3;

    KeypointBoxCoder keypoint_box_coder = 4;

 

SSD算法借鑒了Faster-RCNN的思想,所以這里的設置應該選faster_rcnn_box_coder。

 

Faster-RCNN中,bounding box的坐標值可以用兩種不同的坐標系表示:一種坐標系以圖片左上角作為原點,我稱其為絕對坐標系;另一種坐標系以用於參考的anchor boxes的中心點位置作為原點,我稱其為相對坐標系。

 

所謂box編碼就是以anchor box為參照系,將box的絕對坐標值和絕對尺寸,轉換為相對於anchor box的坐標值和尺寸。所謂box解碼就是將box的相對坐標值和相對尺寸,轉換回絕對坐標值和絕對尺寸。

 

在SSD算法中,anchor box的概念被叫做default box。box編解碼中的box,則是指預測框(predicted box,也叫做bounding box)和真實框(ground-truth box)。SSD中的box編碼,就是以default box為參照系,將predicted box和ground-truth box轉換為用相對於default box的數值來表示;SSD中的box解碼,則是將predicted box和ground-truth box轉換回用絕對坐標系數值表示。

 

faster_rcnn_box_coder的解釋詳見box_coders文件夾下的faster_rcnn_box_coder.py。重點分析這組轉換公式即可:

   ty = (y - ya) / ha

   tx = (x - xa) / wa

   th = log(h / ha)

   tw = log(w / wa)

( x, y, w, h是待編碼box的中心點坐標值、寬、高;xa, ya, wa, ha是anchor box的中心點坐標值、寬、高; tx, ty, tw, th則是編碼后的相對中心點坐標值、寬、高。在轉換中用除法實現了歸一化)

 

此處的y_scale、x_scale、height_scale、width_scale則是對ty、tx、th、tw的放大比率。

 

2.1.4  matcher、argmax_matcher

matcher {

    argmax_matcher {

        matched_threshold: 0.5

        unmatched_threshold: 0.5

        ignore_thresholds: false

        negatives_lower_than_unmatched: true

        force_match_for_each_row: true

    }

}

 

這部分參數用於設置default box和ground-truth box之間的匹配策略。  

 

可選參數值:

    ArgMaxMatcher argmax_matcher = 1;

    BipartiteMatcher bipartite_matcher = 2;

 

SSD算法中,采用了ArgMaxMatcher策略,所以這里選擇argmax_matcher。所謂ArgMaxMatcher策略,就是選取最大值策略。在matchers文件夾的argmax_matcher.py里有詳細解釋。

 

在SSD算法中,用default box和ground-truth box的IOU值(一種定量的相似度)來作為閾值標准,設置了matched_threshold、unmatched_threshold兩個閾值。分為三種子情況:

(1) 當IOU >= matched_threshold時:default box和ground-truth box匹配,default box記為正樣本。

(2) 當IOU < unmatched_threshold時:default box和ground-truth box不匹配。引入另一個參數negatives_lower_than_unmatched。negatives_lower_than_unmatched=true時:所有不匹配default box記為負樣本;negatives_lower_than_unmatched=false時:所有不匹配default box被忽略。

(3) 當matched_threshold > IOU >= matched_threshold時:記為中間態,並引入另一個參數negatives_lower_than_unmatched。negatives_lower_than_unmatched=true時:所有中間態default box被忽略;negatives_lower_than_unmatched=false時:所有中間態default box被記為負樣本。上述參數例中兩個閾值都是0.5,故沒有中間態。

 

ignore_thresholds: 沒有找到具體解釋。應該是顯式地指定是否單獨設置ignore閾值。

 

force_match_for_each_row:設置為true,以確保每個ground-truth box都至少有一個default box與之對應,防止有些ground-truth沒有default box對應。否則,這些ground-truth box最后將沒有bounding box回歸對應,也就是產生了漏檢。

 

在SSD算法中,將所有ground-truth box按行排列、將所有default box按列排列,形成一個矩陣。矩陣的每一格記錄ground-truth box和default box的匹配結果。匹配分兩步:

(1) 對每行的ground-truth box,采用ArgMax策略,選擇與它的IOU最大的default box進行匹配;

(2) 對剩余的每一個沒有匹配到ground-truth box的default box,選擇所有與它的IOU大於match threshold的ground-truth box進行匹配。

 

這樣,每個ground-truth box至少有一個default box與它匹配。

 

2.1.5  similarity_calculator、iou_similarity    

similarity_calculator {

    iou_similarity {

    }

}

 

這個參數選擇使用何種相似度計算標准。在匹配過程中,用default box和ground-truth box的相似度來判斷二者是否匹配。在2.1.4小節中,已經解釋了SSD算法是采用IOU值來定量衡量相似度的,故這里選擇數值iou_similarity。

 

2.1.6  anchor_generator、ssd_anchor_generator

anchor_generator {

    ssd_anchor_generator {

        num_layers: 6

        min_scale: 0.2

        max_scale: 0.95

        aspect_ratios: 1.0

        aspect_ratios: 2.0

        aspect_ratios: 0.5

        aspect_ratios: 3.0

        aspect_ratios: 0.3333

    }

}

 

這部分選擇anchor box的生成器(一組生成公式),配置了生成器所需的部分參數。

 

Anchor box的生成器可以有如下選擇:

    GridAnchorGenerator grid_anchor_generator = 1;

    SsdAnchorGenerator ssd_anchor_generator = 2;

    MultiscaleAnchorGenerator multiscale_anchor_generator = 3;

 

ssd_anchor_generator這部分設置了生成default box所需的一些參數。詳細解釋可參考SSD的論文。這里只解釋一下各參數的基本含義。

 

num_layers: 數值為6,代表提取特征用的6個層。SSD算法借鑒了特征金字塔的思想,從6個feature map層同步提取特征。

 

min_scale和max_scale:我目前的理解是:scale是同層的default boxes中的小正方形寬相對於resize的輸入圖像寬的比率。在SSD論文中,min_scale是指該比率在最低層feature map的值,max_scale是指該比率在最高層feature map的值。至於中間4層feature map上的比率值,論文中是以線性插值的方式來獲得的(但參考代碼中不是這樣確定各層比率的)。

 

aspect_ratios:指定了同一個feature map層上的default box的寬長比。例如,這里aspect ratios指定了5種寬長比,利用圖1的公式(Sk: scale*resize width; ar: aspect_ratios)可以計算出6種不同寬長的default boxes(包括2種正方形、4種長方形)。注意:某些feature map層不使用3和1/3這一對aspect_ratios,故只生成4個default boxes。詳細解釋可參考SSD的論文。

圖1——default box寬長計算公式

 

2.1.7  image_resizer、fixed_shape_resizer

image_resizer {

    fixed_shape_resizer {

     height: 300

     width: 300

    }

}

 

這部分參數設置了對輸入圖像的resize策略。可選參數:

    KeepAspectRatioResizer keep_aspect_ratio_resizer = 1;

    FixedShapeResizer fixed_shape_resizer = 2;

 

傳統SSD300模型中,輸入圖像被統一resize為300*300。故這里選擇fixed_shape_resizer,且height和width均設置為300。

 

2.1.8  box_predictor

box_predictor {

    convolutional_box_predictor {

        min_depth: 0

        max_depth: 0

        num_layers_before_predictor: 0

        use_dropout: false

        dropout_keep_probability: 0.8

        kernel_size: 1

        box_code_size: 4

        apply_sigmoid_to_scores: false

        conv_hyperparams {

            activation: RELU_6,

            regularizer {

                l2_regularizer {

                    weight: 0.00004

                }

            }

            initializer {

                truncated_normal_initializer {

                    stddev: 0.03

                    mean: 0.0

                }

            }

            batch_norm {

                train: true,

                scale: true,

                center: true,

                decay: 0.9997,

                epsilon: 0.001,

            }

        }

    }

}

 

這部分設置了預測器相關層的參數。

 

關於Box predictor的解釋詳見core文件夾下的box_predictor.py。Box predictors輸入高層的feature map,輸出兩類預測:(1)編碼后的predicted box的相對位置;(2)predicted box里的物體類別。

 

Box predictor的可選參數范圍:

    ConvolutionalBoxPredictor convolutional_box_predictor = 1;

    MaskRCNNBoxPredictor mask_rcnn_box_predictor = 2;

    RfcnBoxPredictor rfcn_box_predictor = 3;

    WeightSharedConvolutionalBoxPredictor weight_shared_convolutional_box_predictor = 4;

 

這些參數值的具體定義詳見predictors文件夾。這里選用了convolutional_box_predictor,其含義是在所有feature maps后額外增加一個中間1x1卷積層。選擇原因不明

 

關於convolutional_box_predictor{ }內的許多參數的含義及數值范圍,詳見protos文件夾下的box_predictor.proto文件。下面逐個簡單說明一下。

 

min_depth和max_depth:在位置回歸和類別檢測之前額外插入的feature map層深度的最小值和最大值。當max_depth=0時,表示在位置回歸和類別檢測之前,額外插入的feature map層數=0。

 

num_layers_before_predictor:在檢測器之前的額外convolutional層的層數。

 

use_dropout:對class prediction是否使用dropout來防止過擬合。

 

dropout_keep_probability:如果使用了dropout,dropout的數值保留概率。

 

kernel_size:最后的卷積核的尺寸。

 

box_code_size:我的理解是box需要編碼的參數個數。SSD算法里是cx, cy, w, h這4個參數需要編碼,所以box_code_size=4。

 

apply_sigmoid_to_scores:最后class prediction輸出時是否采用sigmoid。

 

conv_hyperparams{ }:卷積操作超參數的設置。詳見protos文件夾里的hyperparams.proto。

 

activation:激活函數。目前可以選擇NONE、RELU、RELU_6。這里選擇了RELU_6。關於激活函數的細節,請自行查閱資料。

 

regularizer:正則化操作。目前可以選擇l1_regularizer、l2_regularizer。這里選擇了l2_regularizer。例子里L2_regularizer的weight值只有0.00004,所以正則化操作對loss的影響較小。關於L1正則化、L2正則化的細節,請自行查閱資料。

 

Initializer{ }:隨機數初始化機制設置。可選參數如下:

TruncatedNormalInitializer truncated_normal_initializer = 1;

VarianceScalingInitializer variance_scaling_initializer = 2;

RandomNormalInitializer random_normal_initializer = 3; 

這里選擇了truncated_normal_initializer。

 

truncated_normal_initializer:截斷的正態分布隨機數初始化機制。如果數值超過mean兩個stddev,則丟棄。

 

batch_norm{ }:關於Batch Normalization(批標准化)的一些參數設置。Batch Normalization可以強制將輸入激活函數的數值分布拉回標准正態分布,以防止訓練過程中產生反向梯度消失,加速訓練收斂。批標准化中會用到兩個參數γ和β,分別定量化縮放和平移操作。細節請自行參閱相關資料。這里解釋一下batch_norm的一些參數::

train: true——如果為true,則在訓練過程中batch norm變量的值會更新,也就是得到了訓練。如果為false,則在訓練過程中batch norm變量的值不會更新。

scale: true——如果為true,則乘以γ;如果為false,則不使用γ。

center: true——如果為true,則加上β的偏移量;如果為false,則忽略β。

decay: 0.9997——衰減率。作用存疑

epsilon: 0.001——添加到方差的小浮點數,以避免除以零。

 

2.1.9  feature_extractor

feature_extractor {

    type: 'ssd_mobilenet_v1'

    min_depth: 16

    depth_multiplier: 1.0

    conv_hyperparams {

    activation: RELU_6,

        regularizer {

            l2_regularizer {

                weight: 0.00004

            }

        }

        initializer {

            truncated_normal_initializer {

                stddev: 0.03

                mean: 0.0

            }

        }

        batch_norm {

            train: true,

            scale: true,

            center: true,

            decay: 0.9997,

            epsilon: 0.001,

        }

    }

}

 

這部分設置了特征提取器相關層的參數。

 

不同模型的feature extractor的基類定義,詳見meta_architectures文件夾下的對應文件。例如SSD模型的SSDFeatureExtractor基類,定義在meta_architectures文件夾下的ssd_meta_arch.py文件里。

 

不同預訓練模型的feature extractor的類定義,詳見models文件夾下的對應文件。例如ssd_mobilenet_v1預訓練模型的feature extractor類,定義在models文件夾下的

ssd_mobilenet_v1_feature_extractor.py文件里。

 

models文件夾下的feature extractor類,是meta_architectures文件夾下的feature extractor基類的子類。

 

下面解釋一下相關參數。

type:例子中使用了預訓練模型ssd_moiblenet_v1的feature_extractor,所以這里填寫'ssd_mobilenet_v1'。

 

min_depth:最小的特征提取器的深度。這里填16。原因不明

 

depth_multiplier:是施加在每個input通道上的卷積核的數目。用於計算深度卷積分離后的輸出通道總數。這里是一個浮點數

 

conv_hyperparams超參數的含義和配置同2.1.8小節,不再重復解釋。

 

2.1.10  loss

loss {

    classification_loss {

        weighted_sigmoid {

        }

    }

    localization_loss {

        weighted_smooth_l1 {

        }

    }

    hard_example_miner {

        num_hard_examples: 3000

        iou_threshold: 0.99

        loss_type: CLASSIFICATION

        max_negatives_per_positive: 3

        min_negatives_per_image: 0

    }

    classification_weight: 1.0

    localization_weight: 1.0

}

 

這部分設置了損失函數loss相關的參數。

 

loss{ }可選參數:

  // Localization loss to use.

  optional LocalizationLoss localization_loss = 1;

  // Classification loss to use.

  optional ClassificationLoss classification_loss = 2;

  // If not left to default, applies hard example mining.

  optional HardExampleMiner hard_example_miner = 3;

  // Classification loss weight.

  optional float classification_weight = 4 [default=1.0];

  // Localization loss weight.

  optional float localization_weight = 5 [default=1.0];

  // If not left to default, applies random example sampling.

  optional RandomExampleSampler random_example_sampler = 6;

 

SSD算法的loss分為目標分類損失函數(classification loss)和目標位置損失函數(localization loss),loss公式詳見SSD論文。SSD算法也使用了某種難樣本挖掘策略用於平衡正負樣本比例。所以這里設置了classification_loss、localization_loss、hard_example_miner、classification_weight、localization_weight這5個參數。

 

下面解釋一下這5個參數的具體配置。

 

classification_loss:可選參數:

    WeightedSigmoidClassificationLoss weighted_sigmoid = 1;

    WeightedSoftmaxClassificationLoss weighted_softmax = 2;

    WeightedSoftmaxClassificationAgainstLogitsLoss weighted_logits_softmax = 5;

    BootstrappedSigmoidClassificationLoss bootstrapped_sigmoid = 3;

    SigmoidFocalClassificationLoss weighted_sigmoid_focal = 4;

定義了分類輸出的激活函數。具體含義請自行查閱資料。這里的設置和前面Box predictor部分的apply_sigmoid_to_scores設置是否有沖突,暫時沒能確認

 

localization_loss:可選參數:

    WeightedL2LocalizationLoss weighted_l2 = 1;

    WeightedSmoothL1LocalizationLoss weighted_smooth_l1 = 2;

    WeightedIOULocalizationLoss weighted_iou = 3;

定義了用於localization loss的正則化方法。具體含義請自行查閱資料。這里的設置和前面Box predictor部分的正則化設置是否有沖突,暫時沒能確認

 

hard_example_miner:難樣本挖掘策略。SSD算法隨機抽取一定數量的負樣本(背景位置的default boxes),按一定規則進行降序排列,選擇前k個作為訓練用負樣本,以保證訓練時的正負樣本比例接近1:3。下面解釋一下它的具體子參數含義。

num_hard_examples: 3000——難樣本數目。

iou_threshold: 0.99——在NMS(非極大抑制)階段,如果一個example的IOU值比此閾值低,則丟棄。

loss_type: CLASSIFICATION——挖掘策略是否只使用classification loss,或只使用localization loss,或都使用。可選參數:

    BOTH = 0; (缺省選擇?)

    CLASSIFICATION = 1; (缺省選擇?)

    LOCALIZATION = 2;

max_negatives_per_positive: 3——每1個正樣本對應的最大負樣本數。

min_negatives_per_image: 0——如何設置存疑。我目前的理解:在圖片沒有正樣本的極端情況下,如果把這個值設置為一個正數,可以避免模型在圖片上檢測出目標來,防止了誤檢出。

 

classification_weight:用於配置classifiation loss在總loss中的權重。

 

localization_weight:用於配置localization loss在總loss中的權重。

 

2.1.11  normalize_loss_by_num_matches

我的理解:如果選true,則根據匹配的樣本數目歸一化總loss,也就是總loss公式中,用加權的classification loss和加權的localization loss計算出總loss后,還要再除以一個正樣本總數N。如果選false,則計算出總loss后,不用再除以正樣本總數N。

 

2.1.12  post_processing

post_processing {

    batch_non_max_suppression {

        score_threshold: 1e-8

        iou_threshold: 0.6

        max_detections_per_class: 100

        max_total_detections: 100

    }

    score_converter: SIGMOID

}

 

這部分配置了SSD算法的后處理階段的參數。下面逐一解釋。

 

batch_non_max_suppression{ }:這部分配置了批次的NMS(非極大抑制)策略的參數。先簡單解釋下NMS策略的目的。以目標檢測為例,在最后階段,一個目標上可能有很多個bounding box,但是最終目標檢測框只有一個。因此,我們可以用NMS策略,逐次過濾掉其余的bounding box,最終只保留一個bounding box作為結果。關於NMS算法請自行參閱相關資料。下面簡單解釋一下具體參數含義:

score_threshold: 1e-8——分數低於此閾值的box被過濾掉(去除非極大分數的)。

iou_threshold: 0.6——和之前選擇的box的IOU值超過此閾值的box被過濾掉(去除重疊度高的)

max_detections_per_class: 100——每個類別可保留的檢測框的最大數目。

max_total_detections: 100——所有類別可保留的檢測框的最大數目。

 

score_converter:檢測分數的轉換器類型選擇。可選參數:

    // Input scores equals output scores.

    IDENTITY = 0;

    // Applies a sigmoid on input scores.

    SIGMOID = 1;

    // Applies a softmax on input scores.

    SOFTMAX = 2;

 

2.2  train_config{ }

訓練用參數的配置。詳見protos文件夾下的train.proto。下面解釋.config例中的參數。

 

2.2.1  batch_size

每個批次的訓練樣本數。一般是2的冪次方。我只有CPU資源,所以batch_size設置比較小。

 

2.2.2  optimizer{ }

優化器的參數配置部分。

 

由於優化器的配置很關鍵,所以這部分想更詳細展開一些。首先介紹一下參數的含義及可選范圍,然后分別貼兩個優化器配置的例子。

 

目前可選的優化器參數:

    RMSPropOptimizer rms_prop_optimizer

    MomentumOptimizer momentum_optimizer

    AdamOptimizer adam_optimizer

關於這三種優化器的特性,可自行參閱相關資料。

 

rms_prop_optimizer的可選參數:

 LearningRate learning_rate = 1;

 float momentum_optimizer_value = 2 [default = 0.9];

 float decay = 3 [default = 0.9];

 float epsilon = 4 [default = 1.0];

 

momentum_optimizer的可選參數:

 LearningRate learning_rate = 1;

 float momentum_optimizer_value = 2 [default = 0.9];

 

adam_optimizer的可選參數:

 LearningRate learning_rate = 1;

 

學習率learning_rate的可選參數:

 ConstantLearningRate constant_learning_rate = 1;

 ExponentialDecayLearningRate exponential_decay_learning_rate = 2;

 ManualStepLearningRate manual_step_learning_rate = 3;

 CosineDecayLearningRate cosine_decay_learning_rate = 4;

解釋如下:

constant_learning_rate:恆定學習率。恆定學習率太小則收斂很慢;太大則在極值附近震盪難以收斂。故一般不會使用。

exponential_decay_learning_rate:學習率按照指數規律衰減。下面會展開並舉例(例1)。

manual_step_learning_rate:學習率按照人工設置的step逐段變小。下面會展開並舉例(例2)。

cosine_decay_learning_rate:學習率按照噪聲線性余弦規律衰減。

 

exponential_decay_learning_rate可選參數:

    float initial_learning_rate [default = 0.002];

    uint32 decay_steps [default = 4000000];

    float decay_factor [default = 0.95];

    bool staircase [default = true];

    float burnin_learning_rate [default = 0.0];

    uint32 burnin_steps [default = 0];

    float min_learning_rate [default = 0.0];

簡單解釋如下:

initial_learning_rate:初始學習率數值。

decay_steps:衰減周期。即每隔decay_steps步衰減一次學習率。下面例1中寫的是800720步,而總的訓練步數不過才200000步,顯然decay_steps的設置偏大了,導致在整個訓練過程中,學習率實際上沒有任何指數衰減。這個設置不合理。

decay_factor:每次衰減的衰減率。

staircase:是否階梯性更新學習率,也就是每次衰減結果是向下取整還是float型。

burnin_learning_rate:采用burnin策略進行調整的學習率(初始值?)。SSD算法中,是否有burnin策略、buinin策略又是如何調整學習率的,目前我還不太清楚。存疑。參考:在yolov3所用的darknet中,當學習率更新次數小於burnin參數時,學習率從小到大變化;當更新次數大於burnin參數后,學習率按照配置的衰減策略從大到小變化。

burnin_steps:按照字面意思,是burnin策略的調整周期。即每隔burnin_steps步調整一次burnin_learning_rate。

min_learning_rate:最小學習率。采用衰減策略變小的學習率不能小於該值。

 

manual_step_learning_rate可選參數:

    float initial_learning_rate = 1 [default = 0.002];

    message LearningRateSchedule {

      optional uint32 step = 1;

      optional float learning_rate = 2 [default = 0.002];

    }

    repeated LearningRateSchedule schedule = 2;

    optional bool warmup = 3 [default = false];

簡單解釋如下:

initial_learning_rate:初始學習率數值。

schedule:人工規划策略。包含兩個參數:

step——當前階梯從全局的第step步開始。

learning_rate——當前階梯的學習率。

warmup:對於全局步數區間[0, schedule.step]之間的steps,是否采用線性插值法來確定steps對應的學習率。缺省是false。

 

優化器還有3個獨立參數:

momentum_optimizer_value: momentum超參數。通過引入這個超參數(公式中一般記為γ),可以使得優化在梯度方向不變的維度上的更新速度變快,在梯度方向有所改變的維度上的更新速度變慢,從而加快收斂並減小震盪。

decay:衰減率。含義和出處不明

epsilon:可能是迭代終止條件。

 

優化器配置例1:

優化器使用rms_prop_optimizer。

采用指數衰減策略來調整學習率。

optimizer {

    rms_prop_optimizer: {

        learning_rate: {

            exponential_decay_learning_rate {

                initial_learning_rate: 0.0001

                decay_steps: 800720

                decay_factor: 0.95

            }

        }

        momentum_optimizer_value: 0.9

        decay: 0.9

        epsilon: 1.0

    }

}

 

優化器配置例2:

優化器使用momentum_optimizer。

采用人工設置下降階梯的策略來調整學習率。

use_moving_average:設為false表示保存模型參數時,不使用moving average策略。moving average(移動平均)是一種保存模型參數的策略,會對不同迭代次數的模型的參數進行平均后再保存。

optimizer {

    momentum_optimizer: {

        learning_rate: {

            manual_step_learning_rate {

                initial_learning_rate: 0.0002

                schedule {

                    step: 1

                    learning_rate: .0002

                }

                schedule {

                    step: 900000

                    learning_rate: .00002

                }

                schedule {

                    step: 1200000

                    learning_rate: .000002

                }

            }

        }

        momentum_optimizer_value: 0.9

    }

    use_moving_average: false

}

 

2.2.3  fine_tune_checkpoint

用於設置預訓練模型的參數文件model.ckpt的路徑。該參數文件用於精調。當訓練開始時,導入已預訓練好的模型參數,可以縮短訓練過程。從零開始訓練時,由於沒有預訓練模型的參數文件,故可以屏蔽這個路徑參數。

 

2.2.4  from_detection_checkpoint

此參數已被廢棄,使用fine_tune_checkpoint_type替代。

 

fine_tune_checkpoint_type:用來確定fine tune checkpoint使用的是分類模型參數還是檢測模型參數。可選參數值:“”,“classification”,“detection”。 

 

2.2.5  load_all_detection_checkpoint_vars

用於確定是否導入所有和模型變量名字和大小相符的detection checkpoint變量。只在使用檢測模型時有效。

 

2.2.6  num_steps

訓練總步數。如果設置為0,則訓練步數為無窮大。

 

2.2.7  data_augmentation_options

數據增強參數配置。可選參數詳見protos文件夾下的preprocessor.proto。

這個例子里數據增強使用了兩個具體參數:

random_horizontal_flip——隨機水平翻轉。

ssd_random_crop——SSD算法圖像隨機裁剪。

 

2.3  train_input_reader{ }

訓練集數據的路徑配置。可選參數詳見protos文件夾下的input_reader.proto。

 

2.3.1  tf_record_input_reader、input_path

訓練用tf_record格式數據集的路徑配置。

 

2.3.2  label_map_path

labelmap.pbtxt文件的路徑配置。labelmap.pbtxt文件定義了待分類目標的id號和標簽名稱之間的映射關系。

 

2.4  eval_config{ }

測試用參數的配置。可選參數詳見protos文件夾下的eval.proto。

 

2.4.1  metrics_set

用於配置評估模型性能的標准。

可選參數詳見框架總目錄下eval_util.py里的EVAL_METRICS_CLASS_DICT。目前有8種。

例子中使用的是coco_detection_metrics, 是使用coco數據集進行目標檢測時評估模型性能的標准。

 

2.4.2  num_examples

測試樣本數目。

 

2.5  eval_input_reader{ }

測試集數據的路徑配置。可選參數詳見protos文件夾下的input_reader.proto。

 

2.5.1  tf_record_input_reader、input_path

測試用tf_record格式數據集的路徑配置。

 

2.5.2  label_map_path

同2.3.2節。

 

2.5.3  shuffle

隨機排序操作配置。如果選false,則對測試樣本不進行隨機排序操作。

 

2.5.4  num_readers

用於配置可並行讀入的文件分片的數目。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM