gpt4 book ai didi

python - Keras NASNet 训练

转载 作者:行者123 更新时间:2023-12-05 07:25:28 30 4
gpt4 key购买 nike

我打算:

  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 需要 (331,331,3),但它非常大,我看到 imagenet 正在使用差异大小进行训练。我可以使用较小的图像,例如 (120,120,3) 并替换顶层吗?这仍然会被视为迁移学习,对吧?然而,NASNet 最后一层似乎是一种特殊类型的单元格,我该如何实现?

  3. 如果我想从头开始训练,是否可以确认我设置了include_top = False,并在最后添加了全连接层?

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

最佳答案

以下是您问题的答案:

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,则不会加载用于进行预测的模型的全连接输出层,从而允许您添加一个新的要添加和训练的输出层。

Is it a requirement to have input images in the same shape as 
specified? NASNet requires (331,331,3) but that is quite large and i
see imagenet being trained with diff sizes. Can I use smaller images
such as (120,120,3) and replace the top layer? This would still be
considered transfer learning right? However, the NASNet last layer
seems to be a special type of cell, how would I implement that?

reshape 图像非常重要,使它们与预训练模型(例如 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

关于python - Keras NASNet 训练,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54788058/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com