Python 带有Mobilenets的Tensorflow对象检测API超过了自定义多类数据集
该模型过度拟合训练集,无法推广到测试集。Python 带有Mobilenets的Tensorflow对象检测API超过了自定义多类数据集,python,machine-learning,tensorflow,object-detection,Python,Machine Learning,Tensorflow,Object Detection,该模型过度拟合训练集,无法推广到测试集。 如何向模型的特征提取部分添加辍学?(该.config文件仅提供一个键值,用于向框预测器添加退出) 我还可以采取哪些其他措施来减少过度装配 以下详细信息: 我试图在玩具动物数据集上重新训练模型检查点“ssd_mobilenet_v1_coco_11_06_2017”。有14个类,每个类中有400-600个图像。网络以不到30k的步骤学习训练集。虽然我没有足够的经验来评估这一点,但在最初的训练之后,损失似乎仍然很不稳定 我通过将导出的图形应用于图像并手动
- 如何向模型的特征提取部分添加辍学?(该.config文件仅提供一个键值,用于向框预测器添加退出)
- 我还可以采取哪些其他措施来减少过度装配
- 将特征提取器和长方体预测器的l2_正则化器权重从0.00004增加到0.0001
- 设置框预测器
至使用_dropout
以启用20%的退出true
python train.py --logtostderr --train_dir=/home/X/TrainDir/Process --pipeline_config_path=/home/X/ssd_mobilenet_v1_coco.config
我的配置文件如下所示:
# SSD with Mobilenet v1 configuration for MSCOCO Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
ssd {
num_classes: 14
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
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
}
}
similarity_calculator {
iou_similarity {
}
}
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
}
}
image_resizer {
fixed_shape_resizer {
height: 300
width: 300
}
}
box_predictor {
convolutional_box_predictor {
min_depth: 0
max_depth: 0
num_layers_before_predictor: 0
use_dropout: true
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.0001
}
}
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 {
type: 'ssd_mobilenet_v1'
min_depth: 16
depth_multiplier: 1.0
conv_hyperparams {
activation: RELU_6,
regularizer {
l2_regularizer {
weight: 0.0001
}
}
initializer {
truncated_normal_initializer {
stddev: 0.03
mean: 0.0
}
}
batch_norm {
train: true,
scale: true,
center: true,
decay: 0.9997,
epsilon: 0.001,
}
}
}
loss {
classification_loss {
weighted_sigmoid {
anchorwise_output: true
}
}
localization_loss {
weighted_smooth_l1 {
anchorwise_output: true
}
}
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
}
normalize_loss_by_num_matches: true
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
}
}
}
train_config: {
batch_size: 8
optimizer {
rms_prop_optimizer: {
learning_rate: {
exponential_decay_learning_rate {
initial_learning_rate: 0.004
decay_steps: 800720
decay_factor: 0.95
}
}
momentum_optimizer_value: 0.9
decay: 0.9
epsilon: 1.0
}
}
fine_tune_checkpoint: "/home/X/tensorflow/models/research/object_detection/ssd_mobilenet_v1_coco_11_06_2017/model.ckpt"
from_detection_checkpoint: true
# Note: The below line limits the training process to 200K steps, which we
# empirically found to be sufficient enough to train the pets dataset. This
# effectively bypasses the learning rate schedule (the learning rate will
# never decay). Remove the below line to train indefinitely.
num_steps: 200000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
ssd_random_crop {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "/home/X/TrainDir/train.record"
}
label_map_path: "/home/X/TrainDir/data_label_map.pbtxt"
}
eval_config: {
num_examples: 1200
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 30
}
eval_input_reader: {
tf_record_input_reader {
input_path: "/home/X/TrainDir/test.record"
}
label_map_path: "/home/X/TrainDir/data_label_map.pbtxt"
shuffle: false
num_readers: 1
num_epochs: 1
}
您是否尝试过设置验证集,并在使用部分训练模型进行训练的同时自动运行评估?如果验证精度尚未收敛,那么您可能只需要对模型进行更长时间的训练 其他需要注意的事项:在“好”和“坏”测试集之间还有其他区别吗?例如分辨率/纵横比。您是否正确地遵循了培训期间执行的所有预处理步骤?例如,数据标准化、使用相同算法调整大小等
编辑:我查看了你的张力板截图,你认为网络为什么学习了你的训练集?看来损失并没有真正趋同。另外一件你应该做的事情是设置一个调度程序,以减少你的学习除以10,比如说每40K步,在学习了一些特征之后,你的梯度下降可能会出现收敛困难,因为你从未改变起始值的学习率,而且对于训练中的那个时间点来说,它可能太大了 在一些技巧之后,网络学得很好,并开始在好的测试集上推广
- 我把每5000步的学习率衰减10%计算在内(这已经帮了不少忙)
- 我在玩具动物的训练集中增加了10%的同类真实动物的额外图像。这大大改进了推广
- 长期培训进一步改善了结果
- 我将正则化和box_预测值保留为其原始值
# SSD with Mobilenet v1 configuration for MSCOCO Dataset.
# Users should configure the fine_tune_checkpoint field in the train config as
# well as the label_map_path and input_path fields in the train_input_reader and
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that
# should be configured.
model {
ssd {
num_classes: 14
box_coder {
faster_rcnn_box_coder {
y_scale: 10.0
x_scale: 10.0
height_scale: 5.0
width_scale: 5.0
}
}
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
}
}
similarity_calculator {
iou_similarity {
}
}
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
}
}
image_resizer {
fixed_shape_resizer {
height: 300
width: 300
}
}
box_predictor {
convolutional_box_predictor {
min_depth: 0
max_depth: 0
num_layers_before_predictor: 0
use_dropout: true
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,
}
}
}
}
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,
}
}
}
loss {
classification_loss {
weighted_sigmoid {
anchorwise_output: true
}
}
localization_loss {
weighted_smooth_l1 {
anchorwise_output: true
}
}
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
}
normalize_loss_by_num_matches: true
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
}
}
}
train_config: {
batch_size: 8
optimizer {
rms_prop_optimizer: {
learning_rate: {
exponential_decay_learning_rate {
initial_learning_rate: 0.004
decay_steps: 7000
decay_factor: 0.75
}
}
momentum_optimizer_value: 0.9
decay: 0.9
epsilon: 1.0
}
}
fine_tune_checkpoint: "/home/sander/tensorflow/models/research/object_detection/ssd_mobilenet_v1_coco_11_06_2017/model.ckpt"
from_detection_checkpoint: true
# Note: The below line limits the training process to 200K steps, which we
# empirically found to be sufficient enough to train the pets dataset. This
# effectively bypasses the learning rate schedule (the learning rate will
# never decay). Remove the below line to train indefinitely.
num_steps: 200000
data_augmentation_options {
random_horizontal_flip {
}
}
data_augmentation_options {
ssd_random_crop {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "/home/sander/ROBOT/TrainDir/train.record"
}
label_map_path: "/home/sander/ROBOT/TrainDir/data_label_map.pbtxt"
}
eval_config: {
num_examples: 1200
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 30
}
eval_input_reader: {
tf_record_input_reader {
input_path: "/home/sander/ROBOT/TrainDir/test.record"
}
label_map_path: "/home/sander/ROBOT/TrainDir/data_label_map.pbtxt"
shuffle: false
num_readers: 1
num_epochs: 1
}
谢谢你的建议,安德里亚。我不久前就完成了这方面的工作,应该更新这篇文章。我按照您的建议实施了学习率衰减,并进行了更长时间的培训,这当然有所帮助。有关更多详细信息,请参阅我的问题答案。谢谢更新。所以你最终不必增加l2正则化或使用辍学?@AlexU:你能在这里帮助我吗:你能上传你更新的配置文件(作为回答)来帮助你解决问题吗?@SaurabhChauhan我已经用配置文件更新了上面的答案,我相信这是最后一个。我希望配置文件中的细节和一般答案能帮助您的网络正常工作。太好了,谢谢!你能告诉我在增加体重衰减(和辍学)之前和增加体重衰减(和辍学)之后的损失是多少吗?您在准确性和损失方面有多大改进?