【发布时间】:2020-04-03 16:50:26
【问题描述】:
嗨,我在做tensorflow object detection api。我已经按照 repo 中的所有主要说明进行操作,直到现在它一直运行良好。但是突然开始出现一些奇怪的错误。我之前使用的是fast rcnn,现在切换到ssd mobile v2 coco。
使用命令生成推理图时
python export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_v2_pets.config --trained_checkpoint_prefix training/model.ckpt-10250 --output_directory inference_graph
我收到以下错误:
Traceback(最近一次调用最后一次):文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 1356 行,在 _do_call 返回 fn(*args) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 1341 行,在 _run_fn 选项,feed_dict,fetch_list,target_list,run_metadata)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第1429行,在_call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.NotFoundError: Key Conv/biases 在检查点中找不到 [[{{node save/RestoreV2}}]]
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次):文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/training/saver.py”,第 1286 行,在恢复中 {self.saver_def.filename_tensor_name: save_path}) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 950 行,运行中 run_metadata_ptr)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 1173 行,在 _run feed_dict_tensor,选项,run_metadata)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 1350 行,在 _do_run run_metadata)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/client/session.py”,第 1370 行,在 _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.NotFoundError: Key Conv/biases 在检查点 [[node save/RestoreV2 (定义在 /home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py:331) ]]
“save/RestoreV2”的原始堆栈跟踪:文件 “export_inference_graph.py”,第 162 行,在 tf.app.run() 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/platform/app.py”, 第 40 行,运行中 _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) 文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 299 行,运行中 _run_main(main, args) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 250 行,在 _run_main sys.exit(main(argv)) 文件“export_inference_graph.py”,第 158 行,在 main write_inference_graph=FLAGS.write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 497 行,在 export_inference_graph 中 write_inference_graph=write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 426 行,在 _export_inference_graph train_checkpoint_prefix=checkpoint_to_use) 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py", 第 331 行,在 write_graph_and_checkpoint tf.import_graph_def(inference_graph_def, name='') 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", 第 507 行,在 new_func 中 返回 func(*args, **kwargs) 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", 第 443 行,在 import_graph_def _ProcessNewOps(图形)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/importer.py”, 第 236 行,在 _ProcessNewOps for new_op in graph._add_new_tf_operations(compute_devices=False): # pylint: disable=protected-access File "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops .py", 第 3751 行,在 _add_new_tf_operations 对于 c_api_util.new_tf_operations(self) 文件中的 c_op “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 3751 行,在 对于 c_api_util.new_tf_operations(self) 文件中的 c_op “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 3641 行,在 _create_op_from_tf_operation ret = 操作(c_op,self)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 2005 行,在 init 中 self._traceback = tf_stack.extract_stack()
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次):文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/training/saver.py”,第 1296 行,在恢复中 names_to_keys = object_graph_key_mapping(save_path) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/training/saver.py”,第 1614 行,在 object_graph_key_mapping object_graph_string = reader.get_tensor(trackable.OBJECT_GRAPH_PROTO_KEY) 文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, 第 678 行,在 get_tensor 中 返回 CheckpointReader_GetTensor(self, compat.as_bytes(tensor_str)) tensorflow.python.framework.errors_impl.NotFoundError:关键 _CHECKPOINTABLE_OBJECT_GRAPH 在检查点中找不到
在处理上述异常的过程中,又发生了一个异常:
Traceback(最近一次调用最后一次):文件“export_inference_graph.py”, 第 162 行,在 tf.app.run() 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/platform/app.py”, 第 40 行,运行中 _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) 文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 299 行,运行中 _run_main(main, args) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 250 行,在 _run_main sys.exit(main(argv)) 文件“export_inference_graph.py”,第 158 行,在 main write_inference_graph=FLAGS.write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 497 行,在 export_inference_graph 中 write_inference_graph=write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 426 行,在 _export_inference_graph train_checkpoint_prefix=checkpoint_to_use) 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py", 第 335 行,在 write_graph_and_checkpoint saver.restore(sess,trained_checkpoint_prefix)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/training/saver.py”,第1302行,在恢复 错误,“缺少的变量名称或其他图形键”)tensorflow.python.framework.errors_impl.NotFoundError:从 检查点失败。这很可能是由于变量名称或其他 检查点中缺少的图形键。请确保您 没有根据检查点更改预期的图表。原版的 错误:
在检查点 [[node save/RestoreV2] 中找不到 Key Conv/biases (定义在 /home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py:331) ]]
“save/RestoreV2”的原始堆栈跟踪:文件 “export_inference_graph.py”,第 162 行,在 tf.app.run() 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/platform/app.py”, 第 40 行,运行中 _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) 文件 “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 299 行,运行中 _run_main(main, args) 文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/absl/app.py”, 第 250 行,在 _run_main sys.exit(main(argv)) 文件“export_inference_graph.py”,第 158 行,在 main write_inference_graph=FLAGS.write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 497 行,在 export_inference_graph 中 write_inference_graph=write_inference_graph)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py”, 第 426 行,在 _export_inference_graph train_checkpoint_prefix=checkpoint_to_use) 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/object_detection/exporter.py", 第 331 行,在 write_graph_and_checkpoint tf.import_graph_def(inference_graph_def, name='') 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", 第 507 行,在 new_func 中 返回 func(*args, **kwargs) 文件 "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/importer.py", 第 443 行,在 import_graph_def _ProcessNewOps(图形)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/importer.py”, 第 236 行,在 _ProcessNewOps for new_op in graph._add_new_tf_operations(compute_devices=False): # pylint: disable=protected-access File "/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops .py", 第 3751 行,在 _add_new_tf_operations 对于 c_api_util.new_tf_operations(self) 文件中的 c_op “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 3751 行,在 对于 c_api_util.new_tf_operations(self) 文件中的 c_op “/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 3641 行,在 _create_op_from_tf_operation ret = 操作(c_op,self)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site-packages/tensorflow/python/framework/ops.py”, 第 2005 行,在 init 中 self._traceback = tf_stack.extract_stack()
实际上它一直在正常工作,无法弄清楚现在发生了什么。我也尝试过 fast rcnn(之前工作过),但它也开始失败
这是配置文件。我目前正在为 2 个班级做这件事
# Faster R-CNN with Inception v2, configured for Oxford-IIIT Pets 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 {
faster_rcnn {
num_classes: 2
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 600
max_dimension: 1024
}
}
feature_extractor {
type: 'faster_rcnn_inception_v2'
first_stage_features_stride: 16
}
first_stage_anchor_generator {
grid_anchor_generator {
scales: [0.25, 0.5, 1.0, 2.0]
aspect_ratios: [0.5, 1.0, 2.0]
height_stride: 16
width_stride: 16
}
}
first_stage_box_predictor_conv_hyperparams {
op: CONV
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
truncated_normal_initializer {
stddev: 0.01
}
}
}
first_stage_nms_score_threshold: 0.0
first_stage_nms_iou_threshold: 0.7
first_stage_max_proposals: 300
first_stage_localization_loss_weight: 2.0
first_stage_objectness_loss_weight: 1.0
initial_crop_size: 14
maxpool_kernel_size: 2
maxpool_stride: 2
second_stage_box_predictor {
mask_rcnn_box_predictor {
use_dropout: false
dropout_keep_probability: 1.0
fc_hyperparams {
op: FC
regularizer {
l2_regularizer {
weight: 0.0
}
}
initializer {
variance_scaling_initializer {
factor: 1.0
uniform: true
mode: FAN_AVG
}
}
}
}
}
second_stage_post_processing {
batch_non_max_suppression {
score_threshold: 0.0
iou_threshold: 0.6
max_detections_per_class: 100
max_total_detections: 300
}
score_converter: SOFTMAX
}
second_stage_localization_loss_weight: 2.0
second_stage_classification_loss_weight: 1.0
}
}
train_config: {
batch_size: 1
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
}
gradient_clipping_by_norm: 10.0
fine_tune_checkpoint: "/home/user/Downloads/Data_Science/Git/models/research/object_detection/faster_rcnn_inception_v2_coco_2018_01_28/model.ckpt"
from_detection_checkpoint: true
load_all_detection_checkpoint_vars: false
# 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 {
}
}
}
train_input_reader: {
tf_record_input_reader {
input_path: "/home/user/Downloads/Data_Science/Git/models/research/object_detection/train.record"
}
label_map_path: "/home/user/Downloads/Data_Science/Git/models/research/object_detection/training/labelmap.pbtxt"
}
eval_config: {
num_examples: 67
# 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: "C:/tensorflow1/models/research/object_detection/test.record"
}
label_map_path: "C:/tensorflow1/models/research/object_detection/training/labelmap.pbtxt"
shuffle: false
num_readers: 1
}
【问题讨论】:
标签: python tensorflow computer-vision object-detection object-detection-api