简体   繁体   English

如何向预训练的对象检测模型添加额外的类并训练它检测所有类(预训练 + 新的)?

[英]How to add additional classes to a pre-trained object detection model and train it to detect all of the classes (pre-trained + new)?

I had followed this blog --> https://medium.com/@teyou21/training-your-object-detection-model-on-tensorflow-part-2-e9e12714bdf , and built a SSD Mobilenet model which is pre-trained on the COCO Dataset called "ssd_mobilenet_v2_quantized_coco".我关注了这个博客 --> https://medium.com/@teyou21/training-your-object-detection-model-on-tensorflow-part-2-e9e12714bdf ,并构建了一个预先训练的 SSD Mobilenet 模型在名为“ssd_mobilenet_v2_quantized_coco”的 COCO 数据集上。

What happens here is that it perfectly detects my new classes, but I want to include the pre-trained classes as well.这里发生的事情是它完美地检测了我的新课程,但我也想包括预训练的课程。

I tried changing the number of classes to 96 ( 90 pre-trained + 6 new ) and edited the "labelmap.pbtxt" with the name and corresponding id of all labels from the COCO Dataset with the new classes being added at the last from ids 91 - 96.我尝试将类数更改为 96(90 个预训练 + 6 个新),并使用 COCO 数据集中所有标签的名称和相应 id 编辑“labelmap.pbtxt”,最后从 ids 添加新类91 - 96。

It still detects only the new classes only.它仍然只检测新类。

What should I do to detect both the pre-trained and new classes?我应该怎么做才能检测到预训练的和新的类?

It depends on how you use the pre trained weights:这取决于您如何使用预训练的权重:

  1. Use for transfer learning (I think in the link you send this is what they do)用于迁移学习(我认为在您发送的链接中,这就是他们所做的)
  2. Use has a starting point for fitting the entire model.使用具有拟合整个模型的起点。

The first option only trains the detection head and not the backbone of the network - This means that the backbone weights are sherd between your model and the original model.第一个选项只训练检测头,而不是网络的主干——这意味着主干权重在你的模型和原始模型之间切分。

In the second option you train all the network, backbone + detection head- This means that you have two different models在第二个选项中,您训练所有网络,主干 + 检测头 - 这意味着您有两个不同的模型

If in your case you use the second option then the only way to do what you want is to load both networks and run inference on the image once with the original network and second with your new network.如果在您的情况下您使用第二个选项,那么做您想做的唯一方法是加载两个网络并使用原始网络对图像运行一次推理,然后使用新网络运行第二次推理。 Then you combine your results.然后你结合你的结果。

If you use the first option then you could do the following:如果您使用第一个选项,那么您可以执行以下操作:

  1. Train the network on your data and save the new detection head weights.根据您的数据训练网络并保存新的检测头权重。
  2. Create a new network that has the same backbone but two detection heads: one with the original weights and the second head with the new weights.创建一个具有相同主干但有两个检测头的新网络:一个具有原始权重,第二个具有新权重。

The idea is that because the backbone is the same for both we can use the backbone to extract the features for the image and then feed each detection head with the features.这个想法是,因为两者的主干是相同的,我们可以使用主干来提取图像的特征,然后将这些特征提供给每个检测头。

This is a tutorial on how to extract weights from one graph and combine them in a new one (This is for TF1) TensorFlow: saving/restoring and mixing multiple models这是一个关于如何从一个图中提取权重并将它们组合成一个新图的教程(这适用于 TF1) TensorFlow:保存/恢复和混合多个模型

Here you can read on how to save and restore part of a model - save-and-restore-a-subset-of-variables在这里您可以阅读如何保存和恢复模型的一部分 - save-and-restore-a-subset-of-variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM