假设我有两个功能映射,F1和F2由网络输出。我要计算F1和F2的卷积。假设F1具有形状( 1,C,10,10),F2具有形状(1,C,3,3),如果pad = 0,shape = 1,dilate =1,则希望的结果应该是形状(1,1,8,8)。但是,这样我只能将批大小设置为1,因为卷积层的核与批大小无关,所以不能用一批输出数据来设置权重。
如何使用MXNet实现这一点?
我想出了一种使用mx.sym.Correlation的可能方法,但我无法理解关联操作符是如何通过读取文档来计算的。或者,我是否可以将mx.sym.Convolution层的权重设置为F2,将数据设置为F1?这会不会妨碍毕业生在训练时的传播?
我想要做的更新如下所示:
所谓相关性,我指的是F2就像一个在F1上滑动的相关内核(或卷积内核)。例如,
1 1 1 2 2
F1 = 2 3 4 1 1
0 0 0 2 3
0 1 0
F2 = 1 0 1
0 1 0那么,相关的结果应该是
R = F1 * F2 = 7 5 9 哪里
1 1 1 0 1 0
7 = 2 3 4 x 1 0 1 = 1 + 2 + 4 + 0
0 0 0 0 1 0
1 1 2 0 1 0
5 = 3 4 1 x 1 0 1 = 1 + 3 + 1 + 0
0 0 2 0 1 0
1 2 2 0 1 0
9 = 4 1 1 x 1 0 1 = 2 + 4 + 1 + 2
0 2 3 0 1 0在上面的例子中,stride = 1,pad = 0,dilate =0
发布于 2018-02-06 01:44:29
您应该能够直接使用mx.sym.Convolution (使用batch_size >= 1)。
通过使用mx.nd.NDArray,我们可以更容易地检查数组,最终的输出形状是(batch_size,num_filters,8,8),即(1,1,8,8)。
您将能够将mx.nd替换为mx.sym以使用mx.sym.Symbol。核子的重量也可以训练。
import mxnet as mx
import numpy as np
num_batches = 1
num_channels = 3 # called C in question
num_filters = 1
kernel_shape = (3, 3)
data_shape = (10, 10)
data = mx.nd.random_uniform(shape=(num_batches, num_channels) + data_shape)
# called f1 in question
print("data (f1) shape: " + str(data.shape))
# >>>> data (f1) shape: (1, 3, 10, 10)
weights = mx.nd.random_uniform(shape=(num_filters, num_channels) + kernel_shape)
# called f2 in question
print("weights (f2) shape: " + str(weights.shape))
# >>>> weights (f2) shape: (1, 3, 3, 3)
conv = mx.nd.Convolution(data=data, weight=weights, num_filter=num_filters, kernel=kernel_shape, no_bias=True)
print("convolution output shape: " + str(conv.shape))
# >>>> convolution output shape: (1, 1, 8, 8)https://stackoverflow.com/questions/47122690
复制相似问题