1. 程式人生 > 實用技巧 >Springboot 報錯 Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

Springboot 報錯 Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

一、引言

使用谷歌提供的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;

WeightSharedConvolutionalBoxPredictorweight_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.9feature_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.2train_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.6num_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.4eval_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.5eval_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

用於配置可並行讀入的檔案分片的數目。