gpt4 book ai didi

带有 is_training True 和 False 的 Tensorflow (tf-slim) 模型

转载 作者:行者123 更新时间:2023-12-01 04:53:15 28 4
gpt4 key购买 nike

我想在训练集( is_training=True )和验证集( is_training=False )上运行给定的模型,特别是如何 dropout被申请;被应用。现在 prebuilt models公开一个参数 is_training已通过 dropout构建网络时的层。问题是如果我使用不同的值 is_training 调用该方法两次,我会得到两个不共享权重的不同网络(我认为?)。我如何让两个网络共享相同的权重,以便我可以运行我在验证集上训练过的网络?

最佳答案

我用您的评论写了一个解决方案,以在训练和测试模式下使用 Overfeat。 (我无法测试它所以你可以检查它是否有效?)

首先是一些导入和参数:

import tensorflow as tf
slim = tf.contrib.slim
overfeat = tf.contrib.slim.nets.overfeat

batch_size = 32
inputs = tf.placeholder(tf.float32, [batch_size, 231, 231, 3])
dropout_keep_prob = 0.5
num_classes = 1000

在训练模式下,我们通过一个 正常范围到函数 overfeat :

scope = 'overfeat'
is_training = True

output = overfeat.overfeat(inputs, num_classes, is_training,
dropout_keep_prob, scope=scope)

然后在测试模式下,我们创建相同的范围,但使用 reuse=True .

scope = tf.VariableScope(reuse=True, name='overfeat')
is_training = False

output = overfeat.overfeat(inputs, num_classes, is_training,
dropout_keep_prob, scope=scope)

关于带有 is_training True 和 False 的 Tensorflow (tf-slim) 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39353503/

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