如何微调现有的Tensorflow对象检测模型以识别其他类? [英] How to Fine tune existing Tensorflow Object Detection model to recognize additional classes?

查看:56
本文介绍了如何微调现有的Tensorflow对象检测模型以识别其他类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢Google提供很少使用带有tensorflow API的预训练模型.

Thanks to Google for providing a few pre-trained models with tensorflow API.

我想知道如何通过向模型添加新的类来重新训练上述存储库中可用的预训练模型.例如,经过训练的COCO数据集模型有90个类别,我想在现有的1个或2个类别中添加一个,从而得到一个92个类别的对象检测模型.

I would like to know how to retrain a pre-trained model available from the above repository, by adding new classes to the model. For example, the trained COCO dataset model has 90 classes, I would like to add 1 or 2 classes to the existing one and get one 92 class object detection model as a result.

本地运行由存储库,但它完全用新训练的课程替换了那些预先训练的课程.在那里,只提及火车和评估.

Running Locally is provided by the repository but it is completely replacing those pre-trained classes with newly trained classes. There, only train and eval are mentioned.

那么,还有其他方法可以重新训练模型并获得92个类吗?

So, is there any other way to retrain the model and get 92 classes as a result?

推荐答案

问题:如何向我已经训练有素的网络中添加更多的课程?

具体来说,我们希望所有网络保持不变,而不是新类的输出.这意味着对于像ResNet这样的东西,我们希望冻结除最后一层以外的所有内容,并以某种方式扩展最后一层以拥有我们的新类.

Specifically, we want to keep all the network as-is other than the output of the new classes. This means that for something like ResNet, we want to keep everything other than the last layer frozen, and somehow expand the last layer to have our new classes.

答案:将现有的最后一层与您要训练的新层相结合

具体来说,我们将用完全连接的层替换最后一层,该层对于新类和旧类都足够大.使用随机权重对其进行初始化,然后在您的课程和其他课程中对其进行训练.训练后,将原始的最后一个完全连接层的原始权重复制到新的经过训练的完全连接层中.

Specifically, we will replace the last layer with a fully connected layer that is large enough for your new classes and the old ones. Initialize it with random weights and then train it on your classes and just a few of the others. After training, copy the original weights of the original last fully connected layer into your new trained fully connected layer.

例如,如果先前的最后一层是1024x90矩阵,而新的最后一层是1024x92矩阵,则将1024x90复制到新的1024x92中的相应空间中.这将破坏性地将您对旧班级的所有培训替换为预先培训的值,而将您的培训留给新班级.那样很好,因为您可能没有使用相同数量的旧课程进行培训.如果有偏见,请做同样的事情.

If, for example, the previous last layer was a 1024x90 matrix, and your new last layer is a 1024x92 matrix, copy the 1024x90 into the corresponding space in your new 1024x92. This will destructively replace all your training of the old classes with the pre-trained values but leave your training of your new classes. That is good, because you probably didn't train it with the same number of old classes. Do the same thing with the bias, if any.

您的最终网络将仅具有1024x2的新权重值(加上任何偏差),与您的新类别相对应.

Your final network will have only 1024x2 new weight values (plus any bias), corresponding to your new classes.

请注意,尽管这样做可以快速训练并提供快速的结果,但是在对完整而全面的数据集进行重新训练时,效果不佳.

也就是说,它仍然可以很好地工作;)

That said, it'll still work well ;)

这里是有关如何替换最后一层的参考

Here is a reference to how to replace the last layer How to remove the last layer from trained model in Tensorflow that someone else answered

这篇关于如何微调现有的Tensorflow对象检测模型以识别其他类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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