コード例 #1
0
parser.add_argument(
    "--eval-d", default=config.EVAL, help="directory to output")
opt = parser.parse_args()
try:
    os.makedirs(opt.ckpt_d)
    os.makedirs(opt.eval_d)
except OSError:
    if not (os.path.exists(opt.ckpt_d) and os.path.exists(opt.eval_d)):
        raise OSError("Failed to make ckpt and eval directories")

browserwriter = SummaryWriter(config.TFLOGDIR)
cudnn.benchmark = True
en_cuda = opt.cuda and torch.cuda.is_available()
dataloader = thindidata.get_dataloader(
    thindidata.ThindiCifar10Data,
    opt.root,
    "train",
    opt.batch_size,
    num_workers=8)

device = torch.device("cuda" if en_cuda else "cpu")
if opt.ngpu == 1 and int(torch.cuda.device_count()) > 1:
    torch.cuda.set_device(1)

ngpu = opt.ngpu
netSD = SketchDiscriminator(ngpu).to(device)
netPD = PhotoDiscriminator(ngpu).to(device)
netSG = SKetchGenerator(ngpu).to(device)
netPG = PhotoGenerator(ngpu).to(device)
netSD.apply(utils.weight_init)
netSG.apply(utils.weight_init)
netPD.apply(utils.weight_init)
コード例 #2
0
ファイル: dcgan.py プロジェクト: chillingche/thindi-gan
parser.add_argument("--ckpt-d",
                    default=config.CKPT,
                    help="directory to checkpoint")
parser.add_argument("--eval-d",
                    default=config.EVAL,
                    help="directory to output")
opt = parser.parse_args()
try:
    os.makedirs(opt.ckpt_d)
    os.makedirs(opt.eval_d)
except OSError:
    pass

cudnn.benchmark = True
en_cuda = opt.cuda and torch.cuda.is_available()
dataloader = thindidata.get_dataloader(thindidata.Cifar10Data, opt.root, "all",
                                       opt.batch_size)
device = torch.device("cuda" if en_cuda else "cpu")
ngpu = opt.ngpu
netD = arch.Discriminator(ngpu).to(device)
netG = arch.Generator(ngpu).to(device)
netD.apply(utils.weight_init)
netG.apply(utils.weight_init)
if opt.netG != "":
    netG.load_state_dict(torch.load(opt.netG))
if opt.netD != "":
    netD.load_state_dict(torch.load(opt.netD))
criterion = nn.MSELoss()
fixed_noise = torch.randn(opt.batch_size, opt.nz, 1, 1, device=device)
real_label = 1
fake_label = 0