Exemple #1
0
    def make_img(self, x, l, num_lm, random=0):
        if random == 0:
            lm = Variable(xp.clip(l.data, 0, 1))
        else:
            eps = xp.random.normal(0, 1, size=l.data.shape).astype(xp.float32)
            lm = xp.clip(l.data + eps * xp.sqrt(self.vars), 0, 1)

            lm = Variable(lm.astype(xp.float32))
        if self.use_gpu:
            xm = make_sampled_image.generate_xm_const_size_gpu(
                lm.data,
                self.gsize,
                x.data,
                num_lm,
                g_size=self.gsize,
                img_size=self.img_size)
        else:
            xm = make_sampled_image.generate_xm_const_size(
                lm.data,
                self.gsize,
                x.data,
                num_lm,
                g_size=self.gsize,
                img_size=self.img_size)

        return xm, lm
Exemple #2
0
 def make_img(self, x, l, s, num_lm, random=0):
     if random == 0:
         lm = Variable(xp.clip(l.data, 0, 1))
         sm = Variable(xp.clip(s.data, 0, 1))
     else:
         eps = xp.random.normal(0, 1, size=l.data.shape).astype(xp.float32)
         epss = xp.random.normal(0, 1, size=s.data.shape).astype(xp.float32)
         sm = xp.clip((s.data + xp.sqrt(self.var) * epss), 0,
                      1).astype(xp.float32)
         lm = xp.clip(l.data + eps * xp.sqrt(self.vars), 0, 1)
         sm = Variable(sm)
         lm = Variable(lm.astype(xp.float32))
     if self.use_gpu:
         xm = make_sampled_image.generate_xm_rgb_gpu(lm.data,
                                                     sm.data,
                                                     x,
                                                     num_lm,
                                                     g_size=self.gsize)
     else:
         xm = make_sampled_image.generate_xm_rgb(lm.data,
                                                 sm.data,
                                                 x,
                                                 num_lm,
                                                 g_size=self.gsize)
     return xm, lm, sm
Exemple #3
0
    def make_img(self, x, l, num_lm, random=0):
        s = xp.log10(xp.ones((1, 1)) * self.gsize / self.img_size) + 1
        sm = xp.repeat(s, num_lm, axis=0)

        if random == 0:
            lm = Variable(xp.clip(l.data, 0, 1))
        else:
            eps = xp.random.normal(0, 1, size=l.data.shape).astype(xp.float32)
            lm = xp.clip(l.data + eps * xp.sqrt(self.vars), 0, 1)
            lm = Variable(lm.astype(xp.float32))
        if self.use_gpu:
            xm = make_sampled_image.generate_xm_rgb_gpu(lm.data, sm, x, num_lm, g_size=self.gsize)
        else:
            xm = make_sampled_image.generate_xm_rgb(lm.data, sm, x, num_lm, g_size=self.gsize)
        return xm, lm
Exemple #4
0
def generate_xm_in_gpu(lm, sm, img, num_lm, g_size, img_size=112):
    xm = xp.empty((num_lm, g_size * g_size)).astype(xp.float32)
    img_buf = img.reshape((num_lm, img_size * img_size))
    zm = xp.power(10, sm - 1)
    for k in range(num_lm):
        xr = xp.linspace((lm[k][0] - zm[k] / 2), (lm[k][0] + zm[k] / 2),
                         g_size)
        xr *= img_size
        xr = xp.clip(xr, 0, img_size - 1).astype(np.int32)
        yr = xp.linspace((lm[k][1] - zm[k] / 2), (lm[k][1] + zm[k] / 2),
                         g_size)
        yr *= img_size
        yr = xp.clip(yr, 0, img_size - 1).astype(np.int32)
        xr = img_size * np.repeat(xr, g_size) + xp.tile(yr, g_size)
        xm[k] = img_buf[k][xr]
    return xm.reshape(num_lm, 1, g_size, g_size).astype(xp.float32)