Keras NASNet训练

2024-05-16 22:05:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我打算:

  1. 在数据集上从头开始训练NASNet
  2. 仅重新培训NASNet的最后一层(转移学习)

比较他们的相对表现。从文档中我看到:

keras.applications.nasnet.NASNetLarge(input_shape=None, include_top=True, weights='imagenet', input_tensor=None, pooling=None, classes=1000)

不过,文档有点混乱。在

问题:

  1. 对于转移学习,我是否要设置include_top = Trueclasses = (num_classes),冻结除最后一层之外的所有层,然后对其进行训练吗?

  2. 是否要求输入图像与指定的形状相同?NASNet需要(331331,3),但这是相当大的,我看到imagenet正在使用不同的大小进行训练。我可以使用较小的图像,如(120120,3)并替换顶层吗?这还算是转移学习吧?然而,NASNet的最后一层似乎是一种特殊类型的单元,我该如何实现它呢?

  3. 如果我想从头开始训练,我能确认我设置了include_top = False,并在末尾添加完全连接的层吗?

理想的情况下,如果有一个教程,说明如何从零开始训练NASNet,以及在新的数据集上进行转移学习,那就太好了。我为imagenet找到了一个,但是他自己构建了模型层,而不是使用keras.applications。在


Tags: 数据文档图像nonetrueinputincludetop
1条回答
网友
1楼 · 发布于 2024-05-16 22:05:23

以下是您问题的答案:

For transfer learning, do I set include_top = True and classes = 
(num_classes), freeze all the layers except the last one, then train 
that?

加载要用于传输学习的任何模型时,如果将“include_top”参数设置为False,则不会加载用于进行预测的模型的完全连接的输出层,从而允许您添加要添加和训练的新输出层。在

^{pr2}$

对你来说重塑图像是非常重要的,使它们与预训练模型(如NasNet)的图像大小相同,否则会导致偏差。在

If I want to train from scratch, can I confirm that i set include_top = 
False, and add fully connected layers to the end?

“include_top”参数与是否必须训练整个模型或冻结模型无关。下面是如何训练整个模型以及模型的一部分的示例:

for layer in model.layers:
    layer.trainable=False
# or if we want to set the first 20 layers of the network to be non- 
trainable
for layer in model.layers[:20]:
    layer.trainable=False
for layer in model.layers[20:]:
    layer.trainable=True

相关问题 更多 >