我正在按照本教程来训练自定义对象检测器:https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html
当我使用以下命令启动训练脚本时:
python train.py --logtostderr --train_dir = training / --pipeline_config_path = training / ssd_inception_v2_coco.config
我收到以下输出:
(tensorflow_gpuenv) C:\Content\workspace\training_demo>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_inception_v2_coco.config
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\slim\nets\inception_resnet_v2.py:373: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\slim\nets\mobilenet\mobilenet.py:397: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.
WARNING:tensorflow:From train.py:55: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.
WARNING:tensorflow:From train.py:55: The name tf.logging.INFO is deprecated. Please use tf.compat.v1.logging.INFO instead.
WARNING:tensorflow:From train.py:184: The name tf.app.run is deprecated. Please use tf.compat.v1.app.run instead.
WARNING:tensorflow:From C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py:250: main (from __main__) is deprecated and will be removed in a future version.
Instructions for updating:
Use object_detection/model_main.py.
W1014 09:39:33.230681 15784 deprecation.py:323] From C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py:250: main (from __main__) is deprecated and will be removed in a future version.
Instructions for updating:
Use object_detection/model_main.py.
WARNING:tensorflow:From train.py:90: The name tf.gfile.MakeDirs is deprecated. Please use tf.io.gfile.makedirs instead.
W1014 09:39:33.231679 15784 deprecation_wrapper.py:119] From train.py:90: The name tf.gfile.MakeDirs is deprecated. Please use tf.io.gfile.makedirs instead.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py:102: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
W1014 09:39:33.231679 15784 deprecation_wrapper.py:119] From C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py:102: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
Traceback (most recent call last):
File "train.py", line 184, in <module>
tf.app.run()
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\tensorflow\python\util\deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "train.py", line 93, in main
FLAGS.pipeline_config_path)
File "C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py", line 104, in get_configs_from_pipeline_file
text_format.Merge(proto_str, pipeline_config)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 690, in Merge
allow_unknown_field=allow_unknown_field)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 757, in MergeLines
return parser.MergeLines(lines, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 782, in MergeLines
self._ParseOrMerge(lines, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 804, in _ParseOrMerge
self._MergeField(tokenizer, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 872, in _MergeField
name = tokenizer.ConsumeIdentifierOrNumber()
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 1340, in ConsumeIdentifierOrNumber
raise self.ParseError('Expected identifier or number, got %s.' % result)
': Expected identifier or number, got .1:1 : '# SSD with Inception v2 configuration for MSCOCO Dataset.
我还测试了在tensorflow模型研究目录中运行脚本“ model_main.py” :
SET PIPELINE_CONFIG_PATH=C:\Content\workspace\training_demo\annotations\ssd_inception_v2_coco.config
SET MODEL_DIR=C:\TEMP
SET NUM_TRAIN_STEPS=50000
SET SAMPLE_1_OF_N_EVAL_EXAMPLES=1
python object_detection/model_main.py --pipeline_config_path=%PIPELINE_CONFIG_PATH% --model_dir=%MODEL_DIR% --num_train_steps=%NUM_TRAIN_STEPS% --sample_1_of_n_eval_examples=%SAMPLE_1_OF_N_EVAL_EXAMPLES% --alsologtostderr
并得到以下结果:
(tensorflow_gpuenv) C:\Content\TensorFlow\models\research>SET PIPELINE_CONFIG_PATH=C:\Content\workspace\training_demo\annotations\ssd_inception_v2_coco.config
(tensorflow_gpuenv) C:\Content\TensorFlow\models\research>SET MODEL_DIR=C:\TEMP
(tensorflow_gpuenv) C:\Content\TensorFlow\models\research>SET NUM_TRAIN_STEPS=50000
(tensorflow_gpuenv) C:\Content\TensorFlow\models\research>SET SAMPLE_1_OF_N_EVAL_EXAMPLES=1
(tensorflow_gpuenv) C:\Content\TensorFlow\models\research>python object_detection/model_main.py --pipeline_config_path=%PIPELINE_CONFIG_PATH% --model_dir=%MODEL_DIR% --num_train_steps=%NUM_TRAIN_STEPS% --sample_1_of_n_eval_examples=%SAMPLE_1_OF_N_EVAL_EXAMPLES% --alsologtostderr
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\slim\nets\inception_resnet_v2.py:373: The name tf.GraphKeys is deprecated. Please use tf.compat.v1.GraphKeys instead.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\slim\nets\mobilenet\mobilenet.py:397: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.
WARNING:tensorflow:From object_detection/model_main.py:109: The name tf.app.run is deprecated. Please use tf.compat.v1.app.run instead.
WARNING:tensorflow:From C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py:102: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
W1014 09:43:24.385520 6260 deprecation_wrapper.py:119] From C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py:102: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
Traceback (most recent call last):
File "object_detection/model_main.py", line 109, in <module>
tf.app.run()
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "object_detection/model_main.py", line 71, in main
FLAGS.sample_1_of_n_eval_on_train_examples))
File "C:\Content\TensorFlow\models\research\object_detection\model_lib.py", line 605, in create_estimator_and_inputs
pipeline_config_path, config_override=config_override)
File "C:\Content\TensorFlow\models\research\object_detection\utils\config_util.py", line 104, in get_configs_from_pipeline_file
text_format.Merge(proto_str, pipeline_config)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 690, in Merge
allow_unknown_field=allow_unknown_field)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 757, in MergeLines
return parser.MergeLines(lines, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 782, in MergeLines
self._ParseOrMerge(lines, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 804, in _ParseOrMerge
self._MergeField(tokenizer, message)
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 872, in _MergeField
name = tokenizer.ConsumeIdentifierOrNumber()
File "C:\Content\Anaconda3\envs\tensorflow_gpuenv\lib\site-packages\google\protobuf\text_format.py", line 1340, in ConsumeIdentifierOrNumber
raise self.ParseError('Expected identifier or number, got %s.' % result)
': Expected identifier or number, got .1:1 : '# SSD with Inception v2 configuration for MSCOCO Dataset.
在这两种情况下, ssd_inception_v2_coco.config 文件中似乎都存在某种解析错误。我使用了错误的文件吗?这是该文件的完整列表:
# SSD with Inception v2 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: 1
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
reduce_boxes_in_lowest_layer: true
}
}
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: false
dropout_keep_probability: 0.8
kernel_size: 3
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
}
}
}
}
}
feature_extractor {
type: 'ssd_inception_v2_coco_2018_01_28'
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,
}
}
override_base_feature_extractor_hyperparams: true
}
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
}
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: 24
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: "pre-trained-model/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: "annotations/train.record"
}
label_map_path: "annotations/label_map.pbtxt"
}
eval_config: {
metrics_set: "coco_detection_metrics"
num_examples: 8000
# Note: The below line limits the evaluation process to 10 evaluations.
# Remove the below line to evaluate indefinitely.
max_evals: 10
}
eval_input_reader: {
tf_record_input_reader {
input_path: "annotations/test.record"
}
label_map_path: "annotations/label_map.pbtxt"
shuffle: false
num_readers: 1
}
我下载的模型名为“ ssd_inception_vs_coco_2018_01_28”。这是我创建的其他文件的转储:
label_map.pbtxt:
item {
id: 1
name: 'car'
}
test_labels.csv:
filename,width,height,class,xmin,ymin,xmax,ymax
image-01.jpg,640,480,car,44,104,600,366
image-02.jpg,640,480,car,125,153,530,360
image-03.jpg,640,480,car,107,117,557,375
image-04.jpg,640,480,car,71,217,533,480
image-05.jpg,640,480,car,160,172,574,370
image-06.jpg,640,480,car,44,112,587,390
image-07.jpg,640,480,car,104,162,550,368
image-08.jpg,640,480,car,248,100,640,311
image-09.jpg,640,480,car,2,63,638,418
image-10.jpg,640,480,car,16,118,633,358
train_labels.csv:
image-11.jpg,640,480,car,2,25,633,457
image-12.jpg,640,480,car,136,178,474,338
image-13.jpg,640,480,car,121,71,611,344
image-14.jpg,640,480,car,61,114,569,361
image-15.jpg,640,480,car,79,149,389,403
image-15.jpg,640,480,car,393,181,602,285
image-16.jpg,640,480,car,65,161,591,375
image-17.jpg,640,480,car,2,132,316,300
image-17.jpg,640,480,car,321,134,640,451
image-18.jpg,640,480,car,200,272,428,374
image-19.jpg,640,480,car,1,71,630,420
image-20.jpg,640,480,car,200,129,462,365
image-21.jpg,640,480,car,5,41,640,452
image-22.jpg,640,480,car,260,180,422,295
image-23.jpg,640,480,car,37,54,591,390
image-24.jpg,640,480,car,89,155,602,409
image-25.jpg,640,480,car,52,107,591,381
image-26.jpg,640,480,car,2,1,584,451
image-27.jpg,640,480,car,13,84,599,403
image-28.jpg,640,480,car,194,135,636,384
image-29.jpg,640,480,car,3,33,639,451
image-30.jpg,640,480,car,83,104,584,389
image-31.jpg,640,480,car,59,68,581,477
image-32.jpg,640,480,car,45,104,597,367
image-33.jpg,640,480,car,131,163,530,358
image-34.jpg,640,480,car,102,119,560,377
image-35.jpg,640,480,car,159,172,574,372
image-36.jpg,640,480,car,45,100,584,392
image-37.jpg,640,480,car,102,160,546,367
image-38.jpg,640,480,car,2,106,637,416
image-39.jpg,640,480,car,20,118,626,360
image-40.jpg,640,480,car,2,25,633,461
image-41.jpg,640,480,car,140,180,471,338
image-42.jpg,640,480,car,60,110,570,360
image-43.jpg,640,480,car,74,151,390,397
image-43.jpg,640,480,car,391,183,600,284
image-44.jpg,640,480,car,2,134,317,298
image-45.jpg,640,480,car,203,268,426,377
image-46.jpg,640,480,car,2,72,628,417
image-47.jpg,640,480,car,202,130,459,357
image-49.jpg,640,480,car,2,30,639,450
image-50.jpg,640,480,car,262,180,423,294
image-51.jpg,640,480,car,41,62,585,388
image-53.jpg,640,480,car,87,156,599,407