- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近开始使用 Tensorflow,并一直在尽力适应环境。这真是太棒了!然而,使用 tf.contrib.layers.batch_norm 进行批量归一化有点棘手。现在,这是我正在使用的函数:
def batch_norm(x, phase):
return tf.contrib.layers.batch_norm(x,center = True, scale = True,
is_training = phase, updates_collections = None)
使用这个,我遵循了我在网上找到的大多数文档(还有问答),这使我得出以下结论:
1) is_training 对于训练应设置为 True,对于测试应设置为 false。这是有道理的!训练时,我收敛了(误差 < 1%,Cifar 10 数据集)。
但是在测试过程中,我的结果很糟糕(错误> 90%),除非我将(更新集合=无)作为参数添加到上面的批规范函数中。只有以此作为参数,测试才会给出我预期的错误。
我也确信使用以下内容进行培训:
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops): # Ensures, Updating ops will perform before training
with tf.name_scope('Cross_Entropy'):
cross_entropy = tf.reduce_mean( # Implement Cross_Entropy to compute the softmax activation
tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y_conv)) # Cross Entropy: True Output Labels (y_), Softmax output (y_conv)
tf.summary.scalar('cross_entropy', cross_entropy) # Graphical output Cross Entropy
with tf.name_scope('train'):
train_step = tf.train.AdamOptimizer(1e-2).minimize(cross_entropy) # Train Network, Tensorflow minimizes cross_entropy via ADAM Optimization
with tf.name_scope('Train_Results'):
with tf.name_scope('Correct_Prediction'):
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1)) # Check if prediction is wrong with tf.equal(CNN_result,True_result)
with tf.name_scope('Accuracy'):
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # Find the percent accuracy, take mean of correct_prediction outputs
tf.summary.scalar('accuracy', accuracy) # Graphical output Classification Accuracy
这应该确保批量归一化参数在训练期间更新。
所以这让我相信 update collections = None 只是我的批量标准化函数的一个很好的默认值,在测试过程中函数将确保不会调整任何批量标准化参数......我是对的吗?
最后:在测试阶段,打开和关闭批量标准化时获得良好结果(预期错误)是否正常?使用上面的批归一化函数,我能够很好地训练(is_training = True)和测试(is_training = False)。然而,在测试期间(is_training = True)我仍然能够获得很好的结果。这只是给我一种不好的感觉。有人可以解释为什么会发生这种情况吗?或者它是否应该发生?
感谢您的宝贵时间!
最佳答案
移动平均值
不稳定的衰减
率(默认0.999)可能是训练性能相当良好但验证/测试性能较差的原因。尝试稍低的衰减
率(0.99 或0.9)。另外,请尝试 zero_debias_moving_mean=True
以提高稳定性。
您还可以尝试不同的批量大小,看看验证性能是否有所提高。使用批量归一化时,大批量可能会破坏验证性能。请参阅this .
关于Tensorflow批量标准化: tf. contrib.layers.batch_norm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47953242/
我是 Keras 新手,我正在尝试获取 Keras 中的权重。我知道如何在 Python 中的 Tensorflow 中执行此操作。 代码: data = np.array(attributes, '
我正在尝试为上下文强盗问题 (https://medium.com/emergent-future/simple-reinforcement-learning-with-tensorflow-part
我尝试在单击时向 map 添加新标记,并尝试保存标题和描述以在标记悬停时显示,但出现以下错误: Cannot read property 'add Layer' of undefined Javasc
我想要一个传单图层控件,我可以在其中选择一个基础图层,并使这个基础图层本身成为一个 LayerGroup,我可以从中选择要显示的子图层。我正在考虑一个设置,我单击一个单选按钮来选择基础层(层组),然后
我在 GIMP Script-fu 和过程浏览器中遇到了一个简单的问题。 我正在尝试在具有 40 层的图像中向上/向下移动一个层。让我们调用图像 test.xcf 和所述层 Chromask-snap
我有一个(非常大的)脚本在 InDesign 中运行,该脚本在某一时刻将库资源放置到页面上,然后将其移动到特定图层。此脚本在我们这里的所有计算机上都运行良好,但仅当当时 InDesign 中没有打开其
在一些使用 tf2 的 Tensorflow 教程(例如 Neural Machine Translation with Attention 和 Eager essentials )中,他们定义了自定
现在我无法解决依赖性,怎么了? 公司会更改名称吗?但是,我在他们的网站上看到它,但没有“com.layer.atlas:layer-atlas”,但是我的应用程序包含此依赖项,谁能告诉我原因? 最佳答
我使用 Keras 并尝试将两个不同的层连接成一个向量(向量的第一个值是第一层的值,另一部分是第二层的值)。 其中一层是密集层,另一层是嵌入层。 我知道如何合并两个嵌入层或两个密集层,但我不知道如何合
我正在开发一个类来创建各种对称 AE。我现在把这个类移植到TF 2.0,比我想象的要复杂。但是,我使用层和模型的子类来实现此目的。因此,我想将多个 keras 层分组为一个 keras 层。但如果我想
我正在为 CAGradient 设置动画 let gradientChangeAnimation = CABasicAnimation(keyPath: "colors") gradientC
什么是使用 OOP 在业务逻辑对象和数据库之间分层的良好设计? 最佳答案 这些中的任何一个都可以( from Fowler's POEAA ): 数据源架构模式: 表数据网关:充当数据库表网关的对象。
我正在尝试将一些 UIImages 渲染成一张我可以保存在我的相册中的图像。但是好像 layer.renderInContext 没有考虑图层蒙版? 当前行为:照片保存,我看到了 mosaicLaye
哇,这完全令人困惑,而且 dojo 1.8 文档似乎是围绕构建层的完整 clusterf**k。有人知道那里发生了什么吗? 在构建脚本示例配置文件中,示例 amd.profile.js 有 profi
我的 spacemacs 是 0.200.3@25.1.1 每次启动spacemacs时都会收到警告,如何解决? Warnings: - dotspacemacs-configuration-laye
引用是这样的: There's no problem in Computer Science that can't be solved by adding another layer of abstr
我正在使用 Keras 并且有一个自定义层,但是当我使用它时,会发生以下错误,我不知道问题是什么。你能帮我解决这个问题吗?奇怪的是,当我在另一个系统上使用相同的代码时,没有出现此错误! import
我应该什么时候使用 Input我什么时候应该使用 InputLayer ?在 source code有一个描述,但我不确定它是什么意思。 输入层: Layer to be used as an ent
我正在尝试构建一个可以在音频和视频样本上进行训练的模型,但出现此错误 ValueError:请使用“Layer”实例初始化“TimeDistributed”层。您传递了:Tensor("input_1
我正在实现一个需要支持 mask 的自定义 tf.keras.layers.Layer。 考虑以下场景 embedded = tf.keras.layer.Embedding(input_dim=vo
我是一名优秀的程序员,十分优秀!