예제 #1
0
def main():
    opt = parse_args()
    print(opt)
    # if manual seed is not provide then pick one randomly
    if opt.manualSeed is None:
        opt.manualSeed  = random.randint(1, 10000)
    print('Random Seed: ', opt.manualSeed)
    random.seed(opt.manualSeed)
    torch.manual_seed(opt.manualSeed)

    # check wether cuda is available
    if torch.cuda.is_available() and not opt.cuda:
        print("WARNING: You have a CUDA device, so you should probably run with --cuda")
    if opt.cuda:
        torch.cuda.manual_seed_all(opt.manualSeed)
    cudnn.enabled = True
    cudnn.benchmark = False 

    # prepare the output directories
    try:
        os.makedirs(opt.outf)
        os.makedirs(os.path.join(opt.outf, 'figures'))
    except OSError:
        pass

    # prepare the data loader
    x_files_list_file = opt.xFilesList
    y_files_list_file = opt.yFilesList
    in_dim = opt.mgcDim
    out_dim = opt.mgcDim

    with open(x_files_list_file, 'r') as fid:
        x_files_list = [l.strip() for l in fid.readlines()]

    with open(y_files_list_file, 'r') as fid:
        y_files_list = [l.strip() for l in fid.readlines()]
    
    data_loader = get_loader(x_files_list, y_files_list, 
                            in_dim, out_dim, opt.batchSize, False, 0)
    
    # get the device
    device = torch.device("cuda:0" if opt.cuda else "cpu")
    # define the generator 
    netG = define_netG(in_ch=2,device=device)
    if opt.netG != '':
        netG.load_state_dict(torch.load(opt.netG))
    print(netG)

    # define the discriminator
    netD = define_netD(device=device)
    if opt.netD != '':
        netD.load_state_dict(torch.load(opt.netD))
    print(netD)

    if opt.mode == 'train':
        train(netD, netG, data_loader, opt)
    elif opt.mode == 'test':
        test(netG, opt)
    else:
        print('Mode must be either train or test only')
예제 #2
0
        opt.manualSeed = random.randint(1, 10000)
    print('Random Seed: ', opt.manualSeed)
    random.seed(opt.manualSeed)
    torch.manual_seed(opt.manualSeed)

    if torch.cuda.is_available() and not opt.cuda:
        print(
            "WARNING: You have a CUDA device, so you should probably run with --cuda"
        )
    if opt.cuda:
        torch.cuda.manual_seed_all(opt.manualSeed)
    cudnn.enabled = True
    cudnn.benchmark = True

    # define the generator
    netG = define_netG(in_ch=2)
    if opt.netG != '':
        netG.load_state_dict(torch.load(opt.netG))
    print(netG)

    # define the discriminator
    netD = define_netD()
    if opt.netD != '':
        netD.load_state_dict(torch.load(opt.netD))
    print(netD)

    if opt.mode == 'train':
        train(netD, netG, data_loader, opt)
    elif opt.mode == 'test':
        test(netG, opt)
    else:
예제 #3
0
from pathlib import Path
import random

from models import define_netG
from utils import read_binary_file

import torch
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
import numpy as np
from sklearn.preprocessing import StandardScaler
from pysptk.sptk import mgc2sp

device = torch.device("cpu")
netG = define_netG(in_ch=2, device=device)
netG.load_state_dict(torch.load('netG_epoch_22.pth'))

nat_dir_path = Path('/Users/dintu/zalo_ai/postfilt_gan/mgc')
syn_dir_path = Path('/Users/dintu/zalo_ai/postfilt_gan/mgc_gen')


def prepare_normalizer(list_paths, dim):
    dataset = []
    for file_path in list_paths:
        try:
            data, _ = read_binary_file(file_path, dim)
            dataset.append(data)
        except FileNotFoundError:
            print(FileNotFoundError)
    dataset = np.concatenate(dataset)
예제 #4
0
    # if manual seed is not provide then pick one randomly
    if opt.manualSeed is None:
        opt.manualSeed  = random.randint(1, 10000)
    print('Random Seed: ', opt.manualSeed)
    random.seed(opt.manualSeed)
    torch.manual_seed(opt.manualSeed)

    if torch.cuda.is_available() and not opt.cuda:
        print("WARNING: You have a CUDA device, so you should probably run with --cuda")
    if opt.cuda:
        torch.cuda.manual_seed_all(opt.manualSeed)
    cudnn.enabled = False
    cudnn.benchmark = False

    # define the generator 
    netG_AB = define_netG(in_ch=2, device=device)
    if opt.netG != '':
        netG_AB.load_state_dict(torch.load(opt.netG))
    print(netG_AB)

    netG_BA = define_netG(in_ch=2, device=device)

    # define the discriminator
    netD_A = define_netD(device=device)
    if opt.netD != '':
        netD_A.load_state_dict(torch.load(opt.netD))
    print(netD_A)

    netD_B = define_netD(device=device)

    if opt.mode == 'train':
예제 #5
0
파일: main.py 프로젝트: tressetp/GlottGAN
    # if manual seed is not provide then pick one randomly
    if opt.manualSeed is None:
        opt.manualSeed  = random.randint(1, 10000)
    print('Random Seed: ', opt.manualSeed)
    random.seed(opt.manualSeed)
    torch.manual_seed(opt.manualSeed)
    if opt.cuda:
        torch.cuda.manual_seed_all(opt.manualSeed)

    cudnn.benchmark = True

    if torch.cuda.is_available() and not opt.cuda:
        print("WARNING: You have a CUDA device, so you should probably run with --cuda")
    nz = int(opt.nz)
    # define the generator 
    netG = define_netG(opt.nz, opt.acSize)
    if opt.netG != '':
        netG.load_state_dict(torch.load(opt.netG))
    print(netG)

    # define the discriminator
    netD = define_netD(opt.acSize)
    if opt.netD != '':
        netD.load_state_dict(torch.load(opt.netD))
    print(netD)

    if opt.mode == 'train':
        train(netD, netG, opt)
    elif opt.mode == 'test':
        test(netG, opt)
    else: