带有 is_training True 和 False 的 Tensorflow (tf-slim) 模型 [英] Tensorflow (tf-slim) Model with is_training True and False
问题描述
我想在训练集 (is_training=True
) 和验证集 (is_training=False
) 上运行给定模型,特别是如何<应用代码>dropout.现在
I would like to run a given model both on the train set (is_training=True
) and on the validation set (is_training=False
), specifically with how dropout
is applied. Right now the prebuilt models expose a parameter is_training
that is passed it the dropout
layer when building the network. The issue is that If I call the method twice with different values of is_training
, I will get two different networks that do no share weights (I think?). How do I go about getting the two networks to share the same weights such that I can run the network that I have trained on the validation set?
推荐答案
我根据您的评论编写了一个解决方案,以在训练和测试模式下使用 Overfeat.(我无法测试它所以你可以检查它是否有效?)
I wrote a solution with your comment to use Overfeat in train and test mode. (I couldn't test it so you can check if it works?)
首先是一些导入和参数:
First some imports and parameters:
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) 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!