计算给定输入大小的过滤器的数量和大小

时间:2019-05-16 09:08:39

标签: conv-neural-network chainer

我有一个自动编码器来重新生成输入图像。图像形状为(10,1308608)。 1308608是4 * 644 * 508。

class AutoEncoder(chainer.Chain):
    def __init__(self, input_size, n_filters, n_units, filter_size, 
activation):
        self.activation = activation#{'relu': F.relu, 'sigmoid': 
F.sigmoid}[activation]
        self.n_filters = n_filters
        self.n_units = n_units
        self.filter_size = filter_size
        self.dim1 = input_size - filter_size + 1

        super(AutoEncoder, self).__init__(
            conv1 = L.Convolution2D(1, n_filters, filter_size),
            lenc1 = L.Linear(n_filters*self.dim1*self.dim1, n_units),
            ldec1 = L.Linear(n_units, n_filters*self.dim1*self.dim1),
            deconv1 = L.Deconvolution2D(n_filters, 1, filter_size)
        )

    def __call__(self, x):
        h1 = self.activation(self.conv1(x))
        h2 = F.dropout(self.activation(self.lenc1(h1)))
        h3 = F.reshape(self.activation(self.ldec1(h2)), (x.data.shape[0], 
self.n_filters, self.dim1, self.dim1))
        h4 = self.activation(self.deconv1(h3))
        return h4

class Regression(chainer.Chain):
    def __init__(self, predictor):
        super(Regression, self).__init__(predictor=predictor)

    def __call__(self, x, t):
        y = self.predictor(x)
        self.loss = F.mean_squared_error(y, t)
        report({'loss': self.loss}, self)
        return self.loss

    def dump(self, x):
        return self.predictor(x, False)

对于大小为(1,28,28)的小数,他们使用了input_size = 28,n_filters = 10,n_units = 20,filter_size =9。我想了解如何根据input_size计算n_filters,n_units,filter_size。

1 个答案:

答案 0 :(得分:1)

您可以参考Chainer official document for convolution_2d

输出高度可以计算为

hO = (hI+2 * hP − hK) / sY+1

其中

  • hO:输出高度
  • hI:输入高度
  • hP:填充大小
  • hK:内核大小
  • sY:步幅大小

宽度相同。