本文整理汇总了Python中ipdb.set_trace方法的典型用法代码示例。如果您正苦于以下问题:Python ipdb.set_trace方法的具体用法?Python ipdb.set_trace怎么用?Python ipdb.set_trace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipdb
的用法示例。
在下文中一共展示了ipdb.set_trace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lidar_to_img
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def lidar_to_img(points, img_size):
# pdb.set_trace()
lidar_data = np.array(points[:, :2])
lidar_data *= 9.9999
lidar_data -= (0.5 * img_size, 0.5 * img_size)
lidar_data = np.fabs(lidar_data)
lidar_data = lidar_data.astype(np.int32)
lidar_data = np.reshape(lidar_data, (-1, 2))
lidar_img = np.zeros((img_size, img_size))
lidar_img[tuple(lidar_data.T)] = 255
return torch.tensor(lidar_img).cuda()
# def lidar_to_img(points, img_size):
# # pdb.set_trace()
# lidar_data = points[:, :2]
# lidar_data *= 9.9999
# lidar_data -= torch.tensor((0.5 * img_size, 0.5 * img_size)).cuda()
# lidar_data = torch.abs(lidar_data)
# lidar_data = torch.floor(lidar_data).long()
# lidar_data = lidar_data.view(-1, 2)
# lidar_img = torch.zeros((img_size, img_size)).cuda()
# lidar_img[lidar_data.permute(1,0)] = 255
# return lidar_img
示例2: lidar_to_heightmap
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def lidar_to_heightmap(points, img_size):
# pdb.set_trace()
lidar_data = np.array(points[:, :2])
height_data = np.array(points[:,2])
height_data *= 255/2
height_data[height_data < 0] = 0
height_data[height_data > 255] = 255
height_data = np.fabs(height_data)
height_data = height_data.astype(np.int32)
lidar_data *= 9.9999
lidar_data -= (0.5 * img_size, 0.5 * img_size)
lidar_data = np.fabs(lidar_data)
lidar_data = lidar_data.astype(np.int32)
lidar_data = np.reshape(lidar_data, (-1, 2))
lidar_img = np.zeros((img_size, img_size))
lidar_img[tuple(lidar_data.T)] = height_data # TODO: sort the point wrt height first lex sort
return lidar_img
示例3: forward
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def forward(self, input):
"""
input: (wrap(srcBatch), wrap(srcBioBatch), lengths), (wrap(tgtBatch), wrap(copySwitchBatch), wrap(copyTgtBatch))
"""
# ipdb.set_trace()
src = input[0]
tgt = input[1][0][:-1] # exclude last target from inputs
src_pad_mask = Variable(src[0].data.eq(s2s.Constants.PAD).transpose(0, 1).float(), requires_grad=False,
volatile=False)
enc_hidden, context = self.encoder(src)
init_att = self.make_init_att(context)
enc_hidden = self.decIniter(enc_hidden[1]).unsqueeze(0) # [1] is the last backward hiden
g_out, dec_hidden, _attn, _attention_vector = self.decoder(tgt, enc_hidden, context, src_pad_mask, init_att)
return g_out
示例4: forward
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def forward(self, input):
"""
(wrap(srcBatch), lengths), \
(wrap(bioBatch), lengths), ((wrap(x) for x in featBatches), lengths), \
(wrap(tgtBatch), wrap(copySwitchBatch), wrap(copyTgtBatch)), \
indices
"""
# ipdb.set_trace()
src = input[0]
tgt = input[3][0][:-1] # exclude last target from inputs
src_pad_mask = Variable(src[0].data.eq(s2s.Constants.PAD).transpose(0, 1).float(), requires_grad=False,
volatile=False)
bio = input[1]
feats = input[2]
enc_hidden, context = self.encoder(src, bio, feats)
init_att = self.make_init_att(context)
enc_hidden = self.decIniter(enc_hidden[1]).unsqueeze(0) # [1] is the last backward hiden
g_out, c_out, c_gate_out, dec_hidden, _attn, _attention_vector = self.decoder(tgt, enc_hidden, context,
src_pad_mask, init_att)
return g_out, c_out, c_gate_out
示例5: sample_kernel
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def sample_kernel():
ker_n = 16
ker_h = 3
ker_w = 3
ker_d = 8
ker_shape = [ker_n, ker_h, ker_w, ker_d]
filter_h = 3
filter_w = 3
test_seq = np.array(np.arange(ker_d * ker_h * ker_w), ndmin=2)
ones = np.array(np.ones(ker_n), ndmin=2).T
test_mat = ones * test_seq
# out = im2col(x, [ker_h, ker_w])
x = test_mat.astype(np.uint32)
qm = QuantizedMatrix(x, 2)
import ipdb
ipdb.set_trace()
return out
示例6: worker
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def worker():
global SHARE_Q
while True :
if not SHARE_Q.empty():
item = SHARE_Q.get()
# ipdb.set_trace()
do_something(item)
time.sleep(1)
SHARE_Q.task_done()
else:
break
#parser = argparse.ArgumentParser(description='copy selected images from source dir. to target dir.')
#parser.add_argument('--rm_dset', default=False, action='store_true',
# help='true to remove existing selected data before reproducing it')
#parser.add_argument('--auxiliary-dataset', type=str, default='imagenet',
# help='choose auxiliary dataset between imagenet/l_bird')
#args = parser.parse_args()
示例7: __init__
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def __init__(self, generator, tgt_vocab, label_smoothing=0.0):
super(NMTLossCompute, self).__init__(generator, tgt_vocab)
assert (label_smoothing >= 0.0 and label_smoothing <= 1.0)
self.tgt_vocab_len = len(tgt_vocab)
if label_smoothing > 0:
# When label smoothing is turned on,
# KL-divergence between q_{smoothed ground truth prob.}(w)
# and p_{prob. computed by model}(w) is minimized.
# If label smoothing value is set to zero, the loss
# is equivalent to NLLLoss or CrossEntropyLoss.
# All non-true labels are uniformly set to low-confidence.
self.criterion = nn.KLDivLoss(size_average=False)
one_hot = torch.randn(1, len(tgt_vocab))
one_hot.fill_(label_smoothing / (len(tgt_vocab) - 2))
one_hot[0][self.padding_idx] = 0
self.register_buffer('one_hot', one_hot)
else:
weight = torch.ones(len(tgt_vocab))
weight[self.padding_idx] = 0
self.criterion = nn.NLLLoss(weight, size_average=False) # IMPORTANT: NLLLoss is what we use. Interesting that size_average=False
# ipdb.set_trace()
self.confidence = 1.0 - label_smoothing
示例8: loss
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def loss(self, inf_targets, inf_vads, targets, vads, mtl_fac):
'''
Loss definition
Only speech inference loss is defined and work quite well
Add VAD cross entropy loss if you want
'''
loss_v1 = tf.nn.l2_loss(inf_targets - targets) / self.batch_size
loss_o = loss_v1
reg_loss = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
# ipdb.set_trace()
loss_v = loss_o + tf.add_n(reg_loss)
tf.scalar_summary('loss', loss_v)
# loss_merge = tf.cond(
# is_val, lambda: tf.scalar_summary('val_loss_batch', loss_v),
# lambda: tf.scalar_summary('loss', loss_v))
return loss_v, loss_o
# return tf.reduce_mean(tf.nn.l2_loss(inf_targets - targets))
示例9: transform
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def transform(audio_data, save_image_path, nFFT=256, overlap=0.75):
'''audio_data: signals to convert
save_image_path: path to store the image file'''
# spectrogram
freq_data = stft(audio_data, nFFT, overlap)
freq_data = np.maximum(np.abs(freq_data),
np.max(np.abs(freq_data)) / 10000)
log_freq_data = 20. * np.log10(freq_data / 1e-4)
N_samples = log_freq_data.shape[0]
# log_freq_data = np.maximum(log_freq_data, max_m - 70)
# print(np.max(np.max(log_freq_data)))
# print(np.min(np.min(log_freq_data)))
log_freq_data = np.round(log_freq_data)
log_freq_data = np.transpose(log_freq_data)
# ipdb.set_trace()
assert np.max(np.max(log_freq_data)) < 256, 'spectrogram value too large'
# save the image
spec_imag = Image.fromarray(log_freq_data)
spec_imag = spec_imag.convert('RGB')
spec_imag.save(save_image_path)
return N_samples
示例10: initialize
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def initialize(self, opt):
self.opt = opt
self.opt.imageSize = self.opt.imageSize if len(self.opt.imageSize) == 2 else self.opt.imageSize * 2
self.gpu_ids = ''
self.batchSize = self.opt.batchSize
self.checkpoints_path = os.path.join(self.opt.checkpoints, self.opt.name)
self.create_save_folders()
self.netG = self.load_network()
# st()
if 'vaihingen' not in self.opt.dataset_name:
self.data_loader, _ = CreateDataLoader(opt)
# visualizer
self.visualizer = Visualizer(self.opt)
if 'semantics' in self.opt.tasks:
from util.util import get_color_palette
self.opt.color_palette = np.array(get_color_palette(self.opt.dataset_name))
self.opt.color_palette = list(self.opt.color_palette.reshape(-1))
示例11: tensor2im
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def tensor2im(self, img, imtype=np.uint8, convert_value=255.0):
# ToDo: improve this horrible function
if img.shape[0] > 3: # case of focalstack
img = img[:, :3]
if(type(img) != np.ndarray):
image_numpy = img.cpu().float().numpy()
else:
image_numpy = img
if img.shape[0] == 3:
image_numpy = (image_numpy + 1) / 2.0 * convert_value
# image_numpy = (image_numpy + mean/std) * std * 255.0
image_numpy = image_numpy.astype(imtype) # .transpose([2,0,1])
else:
# st()
# image_numpy = image_numpy.astype(imtype)
image_numpy = (image_numpy - image_numpy.min()) * (255 / self.opt.max_distance)
# image_numpy = image_numpy - image_numpy.min()
# image_numpy = (image_numpy / image_numpy.max()) * 255
# image_numpy = (image_numpy / image_numpy.max()) * 255
image_numpy = np.repeat(image_numpy, 3, axis=0)
return image_numpy
# visuals: dictionary of images to display or save
示例12: visualize_tfrecords_test
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def visualize_tfrecords_test(fpaths):
for fname in fpaths:
print(fname)
for serialized_ex in tf.python_io.tf_record_iterator(fname):
results = read_from_example(serialized_ex)
images = results['images']
kps = results['kps']
for i, (image, kp) in enumerate(zip(images, kps)):
kp = kp.T
import matplotlib.pyplot as plt
plt.ion()
plt.clf()
plt.figure(1)
skel_img = draw_skeleton(image, kp[:2, :], vis=kp[2, :])
plt.imshow(skel_img)
plt.title('%d' % i)
plt.axis('off')
plt.pause(1e-5)
if i == 0:
ipdb.set_trace()
if i > config.max_sequence_length:
break
ipdb.set_trace()
示例13: forward
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def forward(self, inpt, lengths, hidden=None):
# use pack_padded
# inpt: [seq_len, batch], lengths: [batch_size]
embedded = self.embed(inpt) # [seq_len, batch, input_size]
if not hidden:
hidden = torch.randn(self.n_layer * 2, len(lengths),
self.hidden_size)
if torch.cuda.is_available():
hidden = hidden.cuda()
embedded = nn.utils.rnn.pack_padded_sequence(embedded, lengths, enforce_sorted=False)
_, hidden = self.gru(embedded, hidden)
hidden = hidden.sum(axis=0)
# [n_layer * bidirection, batch, hidden_size]
# hidden = hidden.reshape(hidden.shape[1], -1)
# ipdb.set_trace()
# hidden = hidden.permute(1, 0, 2) # [batch, n_layer * bidirectional, hidden_size]
# hidden = hidden.reshape(hidden.size(0), -1) # [batch, *]
# hidden = self.bn(hidden)
hidden = torch.tanh(hidden) # [batch, hidden]
return hidden
示例14: forward
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def forward(self, inpt, lengths, hidden=None):
# use pack_padded
# inpt: [seq_len, batch], lengths: [batch_size]
# embedded = self.embed(inpt) # [seq_len, batch, input_size]
if not hidden:
hidden = torch.randn(self.n_layer * 2, len(lengths),
self.hidden_size)
if torch.cuda.is_available():
hidden = hidden.cuda()
embedded = nn.utils.rnn.pack_padded_sequence(inpt, lengths,
enforce_sorted=False)
_, hidden = self.gru(embedded, hidden)
# [n_layer * bidirection, batch, hidden_size]
# hidden = hidden.reshape(hidden.shape[1], -1)
# ipdb.set_trace()
hidden = hidden.sum(axis=0) # [4, batch, hidden] -> [batch, hidden]
# hidden = hidden.permute(1, 0, 2) # [batch, n_layer * bidirectional, hidden_size]
# hidden = hidden.reshape(hidden.size(0), -1) # [batch, *]
# hidden = self.bn(hidden)
# hidden = self.hidden_proj(hidden)
hidden = torch.tanh(hidden) # [batch, hidden]
return hidden
示例15: __init__
# 需要导入模块: import ipdb [as 别名]
# 或者: from ipdb import set_trace [as 别名]
def __init__(self, config, sess=None):
self.config = config
self.load_path = config.load_path
if not config.load_path:
raise Exception(
"provide a pretrained model path"
)
if not exists(config.load_path + '.index'):
print('%s couldnt find..' % config.load_path)
import ipdb
ipdb.set_trace()
# Data
self.batch_size = config.batch_size
self.img_size = config.img_size
self.data_format = config.data_format
input_size = (self.batch_size, self.img_size, self.img_size, 3)
self.images_pl = tf.placeholder(tf.float32, shape=input_size, name='input_images')
if sess is None:
self.sess = tf.Session()
else:
self.sess = sess
# Load graph.
self.saver = tf.train.import_meta_graph(self.load_path+'.meta')
self.graph = tf.get_default_graph()
self.prepare()