如何在预训练的对象检测模型中添加其他类并对其进行训练以检测所有类(预训练的+新的)? [英] How to add additional classes to a pre-trained object detection model and train it to detect all of the classes (pre-trained + new)?

查看:89
本文介绍了如何在预训练的对象检测模型中添加其他类并对其进行训练以检测所有类(预训练的+新的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关注了此博客->

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".

这里发生的是,它可以完美地检测到我的新课程,但是我也想包括经过预训练的课程.

What happens here is that it perfectly detects my new classes, but I want to include the pre-trained classes as well.

我尝试将类数更改为96(90个预训练+ 6个新类),并使用来自COCO数据集的所有标签的名称和相应ID编辑了"labelmap.pbtxt",并在其中添加了新类最后从ID 91-96开始.

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.

它仍然仅仅检测新类.

我该怎么做才能同时检测预训练课程和新课程?

What should I do to detect both the pre-trained and new classes?

推荐答案

这取决于您使用预先训练的权重的方式:

It depends on how you use the pre trained weights:

  1. 用于迁移学习(我认为您发送的链接就是他们的工作)
  2. 使用为整个模型的拟合提供了起点.

第一个选项仅训练检测头,而不训练网络的主干-这意味着主干权重位于模型和原始模型之间.

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. 训练网络上的数据并保存新的检测头权重.
  2. 创建一个具有相同主干但有两个检测头的新网络:一个带有原始砝码,另一个带有新砝码.

这个想法是因为因为两者的主干都相同,所以我们可以使用主干提取图像的特征,然后为每个检测头提供特征.

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.

这是一本有关如何从一个图形中提取权重并将其合并为一个新的权重的教程(这是针对TF1的).

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

在这里您可以阅读如何保存和还原模型的一部分-

Here you can read on how to save and restore part of a model - save-and-restore-a-subset-of-variables

这篇关于如何在预训练的对象检测模型中添加其他类并对其进行训练以检测所有类(预训练的+新的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