本文整理汇总了Python中miscc.config.cfg.CUDA属性的典型用法代码示例。如果您正苦于以下问题:Python cfg.CUDA属性的具体用法?Python cfg.CUDA怎么用?Python cfg.CUDA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类miscc.config.cfg
的用法示例。
在下文中一共展示了cfg.CUDA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_network_stageI
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def load_network_stageI(self):
from model import STAGE1_G, STAGE1_D
netG = STAGE1_G()
netG.apply(weights_init)
netD = STAGE1_D()
netD.apply(weights_init)
if cfg.NET_G != '':
state_dict = \
torch.load(cfg.NET_G, map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict["netG"])
print('Load from: ', cfg.NET_G)
if cfg.NET_D != '':
state_dict = \
torch.load(cfg.NET_D, map_location=lambda storage, loc: storage)
netD.load_state_dict(state_dict)
print('Load from: ', cfg.NET_D)
if cfg.CUDA:
netG.cuda()
netD.cuda()
return netG, netD
示例2: load_network_stageI
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def load_network_stageI(self):
from model import STAGE1_G, STAGE1_D
netG = STAGE1_G()
netG.apply(weights_init)
print(netG)
netD = STAGE1_D()
netD.apply(weights_init)
print(netD)
if cfg.NET_G != '':
state_dict = \
torch.load(cfg.NET_G, map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict["netG"])
print('Load from: ', cfg.NET_G)
if cfg.NET_D != '':
state_dict = \
torch.load(cfg.NET_D, map_location=lambda storage, loc: storage)
netD.load_state_dict(state_dict)
print('Load from: ', cfg.NET_D)
if cfg.CUDA:
netG.cuda()
netD.cuda()
return netG, netD
示例3: load_network_stageI
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def load_network_stageI(self):
from model import STAGE1_G, STAGE1_D
netG = STAGE1_G()
netG.apply(weights_init)
print(netG)
netD = STAGE1_D()
netD.apply(weights_init)
print(netD)
if cfg.NET_G != '':
state_dict = \
torch.load(cfg.NET_G, map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict["netG"])
print('Load from: ', cfg.NET_G)
if cfg.NET_D != '':
state_dict = \
torch.load(cfg.NET_D, map_location=lambda storage, loc: storage)
netD.load_state_dict(state_dict)
print('Load from: ', cfg.NET_D)
if cfg.CUDA:
netG.cuda()
netD.cuda()
return netG, netD
# ############# For training stageII GAN #############
示例4: prepare_labels
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def prepare_labels(self):
if cfg.TRAIN.OPTIMIZE_DATA_LOADING:
batch_sizes = self.batch_size
real_labels, fake_labels, match_labels = [], [], []
for batch_size in batch_sizes:
real_labels.append(Variable(torch.FloatTensor(batch_size).fill_(1)))
fake_labels.append(Variable(torch.FloatTensor(batch_size).fill_(0)))
match_labels.append(Variable(torch.LongTensor(range(batch_size))))
if cfg.CUDA:
for idx in range(len(batch_sizes)):
real_labels[idx] = real_labels[idx].cuda().detach()
fake_labels[idx] = fake_labels[idx].cuda().detach()
match_labels[idx] = match_labels[idx].cuda().detach()
else:
batch_size = self.batch_size[0]
real_labels = Variable(torch.FloatTensor(batch_size).fill_(1))
fake_labels = Variable(torch.FloatTensor(batch_size).fill_(0))
match_labels = Variable(torch.LongTensor(range(batch_size)))
if cfg.CUDA:
real_labels = real_labels.cuda().detach()
fake_labels = fake_labels.cuda().detach()
match_labels = match_labels.cuda().detach()
return real_labels, fake_labels, match_labels
开发者ID:tohinz,项目名称:semantic-object-accuracy-for-generative-text-to-image-synthesis,代码行数:26,代码来源:trainer.py
示例5: prepare_data
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def prepare_data(self, data):
fimgs, cimgs, c_code, _, warped_bbox = data
real_vfimgs, real_vcimgs = [], []
if cfg.CUDA:
vc_code = Variable(c_code).cuda()
for i in range(len(warped_bbox)):
warped_bbox[i] = Variable(warped_bbox[i]).float().cuda()
else:
vc_code = Variable(c_code)
for i in range(len(warped_bbox)):
warped_bbox[i] = Variable(warped_bbox[i])
if cfg.CUDA:
real_vfimgs.append(Variable(fimgs[0]).cuda())
real_vcimgs.append(Variable(cimgs[0]).cuda())
else:
real_vfimgs.append(Variable(fimgs[0]))
real_vcimgs.append(Variable(cimgs[0]))
return fimgs, real_vfimgs, real_vcimgs, vc_code, warped_bbox
示例6: prepare_data
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def prepare_data(self, data):
imgs, w_imgs, t_embedding, _ = data
real_vimgs, wrong_vimgs = [], []
if cfg.CUDA:
vembedding = Variable(t_embedding).cuda()
else:
vembedding = Variable(t_embedding)
for i in range(self.num_Ds):
if cfg.CUDA:
real_vimgs.append(Variable(imgs[i]).cuda())
wrong_vimgs.append(Variable(w_imgs[i]).cuda())
else:
real_vimgs.append(Variable(imgs[i]))
wrong_vimgs.append(Variable(w_imgs[i]))
return imgs, real_vimgs, wrong_vimgs, vembedding
示例7: prepare_data
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def prepare_data(self, data):
imgs, w_imgs, t_embedding, rec_id, im_id, _ = data
real_vimgs, wrong_vimgs = [], []
if cfg.CUDA:
vembedding = Variable(t_embedding).cuda()
else:
vembedding = Variable(t_embedding)
for i in range(self.num_Ds):
if cfg.CUDA:
real_vimgs.append(Variable(imgs[i]).cuda())
wrong_vimgs.append(Variable(w_imgs[i]).cuda())
else:
real_vimgs.append(Variable(imgs[i]))
wrong_vimgs.append(Variable(w_imgs[i]))
return imgs, real_vimgs, wrong_vimgs, vembedding, rec_id, im_id
示例8: reparametrize
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def reparametrize(self, mu, logvar):
std = logvar.mul(0.5).exp_()
# licht - printing many things
#print "cfg.CUDA - ", cfg.CUDA
if cfg.CUDA:
eps = torch.cuda.FloatTensor(std.size()).normal_()
else:
eps = torch.FloatTensor(std.size()).normal_()
# licht - moving the normal_() cmd to here
#eps.normal_()
#print "eps type @Before@ Variable(eps)", type(eps)
eps = Variable(eps)
#print "eps type @After@ Variable(eps)", type(eps)
# licht - printing type for mu and std
#print "std type = ", std.data.type()
#print "mu type = ", mu.data.type()
return eps.mul(std).add_(mu)
示例9: define_module
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def define_module(self):
if cfg.GAN.B_CONDITION:
#device = torch.device("cuda:0" if cfg.CUDA else "cpu")
self.ca_net = CA_NET()#.to(device)
if cfg.TREE.BRANCH_NUM > 0:
self.h_net1 = INIT_STAGE_G(self.gf_dim * 16)
self.img_net1 = GET_IMAGE_G(self.gf_dim)
if cfg.TREE.BRANCH_NUM > 1:
self.h_net2 = NEXT_STAGE_G(self.gf_dim)
self.img_net2 = GET_IMAGE_G(self.gf_dim // 2)
if cfg.TREE.BRANCH_NUM > 2:
self.h_net3 = NEXT_STAGE_G(self.gf_dim // 2)
self.img_net3 = GET_IMAGE_G(self.gf_dim // 4)
if cfg.TREE.BRANCH_NUM > 3: # Recommended structure (mainly limited by GPU memory), and not test yet
self.h_net4 = NEXT_STAGE_G(self.gf_dim // 4, num_residual=1)
self.img_net4 = GET_IMAGE_G(self.gf_dim // 8)
if cfg.TREE.BRANCH_NUM > 4:
self.h_net4 = NEXT_STAGE_G(self.gf_dim // 8, num_residual=1)
self.img_net4 = GET_IMAGE_G(self.gf_dim // 16)
示例10: models
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def models(word_len):
#print(word_len)
text_encoder = cache.get('text_encoder')
if text_encoder is None:
#print("text_encoder not cached")
text_encoder = RNN_ENCODER(word_len, nhidden=cfg.TEXT.EMBEDDING_DIM)
state_dict = torch.load(cfg.TRAIN.NET_E, map_location=lambda storage, loc: storage)
text_encoder.load_state_dict(state_dict)
if cfg.CUDA:
text_encoder.cuda()
text_encoder.eval()
cache.set('text_encoder', text_encoder, timeout=60 * 60 * 24)
netG = cache.get('netG')
if netG is None:
#print("netG not cached")
netG = G_NET()
state_dict = torch.load(cfg.TRAIN.NET_G, map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict)
if cfg.CUDA:
netG.cuda()
netG.eval()
cache.set('netG', netG, timeout=60 * 60 * 24)
return text_encoder, netG
示例11: load_network_stageI
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def load_network_stageI(self):
from model import STAGE1_G, STAGE1_D
netG = STAGE1_G()
netG.apply(weights_init)
print(netG)
netD = STAGE1_D()
netD.apply(weights_init)
print(netD)
if cfg.NET_G != '':
state_dict = \
torch.load(cfg.NET_G,
map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict)
print('Load from: ', cfg.NET_G)
if cfg.NET_D != '':
state_dict = \
torch.load(cfg.NET_D,
map_location=lambda storage, loc: storage)
netD.load_state_dict(state_dict)
print('Load from: ', cfg.NET_D)
if cfg.CUDA:
netG.cuda()
netD.cuda()
return netG, netD
# ############# For training stageII GAN #############
示例12: load_network_stageII
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def load_network_stageII(self):
from model import STAGE1_G, STAGE2_G, STAGE2_D
Stage1_G = STAGE1_G()
netG = STAGE2_G(Stage1_G)
netG.apply(weights_init)
print(netG)
if cfg.NET_G != '':
state_dict = \
torch.load(cfg.NET_G,
map_location=lambda storage, loc: storage)
netG.load_state_dict(state_dict)
print('Load from: ', cfg.NET_G)
elif cfg.STAGE1_G != '':
state_dict = \
torch.load(cfg.STAGE1_G,
map_location=lambda storage, loc: storage)
netG.STAGE1_G.load_state_dict(state_dict)
print('Load from: ', cfg.STAGE1_G)
else:
print("Please give the Stage1_G path")
return
netD = STAGE2_D()
netD.apply(weights_init)
if cfg.NET_D != '':
state_dict = \
torch.load(cfg.NET_D,
map_location=lambda storage, loc: storage)
netD.load_state_dict(state_dict)
print('Load from: ', cfg.NET_D)
print(netD)
if cfg.CUDA:
netG.cuda()
netD.cuda()
return netG, netD
示例13: reparametrize
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def reparametrize(self, mu, logvar):
std = logvar.mul(0.5).exp_()
if cfg.CUDA:
eps = torch.cuda.FloatTensor(std.size()).normal_()
else:
eps = torch.FloatTensor(std.size()).normal_()
eps = Variable(eps)
return eps.mul(std).add_(mu)
示例14: prepare_labels
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def prepare_labels(self):
batch_size = self.batch_size
real_labels = Variable(torch.FloatTensor(batch_size).fill_(1))
fake_labels = Variable(torch.FloatTensor(batch_size).fill_(0))
match_labels = Variable(torch.LongTensor(range(batch_size)))
if cfg.CUDA:
real_labels = real_labels.cuda()
fake_labels = fake_labels.cuda()
match_labels = match_labels.cuda()
return real_labels, fake_labels, match_labels
示例15: sent_loss
# 需要导入模块: from miscc.config import cfg [as 别名]
# 或者: from miscc.config.cfg import CUDA [as 别名]
def sent_loss(cnn_code, rnn_code, labels, class_ids,
batch_size, eps=1e-8):
# ### Mask mis-match samples ###
# that come from the same class as the real sample ###
masks = []
if class_ids is not None:
for i in range(batch_size):
mask = (class_ids == class_ids[i]).astype(np.uint8)
mask[i] = 0
masks.append(mask.reshape((1, -1)))
masks = np.concatenate(masks, 0)
# masks: batch_size x batch_size
masks = torch.ByteTensor(masks)
if cfg.CUDA:
masks = masks.cuda()
# --> seq_len x batch_size x nef
if cnn_code.dim() == 2:
cnn_code = cnn_code.unsqueeze(0)
rnn_code = rnn_code.unsqueeze(0)
# cnn_code_norm / rnn_code_norm: seq_len x batch_size x 1
cnn_code_norm = torch.norm(cnn_code, 2, dim=2, keepdim=True)
rnn_code_norm = torch.norm(rnn_code, 2, dim=2, keepdim=True)
# scores* / norm*: seq_len x batch_size x batch_size
scores0 = torch.bmm(cnn_code, rnn_code.transpose(1, 2))
norm0 = torch.bmm(cnn_code_norm, rnn_code_norm.transpose(1, 2))
scores0 = scores0 / norm0.clamp(min=eps) * cfg.TRAIN.SMOOTH.GAMMA3
# --> batch_size x batch_size
scores0 = scores0.squeeze()
if class_ids is not None:
scores0.data.masked_fill_(masks, -float('inf'))
scores1 = scores0.transpose(0, 1)
if labels is not None:
loss0 = nn.CrossEntropyLoss()(scores0, labels)
loss1 = nn.CrossEntropyLoss()(scores1, labels)
else:
loss0, loss1 = None, None
return loss0, loss1