예제 #1
0
class TestVAE(unittest.TestCase):
    def setUp(self) -> None:
        # self.model2 = VAE(3, 10)
        self.model = VanillaVAE(3, 10)

    def test_summary(self):
        print(summary(self.model, (3, 64, 64), device='cpu'))
        # print(summary(self.model2, (3, 64, 64), device='cpu'))

    def test_forward(self):
        x = torch.randn(16, 3, 64, 64)
        y = self.model(x)
        print("Model Output size:", y[0].size())
        # print("Model2 Output size:", self.model2(x)[0].size())

    def test_loss(self):
        x = torch.randn(16, 3, 64, 64)

        result = self.model(x)
        loss = self.model.loss_function(*result, M_N=0.005)
        print(loss)
예제 #2
0
파일: plot.py 프로젝트: n1ce3/foreveryoung
        plt.savefig('../plots/{}.png'.format(save_as),bbox_inches='tight', transparent="True", pad_inches=0)
    plt.show()



if __name__ == '__main__':

    # plotting with old VAE
    #images, rec_images = random_sample(5)
    #subplot(images, rec_images, save_as='testing_old')

    # plotting with Vanillia - delicious
    model_path = '../models/Vanilla_128_lr5e-4stable_cont_lr1-4-19.pth'
    data_dir = '../data/128x128CACD2000'

    model = VanillaVAE(layer_count=4, in_channels=3, latent_dim=100, size=128)

    #images, rec_images = random_sample(5, model, model_path=model_path, data_dir=data_dir)
    #subplot(images, rec_images, save_as='testing_vanillia_layer4_size64_stableLR_20epochs_final')

    # here interpolation is done
    interpolations1 = random_interpolate(5, model, model_path, subset=None, test_split=0.2)
    interpolations2 = random_interpolate(5, model, model_path, subset=None, test_split=0.2)

    # here interpolation between age is done
    file1 = 'm_Matt_Damon_0001.jpg'
    file2 = '42_Matt_Damon_0010.jpg'
    file3 = '15_Daniel_Radcliffe_0001.jpg'
    file4 = '24_Daniel_Radcliffe_0005.jpg'
    interpolations_age1 = age_interpolate(5, model, model_path, file1, file2)
    interpolations_age2 = age_interpolate(5, model, model_path, file3, file4)
예제 #3
0
 def setUp(self) -> None:
     # self.model2 = VAE(3, 10)
     self.model = VanillaVAE(3, 10)
예제 #4
0
파일: train.py 프로젝트: n1ce3/foreveryoung
    to_tensor = transforms.ToTensor()

    # define transformations
    trafo = transforms.Compose([PIL, to_tensor, normalize])

    # set up Model
    #model = standard_vae()

    if torch.cuda.is_available():
        device = 'cuda'
    else:
        device = 'cpu'

    model = VanillaVAE(layer_count=4,
                       in_channels=3,
                       latent_dim=100,
                       size=128,
                       name='Vanilla_128_lr5e-4stable_cont_lr1-4')
    model.to(device)

    summary(model, (3, 128, 128))

    model_path = '../models/Vanilla_128_lr5e-4stable-9.pth'

    train(model,
          epochs,
          batch,
          trafo,
          subset_size=None,
          test_split=0.2,
          lrs=lrs,
예제 #5
0
    args = parser.parse_args()

    # Housekeeping
    torch.manual_seed(0)
    device = torch.device("cuda" if args.device=="cuda" else "cpu")
    train_loader_kwargs = {'num_workers': 1, 'pin_memory': True} if args.device=="cuda" else {}

    # Initalise VAE model
    model_kwargs = {
        "input_size": args.input_size,
        "latent_size" : args.latent_size
    }

    if args.model_type == "vanilla":
        model = VanillaVAE(**model_kwargs)
    elif args.model_type == "conditional":
        model_kwargs.update({"n_classes": 10})
        model = ConditionalVAE(**model_kwargs)

    # Load MNIST dataset
    train_loader = torch.utils.data.DataLoader(
        datasets.MNIST('../data', train=True, download=True,
                    transform=transforms.ToTensor()),
        batch_size=args.batch_size, shuffle=True, **train_loader_kwargs
    )

    # Train model
    train_kwargs = {
        "learning_rate": args.learning_rate,
        "epochs" : args.epochs,
예제 #6
0
from datetime import datetime
from numpy.random import normal
import numpy as np
import torch
from models import VAE, VanillaVAE
from torchsummary import summary
from utils import standard_vae, newest, set_split
import glob
from PIL import Image
from models import VanillaEncoder

if torch.cuda.is_available():
    device = 'cuda'
else:
    device = 'cpu'

model = VanillaVAE(layer_count=4, in_channels=3, latent_dim=100, size=128, name='trying_shit')
model.to(device)

summary(model, (3, 128, 128))

file_names =

matt_damon_young = '34_Matt_Damon_0001.jpg'
matt_damon_old1 = '42_Matt_Damon_0010.jpg'
matt_damon_old2 = '42_Matt_Damon_0011.jpg'

daniel_radcliff_young = '15_Daniel_Radcliffe_0001.jpg'
daniel_radcliff_old1 = '24_Daniel_Radcliffe_0017.jpg'
daniel_radcliff_old2 = '24_Daniel_Radcliffe_0005.jpg'