Esempio n. 1
0
    def __call__(self, x, stage):
        # stage0: in0->m_std->out0_0->out0_1->out0_2
        # stage1: (1-a)*(down->in0) + (a)*(in1->b1) ->m_std->out0->out1->out2
        # stage2: in1->b1->m_std->out0_0->out0_1->out0_2
        # stage3: (1-a)*(down->in1) + (a)*(in2->b2) ->b1->m_std->out0->out1->out2
        # stage4: in2->b2->b1->m_std->out0->out1->out2
        # ...

        stage = min(stage, self.max_stage)
        alpha = stage - math.floor(stage)
        stage = math.floor(stage)

        if int(stage) % 2 == 0:
            fromRGB = getattr(self, "in%d" % (stage // 2))
            h = leaky_relu(fromRGB(x))
        else:
            fromRGB0 = getattr(self, "in%d" % (stage // 2))
            fromRGB1 = getattr(self, "in%d" % (stage // 2 + 1))
            b1 = getattr(self, "b%d" % (stage // 2 + 1))

            h0 = leaky_relu(fromRGB0(F.average_pooling_2d(x, 2, 2, 0)))
            h1 = b1(leaky_relu(fromRGB1(x)))
            h = (1.0 - alpha) * h0 + alpha * h1

        for i in range(int(stage // 2), 0, -1):
            h = getattr(self, "b%d" % i)(h)

        h = minibatch_std(h)
        h = leaky_relu(self.out0(h))
        h = leaky_relu(self.out1(h))
        return self.out2(h)
Esempio n. 2
0
 def __call__(self, x):
     #
     se = self.se(x)
     h = leaky_relu(self.c0(x))
     h = leaky_relu(self.c1(h))
     h = se * h
     h = F.average_pooling_2d(h, 2, 2, 0)
     return h
Esempio n. 3
0
 def __call__(self, x):
     h = F.unpooling_2d(x,
                        2,
                        2,
                        0,
                        outsize=(x.shape[2] * 2, x.shape[3] * 2))
     h = feature_vector_normalization(leaky_relu(self.c0(h)))
     h = feature_vector_normalization(leaky_relu(self.c1(h)))
     return h
Esempio n. 4
0
    def __call__(self, x):
        h, w = x.data.shape[2:]
        h = F.unpooling_2d(x, 2, 2, 0, outsize=(h * 2, w * 2))

        # se block
        se = self.se(h)

        h = feature_vector_normalization(leaky_relu(self.c0(h)))
        h = leaky_relu(self.c1(h))

        h = feature_vector_normalization(se * h)

        return h
Esempio n. 5
0
    def __call__(self, z, stage):
        # stage0: c0->c1->out0
        # stage1: c0->c1-> (1-a)*(up->out0) + (a)*(b1->out1)
        # stage2: c0->c1->b1->out1
        # stage3: c0->c1->b1-> (1-a)*(up->out1) + (a)*(b2->out2)
        # stage4: c0->c1->b2->out2
        # ...
        #print(np.prod(self.c0.c.b.data.shape))

        stage = min(stage, self.max_stage)
        alpha = stage - math.floor(stage)
        stage = math.floor(stage)

        h = F.reshape(z, (-1, self.n_hidden, 1, 1))
        h = feature_vector_normalization(leaky_relu(self.c0(h)))
        h = feature_vector_normalization(leaky_relu(self.c1(h)))

        for i in range(1, int(stage // 2 + 1)):
            h = getattr(self, "b%d" % i)(h)

        if int(stage) % 2 == 0:
            out = getattr(self, "out%d" % (stage // 2))
            x = out(feature_vector_normalization(h))
        else:
            out_prev = getattr(self, "out%d" % (stage // 2))
            out_curr = getattr(self, "out%d" % (stage // 2 + 1))
            b_curr = getattr(self, "b%d" % (stage // 2 + 1))

            x_0 = out_prev(
                F.unpooling_2d(h,
                               2,
                               2,
                               0,
                               outsize=(2 * h.shape[2], 2 * h.shape[3])))
            x_1 = out_curr(b_curr(h))
            x = (1.0 - alpha) * x_0 + alpha * x_1

        if chainer.configuration.config.train:
            return x
        else:
            scale = int(32 // x.data.shape[2])
            return F.unpooling_2d(x, scale, scale, 0, outsize=(32, 32))