コード例 #1
0
def test_glow():
    print("[Test]: Glow")
    from glow.config import JsonConfig
    glow = models.Glow(JsonConfig("hparams/celeba_test.json"))
    # img = cv2.imread("pictures/tsuki.jpeg")
    # img = cv2.resize(img, (32, 32))
    # img = (img / 255.0).astype(np.float32)
    # img = img[:, :, ::-1].transpose(2, 0, 1)
    # x = torch.Tensor([img]*8)

    x = torch.Tensor(np.random.rand(8, 1, 32, 32))
    print('x.size = ', x.size())

    batch_size = 8
    nb_digits = 10
    y = torch.LongTensor(batch_size).random_() % nb_digits
    print('y = ', y)
    print('y.view(-1,1) = ', y.view(-1, 1))
    y_onehot = torch.FloatTensor(batch_size, nb_digits)
    y_onehot.zero_()
    y_onehot.scatter_(1, y.view(-1, 1), 1)
    print('y_onehot:', y_onehot)

    z, det, y_logits = glow(x=x, y_onehot=y_onehot)
    print(z.size())
    print(det)

    print(models.Glow.loss_generative(det))
    print('y_logits =  ', y_logits)
    print(models.Glow.loss_class(y_logits, y))
コード例 #2
0
    def __init__(self, test_class_index, is_mean, K, class_number):
        super(AssociateGlowGenerated, self).__init__()
        self.glow = models.Glow(JsonConfig("hparams/omni_all_bg.json"),
                                test_class_index=test_class_index,
                                is_mean=is_mean,
                                K=K,
                                y_classes=class_number)
        self.class_number = class_number
        self.eval_index = test_class_index
        self.criterion = nn.MSELoss()
        self.ones_tensor = torch.ones((1, 32, 32)).float().cuda()

        self.glow_generate = models.Glow(
            JsonConfig("hparams/omni_all_bg.json"),
            test_class_index=test_class_index,
            is_mean=is_mean,
            K=K,
            y_classes=class_number)
コード例 #3
0
def test_glow():
    print("[Test]: Glow")
    from glow.config import JsonConfig
    glow = models.Glow(JsonConfig("hparams_celeba.json"))
    img = cv2.imread("tsuki.jpeg")
    img = cv2.resize(img, (64, 64))
    img = (img / 255.0).astype(np.float32)
    img = img[:, :, ::-1].transpose(2, 0, 1)
    x = torch.Tensor([img] * 8)
    y_onehot = torch.zeros((8, 40))
    z, det, y_logits = glow(x=x, y_onehot=y_onehot)
    print(z.size())
    print(det)
    print(models.Glow.loss_generative(det))
コード例 #4
0
def test_glow():
    print("[Test]: Glow")
    from glow.config import JsonConfig
    glow = models.Glow(JsonConfig("hparams/celeba_test.json"),
                       is_mean=True,
                       test_class_index=[1, 2],
                       K=4,
                       y_classes=10,
                       arc_loss=True)
    # img = cv2.imread("pictures/tsuki.jpeg")
    # img = cv2.resize(img, (32, 32))
    # img = (img / 255.0).astype(np.float32)
    # img = img[:, :, ::-1].transpose(2, 0, 1)
    # x = torch.Tensor([img]*8)
    # glow.set_z_add_random()
    glow.cuda()

    x = torch.Tensor(np.random.rand(12, 1, 32, 32))
    print('x.size = ', x.size())

    batch_size = 12
    nb_digits = 10
    y = torch.LongTensor(batch_size).random_() % nb_digits
    print('y = ', y)
    print('y.view(-1,1) = ', y.view(-1, 1))
    y_onehot = torch.FloatTensor(batch_size, nb_digits)
    y_onehot.zero_()
    y_onehot.scatter_(1, y.view(-1, 1), 1)
    print('y_onehot:', y_onehot)

    z, det, y_logits = glow(x=x, y_onehot=y_onehot)
    y_logits = glow.class_flow(z, y_onehot)
    print('z.size() =  ', z.size())
    print('det = ', det)
    print('y_logits = ', y_logits)

    print(models.Glow.loss_generative(det))
    # print('y_logits =  ',y_logits)
    print(models.Glow.loss_class(y_logits, y))