简体   繁体   English

预测时,tflearn.models.dnn.DNN是否会自动关闭辍学层并进行批量归一化?

[英]Does tflearn.models.dnn.DNN automatically turn off dropout layers and batch normalization when predicting?

I'm quite new to Neural Networks, which is why I've decided to use Tflearn because it is quite intuitive. 我对神经网络很陌生,这就是为什么我决定使用Tflearn的原因,因为它非常直观。 However I couldn't find an answer to my question. 但是我找不到我的问题的答案。 The tflearn documentation gives the following example for letting a deep neural network predict something: tflearn文档提供了以下示例,可让深度神经网络预测某些内容:

network = ...
model = DNN(network)
model.load('model.tflearn')
model.predict(X)

I've inserted some batch normalization layers inside the network because my model seemed to be overfitting. 我在网络中插入了一些批处理规范化层,因为我的模型似乎过拟合。 Will model.predict() automatically "tell" the batch normalization layer not to behave like in a training phase? model.predict()是否会自动“告诉”批处理规范化层,使其不像训练阶段那样? Or do I have to specify this somehow with tflearn.config.is_training (is_training=False, session=None) ? 还是我必须使用tflearn.config.is_training (is_training=False, session=None)

If yes, do you know where I should put this line? 如果是,您知道我应该把这行放在哪里吗? And how do I create my session so that it does the same like my code. 以及如何创建会话,使其像我的代码一样执行。 At the moment it basically looks like the example at tflearn.org: 目前,它基本上看起来像是tflearn.org上的示例:

net = tflearn.input_data(shape=[None, 784])
net = tflearn.fully_connected(net, 64)
net = tflearn.dropout(net, 0.5)
net = tflearn.fully_connected(net, 10, activation='softmax')
net = tflearn.regression(net, optimizer='adam', 
loss='categorical_crossentropy')

model = tflearn.DNN(net)
model.fit(X, Y)

except that I use a batch normalization layer and I use the neural network for function approximation. 除了我使用批处理归一化层,并使用神经网络进行函数逼近。 Unfortunately I cannot post my code right now,since it's on another Computer but it really is basically the same. 不幸的是,我现在无法发布代码,因为它在另一台计算机上,但实际上基本上是相同的。

Could someone help me with this question? 有人可以帮我解决这个问题吗?

Thanks in advance! 提前致谢!

You need to set tflearn.is_training to True or False when you are training and predicting, and tflearn will take care of the rest. 在训练和预测时,您需要将tflearn.is_training设置为True或False,tflearn将负责其余的工作。 Once you define your model, you can train it by: 定义模型后,您可以通过以下方法进行训练:

with tf.Session() as sess:
    tflearn.is_training(True, session=sess)
 model.fit(X, Y)

and then predict using: 然后预测使用:

with tf.Session as sess:
    tflearn.is_training(False, session=sess)
model.predict(X)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM