深度学习:使用预先训练的网络的早期激活 [英] Deep Learning: Using a pretrained network's earlier activations

查看:122
本文介绍了深度学习:使用预先训练的网络的早期激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约25k图像,它们属于14种不同的类别(不同类型的领口,例如v领,圆领等).图像主要包含服装的顶部和/或模型的脸部.以下是一些示例:

I have around 25k images belonging to 14 different classes (different kinds of neck-lines, e.g. v-neck, round neck, etc). The images mainly contain the the top-part of the apparel and/or the face of the model. Here are some examples:

为此,我考虑在VGG16的第一个块(在imagenet上进行预训练)之后提取特征,因为较早的块的特征图将捕获事物线,形状等.这是model.summary() :

In order to do this, I thought of extracting the features after the 1st block of VGG16 (pretrained on imagenet) because the feature map of the earlier blocks will be capturing things lines, shapes, etc. Here is the model.summary():

Layer (type)                 Output Shape              Param #   
=================================================================
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
_________________________________________________________________
flatten (Flatten)            (None, 802816)            0         
_________________________________________________________________
fc1 (Dense)                  (None, 4096)              3288338432
_________________________________________________________________
fc2 (Dense)                  (None, 4096)              16781312  
_________________________________________________________________
predictions (Dense)          (None, 16)                65552     
=================================================================
Total params: 3,305,224,016
Trainable params: 3,305,224,016
Non-trainable params: 0

问题在于参数总数巨大.考虑到我的特定数据集,您能否建议如何减少呢?

The problem is that the total number of parameters is huge. Can you please advise, considering my specific dataset, how to reduce that?

推荐答案

如果您使用的是预先训练的模型,则不必重新训练较低的层,而只需保持最后几个分类层可训练.例如,如果您想冻结前6层,则可以调用:

If you are using a pre-trained model, you don't have to re-train the lower layers and just keep the last few classification layers to be trainable. For example, if you'd like to freeze the first 6 layers you can call:

for idx, layer in enumerate(model.layers[:6]):
    print('Make layer {} {} untrainable.'.format(idx, layer.name))
    layer.trainable = False

然后,如果调用model.summary(),您会看到可训练的参数要少得多,这不仅可以使训练更快,而且在不更改预训练的卷积层的情况下通常可以提供更好的结果.

Then if you call the model.summary(), you'll see that you have much less trainable parameters which will not only make the training faster but usually provides better results when you do not alter the pre-trained convolutional layers.

这篇关于深度学习:使用预先训练的网络的早期激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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