【问题标题】:Tensorflow Object Detection: Not Predicting using Custom DataTensorFlow 对象检测:不使用自定义数据进行预测
【发布时间】:2019-01-09 20:30:06
【问题描述】:

我正在使用此存储库,其基本代码 (https://github.com/ndaidong/tf-object-detection) 使用 Tensorflow 对象检测来检测评论屏幕截图中的评论、日期、喜欢和评分。

我浏览了 100 张图片(只是想测试这是否可行),用 4 个标签(评论、日期、喜欢和评分)对图片进行注释,从 XML 转换为 CSV,然后生成 TFrecords。这是为训练和评估数据完成的。 100 幅图像用于训练,20 幅图像用于评估。这是我注释的内容的屏幕截图。 Click here for an example of the annotated image

为了训练,我使用了以下配置

model {
  ssd {
    num_classes: 4
    image_resizer {
      fixed_shape_resizer {
      height: 500
      width: 2000
      }
    }
    feature_extractor {
      type: "ssd_mobilenet_v2"
      depth_multiplier: 1.0
      min_depth: 16
      conv_hyperparams {
        regularizer {
          l2_regularizer {
            weight: 3.99999989895e-05
          }
        }
        initializer {
          truncated_normal_initializer {
            mean: 0.0
            stddev: 0.0299999993294
          }
        }
        activation: RELU_6
        batch_norm {
          decay: 0.999700009823
          center: true
          scale: true
          epsilon: 0.0010000000475
          train: true
        }
      }
      use_depthwise: true
    }
    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 {
      }
    }
    box_predictor {
      convolutional_box_predictor {
        conv_hyperparams {
          regularizer {
            l2_regularizer {
              weight: 3.99999989895e-05
            }
          }
          initializer {
            truncated_normal_initializer {
              mean: 0.0
              stddev: 0.0299999993294
            }
          }
          activation: RELU_6
          batch_norm {
            decay: 0.999700009823
            center: true
            scale: true
            epsilon: 0.0010000000475
            train: true
          }
        }
        min_depth: 0
        max_depth: 0
        num_layers_before_predictor: 0
        use_dropout: false
        dropout_keep_probability: 0.800000011921
        kernel_size: 3
        box_code_size: 4
        apply_sigmoid_to_scores: false
      }
    }
    anchor_generator {
      ssd_anchor_generator {
        num_layers: 6
        min_scale: 0.20000000298
        max_scale: 0.949999988079
        aspect_ratios: 1.0
        aspect_ratios: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 3.0
        aspect_ratios: 0.333299994469
      }
    }
    post_processing {
      batch_non_max_suppression {
        score_threshold: 0.300000011921
        iou_threshold: 0.600000023842
        max_detections_per_class: 100
        max_total_detections: 100
      }
      score_converter: SIGMOID
    }
    normalize_loss_by_num_matches: true
    loss {
      localization_loss {
        weighted_smooth_l1 {
        }
      }
      classification_loss {
        weighted_sigmoid {
        }
      }
      hard_example_miner {
        num_hard_examples: 3000
        iou_threshold: 0.990000009537
        loss_type: CLASSIFICATION
        max_negatives_per_positive: 3
        min_negatives_per_image: 3
      }
      classification_weight: 1.0
      localization_weight: 1.0
    }
  }
}
train_config {
  batch_size: 35
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    ssd_random_crop {
    }
  }
  optimizer {
    rms_prop_optimizer {
      learning_rate {
        exponential_decay_learning_rate {
          initial_learning_rate: 0.00400000018999
          decay_steps: 800720
          decay_factor: 0.949999988079
        }
      }
      momentum_optimizer_value: 0.899999976158
      decay: 0.899999976158
      epsilon: 1.0
    }
  }
  num_steps: 200
}
train_input_reader: {
  tf_record_input_reader {
    input_path: "temp/data/train.record"
  }
  label_map_path: "configs/reviews/labels.pbtxt"
}
eval_config {
  num_examples: 20
  max_evals: 10
  use_moving_averages: false
}
eval_input_reader: {
  tf_record_input_reader {
    input_path: "temp/data/test.record"
  }
  label_map_path: "configs/reviews/labels.pbtxt"
  shuffle: false
  num_readers: 1
}

如您所见,我正在尝试从头开始训练数据,而不是使用现有模型。这样做的原因是因为我不是试图找到已经训练过的一般对象。

我调整了 fixed_shape_resizer,因为评论的图像尺寸大约是 2000 宽和 500 高。

我只使用了 200 步进行训练(我需要做更多吗?),正如我在 Tensorboard 中注意到的,在 100 步后它开始学习,因为“损失”结果开始下降很多. Click here to see Tensorboard results

但是,当我导出/冻结图表然后尝试预测时。什么都无法预测。在我看来一切都很好。我做错了吗?

【问题讨论】:

  • 仅 200 张图像就足以进行对象检测,至少对于测试而言。你可能做错了一些步骤,参考pythonprogramming.net/…

标签: python tensorflow machine-learning object-detection


【解决方案1】:

使用此 API 涉及许多步骤,因此不确定您可能弄错了哪一个,但我觉得如果您从头开始训练对象检测模型,那么您需要庞大的数据集。 100 张图像是非常小的数据集。您可以查看训练预训练对象检测模型(如 ResNet、ImageNet)的数据集的大小。那里的数据集非常庞大。因此,要获得结果,您需要使用预训练模型或更大的数据集。为了增加数据集,您可以在此 API 之外对现有图像进行图像增强,并使用算法调整它们的注释。当我做类似的练习时,我使用了大约 10K 图像和预训练模型和图像增强。

如果您使用 labelImg 进行图像注释,请确保您了解工具中的 this 问题

【讨论】:

  • 要获得结果,您建议我应该注释/训练多少张图片?我会按照您的建议做,并使用现有的现有模型进行训练。是否可以让机器从评论的图像/屏幕截图中检测“喜欢”和“评分”?
  • 使用预训练模型,您也可以从 100 开始进行检查。此外,您可以做的是逐渐增加不同上下文的数据集,以查看结果是否有所改善。我无法建议具体数字,因为它取决于许多因素,但请尝试使用 1K-2K 图像。但是预训练模型肯定会检测到。您还可以发布模型拟合日志的快照吗?就我而言,我从配置管道中删除了随机作物增强,这确实有所帮助。
  • 我删除了“ssd_random_crop”并添加了fine_tune_checkpoint以使用模型“ssd_mobilenet_v2_coco_2018_03_29”。见截图imgur.com/9rVOBTS。现在重复了两次。它还说缺少很多变量。见截图 - imgur.com/yK5Qr1U
猜你喜欢
  • 1970-01-01
  • 2018-07-03
  • 1970-01-01
  • 2019-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-18
相关资源
最近更新 更多