TensorFlow对象检测API:使用预训练模型在训练中更改班级数量时的分类权重初始化 [英] TensorFlow object detection api: classification weights initialization when changing number of classes at training using pre-trained models

查看:337
本文介绍了TensorFlow对象检测API:使用预训练模型在训练中更改班级数量时的分类权重初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不仅要使用特征提取器预训练的权重,还要利用特征图图层的分类器/本地化预训练的权重来使用Tensorflow对象检测API微调Tensorflow对象检测模型(SSD).当我的新模型与用于微调检查点的预训练模型具有不同数量的类时,TensorFlow对象检测API将如何处理分类权重张量?

I want to utilize not only the feature-extractor pre-trained weights but also the feature-map layers' classifier/localization pre-trained weights for fine-tuning tensorflow object detection models (SSD) using tensorflow object detection API. When my new model has a different number of classes from the pre-trained model that I'm using for the fine-tuning checkpoint, how would the TensorFlow object detection API handle the classification weight tensors?

在ML对象检测模型(如SSD)中微调预训练的模型时,我不仅可以使用预训练的权重初始化特征提取器权重,还可以初始化特征图的本地化层权重和分类层权重,后者仅选择选择的经过预先训练的班级权重,这样我就可以减少模型最初可以识别的班级数量(例如,从90个MSCOCO班级减少到这90个班级中的任意一个班级,例如仅汽车和行人)等)
https://github.com/pierluigiferrari/ssd_keras/blob/master/weight_sampling_tutorial. ipynb
这是在keras模型中(即在h5文件中)完成的方式,我也想在Tensorflow对象检测API中执行相同的操作.似乎在训练时我可以在config protobuf文件中指定新模型将要拥有的类数,但是由于我是API(和tensorflow)的新手,所以我无法遵循源代码结构并了解如何在微调时处理该数字.我所知道的大多数SSD模型只是忽略并初始化分类权重张量,以防预训练模型的类权重形状不同于新模型的分类权重形状,但是我想保留必要的分类权重并对其进行训练.另外,我将如何在API结构中执行此操作?
谢谢!

When fine-tuning pre-trained models in ML object detection models like SSD, I can initialize not only the feature-extractor weights with the pre-trained weights but also initialize the feature-map's localization layer weights and classification layer weights, with latter only choosing the pre-trained class weights of choice, so that I can decrease the number of classes that the model can initially identify (for example from 90 MSCOCO classes to whichever classes of choice within those 90 classes like cars & pedestrian only etc.)
https://github.com/pierluigiferrari/ssd_keras/blob/master/weight_sampling_tutorial.ipynb
This is how it's done in keras models (ie in h5 files) and I want to do the same in Tensorflow object detection API as well. It seems that at training time I can specify the number of classes the new model is going to have in the config protobuf file, but since I'm new to the API (and tensorflow) I haven't been able to follow the source structure and understand how that number is going to be handled at fine-tuning. Most SSD models I know just ignore and initialize the classification weight tensor in case the pre-trained model's class weight shape is different from the new model's classification weight shape, but I want to retain the necessary classification weights and train upon those. Also, how would I do that within the API structure?
Thanks!

推荐答案

当我通读代码时,我发现了负责的代码,如果新定义的模型之间的层的形状相同,则该代码仅保留预先训练的模型的权重.与预训练的模型匹配.因此,如果我更改班级的数量,分类器层的形状就会更改,并且不会保留预训练的权重.

As I read through the code I found the responsible code, which only retains the pre-trained model's weights if the shape of the layers between the newly-defined model and the pre-trained model match. So if I change the number of the class, the shape of the classifier layers change, and the pre-trained weights are not retained.

https://github.com /tensorflow/models/blob/master/research/object_detection/utils/variables_helper.py#L133

这篇关于TensorFlow对象检测API:使用预训练模型在训练中更改班级数量时的分类权重初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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