当前位置: 首页 > 知识库问答 >
问题:

在tensorlfow对象检测api中导出推理图时出错

温嘉玉
2023-03-14

嗨,我正在做的tenstorFlow目标检测api。我已经遵循了回购中的所有主要指示,直到现在它一直运行良好。但是一些奇怪的错误开始突然出现。我之前使用的是快速rcnn,现在切换到ssd移动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

我得到以下错误:

回溯(最近一次调用):文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/client/session.py”,第1356行,在_do_call return fn(*args)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/client/session.py”中,第1341行,在_run_fn选项中,提要,feed_dict,fetch列表,target_list,run_metadata)File“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/client/session.py”,第1429行,位于调用_tf_sessionrun_metadata)tensorflow中。python框架错误。NotFoundError:在检查点[[{{node save/RestoreV2}}]]中未找到密钥Conv/bias

在处理上述异常时,发生了另一个异常

回溯(最后一次调用):文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/training/saver.py”,第1286行,在restore{self.saver\u def.filename\u tensor\u name:save_path}文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/python/client/session.py”第950行,运行元数据(ptr)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/client/session.py”,第1173行,运行提要(dict)tensor,选项,运行元数据(ptr)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/client/session.py”,第1350行,运行元数据)文件“/home/user/anaconda3/envs/my_env/lib/python3。6/站点包/tensorflow/python/client/session。py“,第1370行,在_do_call raise type(e)(node_def,op,message)tensorflow.python.framework.errors_impl.NotFoundError:Key Conv/bias未在检查点中找到[[node save/RestoreV2(在/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/object_detection/exporter.py:331中定义)]]

“save/RestoreV2”的原始堆栈跟踪:tf中第162行的文件“export\u interference\u graph.py”。应用程序。run()文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/platform/app.py”,第40行,运行中(main=main,argv=argv,flags\u parser=\u parse\u flags\u undef)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/absl/app.py”,第299行,运行中“/home/user/anaconda3/envs/my_env/lib/python3。6/站点包/absl/应用程序。py“,第250行,在主系统出口(主(argv))文件“导出推理图”中。py”,第158行,在主write\u expression\u graph=FLAGS.write\u expression\u graph)文件“/home/user/anaconda3/envs/my\u env/lib/python3中。6/现场包装/物体探测/出口商。py“,第497行,在导出推理图写入推理图=写入推理图)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/现场包装/物体探测/出口商。py“,第426行,在文件“/home/user/anaconda3/envs/my\u env/lib/python3”中,导出推理图“\u checkpoint\u prefix=checkpoint\u to\u use”。6/现场包装/物体探测/出口商。py“,第331行,在write_graph_和_checkpoint tf.import_graph_def(推断_graph_def,name='')文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/util/deprecation。py“,第507行,在新函数return func(*args,**kwargs)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/framework/importer。py”,第443行,在导入图形定义处理新操作(图形)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/framework/importer。py”,第236行,在图中添加新操作的新操作。添加新操作(compute\u devices=False):\pylint:disable=protected access File”/home/user/anaconda3/envs/my\u env/lib/python3。6/站点包/tensorflow/python/framework/ops。py“,第3751行,在c_api_util.new_tf_operations(self)文件“/home/user/anaconda3/envs/my_env/lib/python3中为c_op添加新的_tfu_操作。6/站点包/tensorflow/python/framework/ops。py”,第3751行,用于c_api_util.new_tf_operations(self)文件“/home/user/anaconda3/envs/my_env/lib/python3中的c_op。6/站点包/tensorflow/python/framework/ops。py”,第3641行,在“从操作ret=operation(c_op,self)文件/home/user/anaconda3/envs/my_env/lib/python3创建操作”中。6/站点包/tensorflow/python/framework/ops。py“,第2005行,在init self._traceback=tf_stack.extract_stack()中

在处理上述异常时,发生了另一个异常:

回溯(最后一次调用):文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/training/saver.py”,第1296行,在restore names\u-keys=object\u-graph\u-key\u-mapping(save\u-path)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/training/saver.py”中,第1614行,在对象\图形\键\映射对象\图形\字符串=读取器中。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返回检查点阅读器_gettensorflow(self,compat.as_bytes(tensor_str))中。python框架错误。NotFoundError:在检查点中找不到键\u可检查点\u对象\u图形

在处理上述异常时,发生了另一个异常:

Traceback(最近一次调用):文件"export_inference_graph.py",第162行,在tf.app.run()文件"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/tensorflow/python/平台/app.py",第40行,在运行_run(main=Main, argv=argv,flags_parser=_parse_flags_tolerate_undef)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/absl/app.py",第299行,在运行_run_main(main, args)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/absl/app.py",第250行,_run_mainsys.exit(main(agv))File"export_inference_graph.py",第158行,mainwrite_inference_graph=FLAGS。write_inference_graph)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/object_detection/exporter.py",第497行,export_inference_graphwrite_inference_graph=write_inference_graph)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/object_detection/exporter.py",第426行,_export_inference_graphtrained_checkpoint_prefix=checkpoint_to_use)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/object_detection/exporter.py",第335行,write_graph_and_checkpointsaver.restore(sess,trained_checkpoint_prefix)File"/home/user/anaconda3/envs/my_env/lib/python3.6/site-包/tensorflow/python/训练/saver.py",第1302行,在恢复err中,"缺少变量名或其他图形键")tensorflow.python.framework.errors_impl。从检查点还原失败。这很可能是由于检查点缺少变量名称或其他图形键造成的。请确保您没有根据检查点更改预期的图形。原始错误:

