卷积块的数组切片
我对数组切片符号感到困惑。
def hypernetwork(self, inputs):
x = self.fc(inputs)
return x[..., :self.channels], x[..., self.channels:]
回报是什么? ...,
是什么意思? self.channels 定义为输入的通道数。我认为 x 只是输入特征块。下面是self.fc
和self.channels
的相关代码
def build(self, input_shape):
self.channels = input_shape[0][-1] # input_shape: [x, z].
self.fc = KL.Dense(
int(2 * self.channels),
kernel_initializer=self.init,
kernel_regularizer=tf.keras.regularizers.l2(
l=self.wt_decay,
),
bias_regularizer=tf.keras.regularizers.l2(
l=self.wt_decay,
),
)
I get confused by a array slicing notation.
def hypernetwork(self, inputs):
x = self.fc(inputs)
return x[..., :self.channels], x[..., self.channels:]
what is the return? what does ...,
mean? The self.channels
is defined as the number of channels of the input. I think x
is just the input feature block. Below is the relevant code for self.fc
and self.channels
def build(self, input_shape):
self.channels = input_shape[0][-1] # input_shape: [x, z].
self.fc = KL.Dense(
int(2 * self.channels),
kernel_initializer=self.init,
kernel_regularizer=tf.keras.regularizers.l2(
l=self.wt_decay,
),
bias_regularizer=tf.keras.regularizers.l2(
l=self.wt_decay,
),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
...
时,您指的是除最后一个维度(您正在切片)之外的所有维度。它等价于其他表示法x[:, :, :channels]
:You are referring to all the dimensions except the last one (which you are slicing) when using
...
. It is equivalent to the other notationx[:, :, :channels]
:...
表示所有维度的所有元素,直到您开始显式引用(使用:self.channels
进行引用)。因此,总而言之,如果 x 是一个 10x4x6 数组,而 self.channels 是 4,则输出将是一个 10x4x4 数组和一个 10x4x2 数组。
如果 x 是 10x6 并且 self.channels 是 2,您将得到一个 10x2 和一个 10x4 数组。您将沿着最后一个维度分割数组。
...
means all elements of all dimensions until you start explicitely referencing, which you do with the:self.channels
.So in conclusion if
x
is e.g. a 10x4x6 array andself.channels
is 4, the output will be one 10x4x4 array and one 10x4x2 array.If
x
is 10x6 andself.channels
is 2, you'll get a 10x2 and a 10x4 array. You're splitting the array along the last dimension.