Tensorflow对象检测服务

时间:2019-05-01 03:09:23

标签: tensorflow object-detection

我正在使用张量流对象检测api。此api的问题在于它会导出冻结图以进行推断。我无法使用该图表进行投放。因此,作为解决方案,我遵循了教程here。但是,当我尝试导出图形时,出现以下错误:

  

InvalidArgumentError(请参阅上面的回溯):从中还原   检查点失败。这很可能是由于两者之间的不匹配   当前图和来自检查点的图。请确保   您尚未更改基于检查点的预期图形。   原始错误:

     

分配需要两个张量的形状匹配。 lhs shape = [1024,4]   rhs shape = [1024,8]

     

[[节点保存/分配_258(在   /home/deploy/models/research/object_detection/exporter.py:67)=   分配[T = DT_FLOAT,   _class = [“ loc:@ SecondStageBoxPredictor / BoxEncodingPredictor / weights”],use_locking = true,validate_shape = true,   _device =“ / job:localhost / replica:0 / task:0 / device:GPU:0”](SecondStageBoxPredictor / BoxEncodingPredictor / weights,   save / RestoreV2 / _517)]] [[{{node save / RestoreV2 / _522}} =   _SendT = DT_FLOAT,client_terminated = false,recv_device =“ / job:localhost /副本:0 / task:0 / device:GPU:0”,   send_device =“ / job:localhost /副本:0 / task:0 / device:CPU:0”,   send_device_incarnation = 1,tensor_name =“ edge_527_save / RestoreV2”,   _device =“ / job:localhost /副本:0 /任务:0 /设备:CPU:0”]]

该错误表明图中不匹配。一个可能的原因可能是我正在使用预训练图进行训练,该训练可能具有4个分类,而我的模型具有8个分类。 (因此形状不匹配)。 Deeplab model及其针对它们的解决方案也存在类似的问题 具体模型是使用--initialize_last_layer=False--last_layers_contain_logits_only=False参数开始训练。但是tensorflow对象检测没有该参数。那么,我应该如何进行?另外,还有其他方法可以服务于Tensorflow对象检测API吗?

我的配置文件如下:

model {
  faster_rcnn {
    num_classes: 1
    image_resizer {
      fixed_shape_resizer {
        height: 1000
        width: 1000
        resize_method: AREA
      }
    }
    feature_extractor {
      type: "faster_rcnn_inception_v2"
      first_stage_features_stride: 16
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        height_stride: 16
        width_stride: 16
        scales: 0.25
        scales: 0.5
        scales: 1.0
        scales: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 1.0
        aspect_ratios: 2.0
      }
    }
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.0
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.00999999977648
        }
      }
    }
    first_stage_nms_score_threshold: 0.0
    first_stage_nms_iou_threshold: 0.699999988079
    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 {
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
        use_dropout: false
        dropout_keep_probability: 1.0
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: 0.0
        iou_threshold: 0.600000023842
        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: 8
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  optimizer {
    adam_optimizer {
      learning_rate {
        manual_step_learning_rate {
          initial_learning_rate: 0.00010000000475
          schedule {
            step: 40000
            learning_rate: 3.00000010611e-05
          }
        }
      }
    }
    use_moving_average: true
  }
  gradient_clipping_by_norm: 10.0
  fine_tune_checkpoint: "/home/deploy/models/research/object_detection/faster_rcnn_inception_v2_coco_2018_01_28/model.ckpt"
  from_detection_checkpoint: true
  num_steps: 60000
  max_number_of_boxes: 100
}
train_input_reader {
  label_map_path: "/home/deploy/models/research/object_detection/Training_carrot_060219/carrot_identify.pbtxt"
  tf_record_input_reader {
    input_path: "/home/deploy/models/research/object_detection/Training_carrot_060219/train.record"
  }
}
eval_config {
  num_visualizations: 100
  num_examples: 135
  eval_interval_secs: 60
  use_moving_averages: false
}
eval_input_reader {
  label_map_path: "/home/deploy/models/research/object_detection/Training_carrot_060219/carrot_identify.pbtxt"
  shuffle: true
  num_epochs: 1
  num_readers: 1
  tf_record_input_reader {
    input_path: "/home/deploy/models/research/object_detection/Training_carrot_060219/test.record"
  }
  sample_1_of_n_examples: 1
}

1 个答案:

答案 0 :(得分:1)

导出用于tf服务的模型时,配置文件和检查点文件应彼此对应。

问题是,导出定制的训练模型时,您使用的是旧配置文件和新检查点文件。