Python 导出推理图在tensorflow对象检测api中当\u stages的num\u为1(仅RPN)时给出错误

Python 导出推理图在tensorflow对象检测api中当\u stages的num\u为1(仅RPN)时给出错误,python,tensorflow,object-detection,object-detection-api,faster-rcnn,Python,Tensorflow,Object Detection,Object Detection Api,Faster Rcnn,我正在做tensorflow(v1.14)对象检测api。我在配置中使用了faster\u rcnn\u inception\u resnet\u v2\u atrus\u coco和num\u-of-stages:1。 我尝试使用以下命令生成推理图: python3 export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_resnet_v2

我正在做tensorflow(v1.14)对象检测api。我在配置中使用了
faster\u rcnn\u inception\u resnet\u v2\u atrus\u coco
num\u-of-stages:1
。 我尝试使用以下命令生成推理图:

python3 export_inference_graph.py --input_type image_tensor --pipeline_config_path training/faster_rcnn_inception_resnet_v2_atrous_coco.config --trained_checkpoint_prefix training/model.ckpt-125846 --output_directory inference_graph/
这给了我一个错误:

Traceback (most recent call last):
  File "export_inference_graph.py", line 162, in <module>
    tf.app.run()
  File "/home/tfs-people-analytics/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/home/tfs-people-analytics/.local/lib/python3.6/site-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/home/tfs-people-analytics/.local/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "export_inference_graph.py", line 158, in main
    write_inference_graph=FLAGS.write_inference_graph)
  File "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/exporter.py", line 515, in export_inference_graph
    write_inference_graph=write_inference_graph)
  File "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/exporter.py", line 418, in _export_inference_graph
    graph_hook_fn=graph_hook_fn)
  File "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/exporter.py", line 385, in build_detection_graph
    output_collection_name=output_collection_name)
  File "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/exporter.py", line 363, in _get_outputs_from_inputs
    output_collection_name)
  File "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/exporter.py", line 246, in add_output_tensor_nodes
    detection_fields.detection_classes) + label_id_offset
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
其中,
postprocessed\u tensors.get(detection\u fields.detection\u classes)
在我使用
num\u of\u stages:1仅训练RPN时返回
Nonetype
。是否有其他方法可以导出我的模型的推理图

这是我的配置文件:

# Faster R-CNN with Inception Resnet v2, Atrous version;
# Configured for MSCOCO Dataset.

model {
  faster_rcnn {
    number_of_stages: 1
    num_classes: 1
    image_resizer {
      fixed_shape_resizer {
        height: 100
        width: 100
      }
    }
    feature_extractor {
      type: 'faster_rcnn_inception_resnet_v2'
      first_stage_features_stride: 8
    }
    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: 8
        width_stride: 8
      }
    }
    first_stage_atrous_rate: 2
    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: 70
    first_stage_localization_loss_weight: 2.0
    first_stage_objectness_loss_weight: 1.0
    initial_crop_size: 17
    maxpool_kernel_size: 1
    maxpool_stride: 1
    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: 100
      }
      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.0003
          schedule {
            step: 900000
            learning_rate: .00003
          }
          schedule {
            step: 1200000
            learning_rate: .000003
          }
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  gradient_clipping_by_norm: 10.0
  fine_tune_checkpoint: "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/faster_rcnn_inception_resnet_v2_atrous_coco_2018_01_28/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: 350000
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/train.record"
  }
  label_map_path: "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/training/labelmap.pbtxt"
}

eval_config: {
  num_examples: 3000
  # 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: "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/test.record"
  }
  label_map_path: "/home/tfs-people-analytics/Documents/tensorflow/models/research/object_detection/training/labelmap.pbtxt"
  shuffle: false
  num_readers: 1
}

在github中找到。但没有任何用处。如果您需要更多信息,请留言。谢谢

好的,找到了解决方案,结果证明github解决方案确实有效,特别是一个。所以我刚刚在
exporter.py
上添加了这些行:

classes = postprocessed_tensors.get(
      detection_fields.detection_classes)
  if classes is not None:
    classes += label_id_offset
  else:
    one = tf.constant(1, dtype=tf.int32, shape=(1, 1), name='classes_dummy')
    classes = tf.tile(one, tf.shape(scores))
同一github线程上的另一个问题是,该常量需要在创建时具有已知的形状

classes = postprocessed_tensors.get(
      detection_fields.detection_classes)
  if classes is not None:
    classes += label_id_offset
  else:
    one = tf.constant(1, dtype=tf.int32, shape=(1, 1), name='classes_dummy')
    classes = tf.tile(one, tf.shape(scores))