gpt4 book ai didi

python - *(星号)应用于 TensorFlow 层时会做什么?

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:04 25 4
gpt4 key购买 nike

当前正在阅读 Inception-ResNet 的 Python 实现,以协助使用不同语言 (Deeplearning4j) 构建模型。这个实现是 Inception-ResNet-v1,我试图弄清楚它是如何实现 ResNet 风格的残差快捷方式的。

下面的代码块是net += scale * up

# Inception-Renset-A
def block35(net, scale=1.0, activation_fn=tf.nn.relu, scope=None, reuse=None):
"""Builds the 35x35 resnet block."""
with tf.variable_scope(scope, 'Block35', [net], reuse=reuse):
with tf.variable_scope('Branch_0'):
tower_conv = slim.conv2d(net, 32, 1, scope='Conv2d_1x1')
with tf.variable_scope('Branch_1'):
tower_conv1_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1')
tower_conv1_1 = slim.conv2d(tower_conv1_0, 32, 3, scope='Conv2d_0b_3x3')
with tf.variable_scope('Branch_2'):
tower_conv2_0 = slim.conv2d(net, 32, 1, scope='Conv2d_0a_1x1')
tower_conv2_1 = slim.conv2d(tower_conv2_0, 32, 3, scope='Conv2d_0b_3x3')
tower_conv2_2 = slim.conv2d(tower_conv2_1, 32, 3, scope='Conv2d_0c_3x3')
mixed = tf.concat(3, [tower_conv, tower_conv1_1, tower_conv2_2])
up = slim.conv2d(mixed, net.get_shape()[3], 1, normalizer_fn=None,
activation_fn=None, scope='Conv2d_1x1')
net += scale * up
if activation_fn:
net = activation_fn(net)
return net

Scale 是 0 到 1 之间的 doubleup 是一层堆栈,最后一个是 conv2d 层。

扩大规模具体发生了什么?

最佳答案

up 中的每一层都乘以 scale 中的标量值。然后,net 被重新定义为 net + scale * up。因此 net 应该与 up 具有相同的尺寸。

关于python - *(星号)应用于 TensorFlow 层时会做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41657172/

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