Пример #1
0
    def alloc_layer_param(self, input_shape):
        assert len(input_shape) == 3
        xh, xw, xchn = input_shape
        sh, sw = cm.get_conf_param_2d(self.stride)
        assert xh % sh == 0
        assert xw % sw == 0

        return [xh // sh, xw // sw, xchn]
Пример #2
0
    def alloc_layer_param(self, input_shape, rand_std=0.030):
        assert len(input_shape) == 3
        xh, xw, xchn = input_shape
        kh, kw = cm.get_conf_param_2d(self.ksize)
        ychn = self.chn
        kernel = np.random.normal(0, rand_std, [kh, kw, xchn, ychn])
        bias = np.zeros([ychn])

        # if self.show_maps: self.kernels.append(kernel)
        self.param = {'k': kernel, 'b': bias}
        return [xh, xw, ychn]
Пример #3
0
    def forward_layer(self, x):
        mb_size, xh, xw, chn = x.shape
        sh, sw = cm.get_conf_param_2d(self.stride)
        yh, yw = xh // sh, xw // sw

        x1 = x.reshape([mb_size, yh, sh, yw, sw, chn])
        x2 = x1.transpose(0, 1, 3, 5, 2, 4)
        x3 = x2.reshape([-1, sh * sw])

        y_flat = np.average(x3, 1)
        y = y_flat.reshape([mb_size, yh, yw, chn])

        # if self.need_maps: self.maps.append(y)

        return y
Пример #4
0
    def backprop_layer(self, G_y):
        mb_size, yh, yw, chn = G_y.shape
        sh, sw = cm.get_conf_param_2d(self.stride)
        xh, xw = yh * sh, yw * sw

        gy_flat = G_y.flatten() / (sh * sw)

        gx1 = np.zeros([mb_size * yh * yw * chn, sh * sw], dtype='float32')
        for i in range(sh * sw):
            gx1[:, i] = gy_flat
        gx2 = gx1.reshape([mb_size, yh, yw, chn, sh, sw])
        gx3 = gx2.transpose([0, 1, 4, 2, 5, 3])

        G_input = gx3.reshape([mb_size, xh, xw, chn])

        return G_input, None
Пример #5
0
    def forward_layer(self, layer_input):
        mb_size, xh, xw, chn = layer_input.shape
        sh, sw = cm.get_conf_param_2d(self.stride)
        yh, yw = xh // sh, xw // sw

        x1 = layer_input.reshape([mb_size, yh, sh, yw, sw, chn])
        x2 = x1.transpose(0, 1, 3, 5, 2, 4)
        x3 = x2.reshape([-1, sh * sw])

        idxs = np.argmax(x3, axis=1)
        layer_output_flat = x3[np.arange(mb_size * yh * yw * chn), idxs]
        layer_output = layer_output_flat.reshape([mb_size, yh, yw, chn])

        # if self.need_maps: self.maps.append(y)
        self.aux = idxs
        return layer_output