图层删除和更新Caffe模型 [英] Layer drop and update caffe model

查看:87
本文介绍了图层删除和更新Caffe模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从现有的caffe模型中更新caffe模型,在该模型中我将删除最后两层.需要减小Caffe模型的大小,以便更轻松,更小地部署.假设我现有的caffe模型是 A1.caffemodel ,它具有 5个卷积层 3个全连接层.我想从中生成一个名为 B1.caffemodel 的新模型,该模型将具有 5个卷积层 1个完全连接 层(最后2个fc层被丢弃).

I need to update a caffe model from an existing caffe model where I will drop last two layers. It is needed to reduce caffe model size so that it would be easier and lesser size to deploy. Say my existing caffe model is A1.caffemodel which has 5 convolution layers and 3 fully connected layers. I want to generate a new model from it named B1.caffemodel which will have 5 convolution layers and 1 fully connected layer (last 2 fc layers discarded).

感谢您提出的所有宝贵建议和有用的代码段.

I appreciate your all valuable suggestions and helpful code snippet.

推荐答案

完全连接的层确实很重.请查看 Girshick,R Fast-RCNN ICCV 2015 描述如何使用 SVD 技巧显着减轻了全连接层的负担.因此,您可以将6个非常薄的层替换为3个完全连接的层.

Fully connected layers can indeed be very heavy. Please look at section "3.1 Truncated SVD for faster detection" at Girshick, R Fast-RCNN ICCV 2015 describing how to use SVD trick to significalntly reduce the burden of fully connected layers. Hence, you can replace your three fully connected layers with 6 very thin layers.

从模型 A B 的步骤:

  1. 创建具有5个卷积层的 B.prototxt A .

B 中的单个完全连接层提供一个新的名称" ,该新名称在 A 中不存在.

Give the single fully connected layer in B a new "name" that does not exist in A.

在python

import caffe
B = caffe.Net('/path/to/B.prototxt', '/path/to/weights_A.caffemodel', caffe.TEST)
B.save('/path/to/weights_B.caffemodel')

  • 现在,您对 B 的权重与所有卷积层的 A 的权重相同,对于所有卷积层的 random 新的单一完全连接层.

  • Now you have weights for B that are the same as the weights of A for all convolutional layers and random for the new single fully connected layer.

    微调模型 B 来学习新的单个完全连接层的权重.

    fine tune model B starting from '/path/to/weights_B.caffemodel' to learn the weights for the new single fully connected layer.

    这篇关于图层删除和更新Caffe模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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