简体   繁体   English

张量流中任何预训练模型的子集

[英]subset of any pre-trained model in tensorflow

Can we take subset of any pre-trained model in tensorflow? 我们可以在张量流中采用任何预训练模型的子集吗? For example, if we have a pre-trained model which can detect 545 obejcts, can we make a subset of this model which can detect only 20 objects so that the time taken to load the model as well as the detection process can be reduced. 例如,如果我们有一个预训练的模型可以检测545个对象,那么我们可以使该模型的子集仅检测20个对象吗,这样就可以减少加载模型所需的时间以及检测过程。

The best you can do is reduce the weights that are related to the last (output) layer only. 最好的办法是减少仅与最后一个(输出)层有关的权重。 So, if the size of your second last layer is 1000 so it will reduce your parameters by (1000 * 545 - 1000 * 20) = 525000. 因此,如果倒数第二层的大小为1000,那么它将使您的参数减少(1000 * 545-1000 * 20)= 525000。
But, if your network is very deep this won't prove to be a great speedup, as you will still need to calculate all the other layers except the last one. 但是,如果您的网络很深,那么这将不会带来很大的提速,因为您仍然需要计算除最后一层以外的所有其他层。

You could, but it's a non-negligible amount of work, and it won't substantially improve the speed. 您可以,但是这是一笔微不足道的工作,并且不会显着提高速度。

Indeed, what you'd need to change is only the class prediction layer, which you'd have to reduce from n_featuresx545 to n_featuresx20 . 确实,您只需要更改类预测层,就可以将其从n_featuresx545减少到n_featuresx20 Typically at that stage you have n_features=7*7=49 (although it actually depends on the method you're using; this is true for Faster RCNN with usual settings), so you'd save approximately 26k parameters and 8million operations per image (considering 300 detections per image), which is negligible compared to the millions of parameters and billions of operations usually involved in object detection models. 通常在该阶段,您有n_features=7*7=49 (尽管这实际上取决于您使用的方法;对于具有常规设置的Faster RCNN而言,这是正确的),因此每个图像可以节省大约26k参数和8million操作(每张图像考虑300次检测),与对象检测模型中通常涉及的数百万个参数和数十亿次操作相比,可以忽略不计。

And changing the prediction layer without retraining and while keeping the trained values is not staight-forward, you'd have to write a piece of code to modify your network manually. 在不进行重新训练的情况下更改预测层并保持训练值的过程并非一帆风顺,您必须编写一段代码来手动修改网络。

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

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