在检查点[[节点保存/恢复2(在/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/object_detection/exporter.py:331中定义)]中未找到密钥转换/偏差

“save/RestoreV2”的原始堆栈跟踪:tf中第162行的文件“export\u interference\u graph.py”。应用程序。run()文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/tensorflow/python/platform/app.py”,第40行,运行中(main=main,argv=argv,flags\u parser=\u parse\u flags\u undef)文件“/home/user/anaconda3/envs/my_env/lib/python3.6/site packages/absl/app.py”,第299行,运行中“/home/user/anaconda3/envs/my_env/lib/python3。6/站点包/absl/应用程序。py“,第250行,在主系统出口(主(argv))文件“导出推理图”中。py”,第158行,在主write\u expression\u graph=FLAGS.write\u expression\u graph)文件“/home/user/anaconda3/envs/my\u env/lib/python3中。6/现场包装/物体探测/出口商。py“,第497行,在导出推理图写入推理图=写入推理图)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/现场包装/物体探测/出口商。py“,第426行,在文件“/home/user/anaconda3/envs/my\u env/lib/python3”中,导出推理图“\u checkpoint\u prefix=checkpoint\u to\u use”。6/现场包装/物体探测/出口商。py“,第331行,在write_graph_和_checkpoint tf.import_graph_def(推断_graph_def,name='')文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/util/deprecation。py“,第507行,在新函数return func(*args,**kwargs)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/framework/importer。py”,第443行,在导入图形定义处理新操作(图形)文件“/home/user/anaconda3/envs/my_env/lib/python3中。6/站点包/tensorflow/python/framework/importer。py”,第236行,在图中添加新操作的新操作。添加新操作(compute\u devices=False):\pylint:disable=protected access File”/home/user/anaconda3/envs/my\u env/lib/python3。6/站点包/tensorflow/python/framework/ops。py“,第3751行,在c_api_util.new_tf_operations(self)文件“/home/user/anaconda3/envs/my_env/lib/python3中为c_op添加新的_tfu_操作。6/站点包/tensorflow/python/framework/ops。py”,第3751行,用于c_api_util.new_tf_operations(self)文件“/home/user/anaconda3/envs/my_env/lib/python3中的c_op。6/站点包/tensorflow/python/framework/ops。py”,第3641行,在“从操作ret=operation(c_op,self)文件/home/user/anaconda3/envs/my_env/lib/python3创建操作”中。6/站点包/tensorflow/python/framework/ops。py“,第2005行,在init self._traceback=tf_stack.extract_stack()中

事实上,它一直在正常工作,不知道现在发生了什么。我尝试了快速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
}

github中发现一个或两个类似的错误。但这没有用。任何帮助都将不胜感激。如果您需要更多信息,请留言。非常感谢。

共有1个答案

党星鹏
2023-03-14

您是否确定您的型号培训/型号。ckpt-10250是一款更快的\u rcnn\u inception\u v2\u pets型号?错误NotFoundError:Key Conv/biases未在检查点[[{{node save/RestoreV2}}]]中找到意味着它无法从检查点恢复Conv/biases

或者,确保您使用的是对象检测框架支持的TF版本。你可以在这里找到所有版本。

 类似资料:
  • 问题内容: 例如,我正在尝试导出TS对象以获取以下JavaScript输出: 这是我的TS,但导出尚不明确, 我已经尝试过了,但是它的生成的输出是不期望的。我究竟做错了什么? 问题答案: 在ES6中,允许使用导出功能导出名称,或者默认情况下,您可以导出任何内容。该格式是这样的: 并且它将默认导出配置文件。对于您的情况,您应该执行以下操作: 如果要使用导出,请执行以下操作: 区别是: 至 注意-默认

  • 这种传递性关系在Protege中非常有效。我用黄色可以看出A类相当于C类,反之亦然。 我想从Protege工具导出这个推断的公理。我转到“文件->导出推断公理为本体”,在第一个屏幕上选择所有选项,在第二个屏幕上不选择任何选项。最后,我以RDF/XML语法将文件保存为OWL。 现在当我打开这个新文件时,我没有看到任何关于推断公理的三元组,即A类等同于C类,事实上,它与我最初的本体论是完全相同的本体论

  • 用例很简单:我只想导出一个名称与导入时相同的对象。 例如: 但这并不起作用。我必须写: 但这很奇怪。正确的方法是什么? 更新: 感谢帮助和参考。我用许多线索解决了我的问题。下面给大家分享一些我常见的案例和解决方法。

  • 问题内容: 我想用JAXB将我的pojo转换为json,我的pojo具有一对多的关系,当我将pojo转换为json时,JAXB会产生错误“在对象图中检测到一个循环。这将导致无限深的XML”。 我从网上读到,可以通过@XmlID和@XmlIDREF的帮助解决此问题,但是有一个问题,我的Id属性不是String类型,而是Long。据我所知,@ XmlID只能与String属性一起使用。 其他网站建议使

  • 您好,我在react js中有此组件: 我需要导出返回函数中的这一行:作为变量在另一个组件中使用它。 所以我这样做了: 但是我得到了这个错误:意外的令牌,预期的,(47:20) 有人能帮我导出变量吗