本文整理匯總了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