def getBatch_(self, indices):
# format NxCHxWxH
batchRGB = np.zeros((len(indices), self.CH, self.W, self.H), dtype='float32')
batchLabel = np.zeros((len(indices), self.W, self.H), dtype='int32')
k = 0
for i in indices:
(rgbname, gtname) = self.flist[i]
# format: HxWxCH
rgb = misc.imread(rgbname)
if(gtname.endswith('.png')):
gt = misc.imread(gtname)
else:
gt = np.loadtxt(gtname)
gt = gt.astype('uint8')
if(self.data_transformer is not None):
rgb = self.data_transformer.transformData(rgb)
gt = self.data_transformer.transformLabel(gt)
#^ data_transformer outputs in format HxWxCH
# convertion from HxWxCH to CHxWxH
batchRGB[k,:,:,:] = rgb.astype(np.float32).transpose((2,1,0))
batchLabel[k,:,:] = gt.astype(np.int32).transpose((1,0))
k += 1
#ipdb.set_trace()
if(self.weights_classes_flag):
return (batchRGB, batchLabel, self.weights_classes)
else:
return (batchRGB, batchLabel)
python类set_trace()的实例源码
def saveInfo(self, model, optimizer, smanager, epoch, outputFolder, saveEach):
#ipdb.set_trace()
if(epoch % saveEach == 0):
if(not os.path.exists(outputFolder)):
os.makedirs(outputFolder)
bname = outputFolder + '/' + model.getName() + '_' + str(epoch)
serializers.save_npz(bname + '.model', model)
serializers.save_npz(bname + '.state', optimizer)
smanager.save(bname + '.stats')
def __call__(self, input_blob, test_mode=False):
# explicit and very flexible DAG!
#################################
data = input_blob[0]
labels = input_blob[1]
if(len(input_blob) >= 3):
weights_classes = input_blob[2]
else:
weights_classes = chainer.Variable(cuda.cupy.ones((self.classes, 1), dtype='float32'))
# ---- CONTRACTION BLOCKS ---- #
blob_b0 = self.bnorm0(data)
(blob_b1, indices_b1, size_b1) = F.max_pooling_2dIndices(self.bnorm1(F.relu(self.conv1(blob_b0)), test=test_mode), (2, 2), stride=(2,2), pad=(0, 0))
(blob_b2, indices_b2, size_b2) = F.max_pooling_2dIndices(self.bnorm2(F.relu(self.conv2(blob_b1)), test=test_mode), (2, 2), stride=(2,2), pad=(0, 0))
(blob_b3, indices_b3, size_b3) = F.max_pooling_2dIndices(self.bnorm3(F.relu(self.conv3(blob_b2)), test=test_mode), (2, 2), stride=(2,2), pad=(0, 0))
(blob_b4, indices_b4, size_b4) = F.max_pooling_2dIndices(self.bnorm4(F.relu(self.conv4(blob_b3)), test=test_mode), (2, 2), stride=(2,2), pad=(0, 0))
# ---- EXPANSION BLOCKS ---- #
blob_b5 = self.bnorm5(F.relu(self.conv5(F.unpooling_2d(blob_b4, indices_b4, size_b4))), test=test_mode)
blob_b6 = self.bnorm6(F.relu(self.conv6(F.unpooling_2d(blob_b5, indices_b3, size_b3))), test=test_mode)
blob_b7 = self.bnorm7(F.relu(self.conv7(F.unpooling_2d(blob_b6, indices_b2, size_b2))), test=test_mode)
blob_b8 = self.bnorm8(F.relu(self.conv8(F.unpooling_2d(blob_b7, indices_b1, size_b1))), test=test_mode)
#ipdb.set_trace()
# ---- SOFTMAX CLASSIFIER ---- #
self.blob_class = self.classi(blob_b8)
self.probs = F.softmax(self.blob_class)
# ---- CROSS-ENTROPY LOSS ---- #
#ipdb.set_trace()
self.loss = F.weighted_cross_entropy(self.probs, labels, weights_classes, normalize=True)
self.output_point = self.probs
return self.loss
def get_rescaled_value_from_model(model, data):
try:
predicted_value = get_data_from_model(model, data)
except:
ipdb.set_trace();
return (predicted_value - data.mean())/data.std()
def __init__(self, assets, look_back, episode_length, look_back_reinforcement, price_series, train):
# think about it whether its needed or not
self.action_repeat = 2
self.gym_actions = range(len(assets) + 1)
self.look_back = look_back
total_data = pd.read_csv("../data/all_data.csv")
cut_index = int(total_data.shape[0] * 0.8)
if train:
data = total_data[0:cut_index]
else:
data = total_data[cut_index:-1]
self.look_back = look_back
self.assets_index = range(0, (len(self.gym_actions)) * 4, 4)[1:]
self.look_ahead = 1
self.batch_size = 50
self.look_back_reinforcement = look_back_reinforcement
self.total_data = pandas_split_series_into_list(data, self.look_back + episode_length + 1)
# ipdb.set_trace();
# self.numpy_data = self.data.as_matrix()
self.price_series = price_series
self.episode_length = episode_length
self.models = make_asset_input(assets, look_back, self.look_ahead, self.batch_size)
# self.models = [0,1]
self.assets = assets
test_ipdb.py 文件源码
项目:python_for_linux_system_administration
作者: lalor
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def sum_nums(n):
s=0
for i in range(n):
ipdb.set_trace()
s += i
print(s)
def test_filter_on_flag_column_nothing_left():
bad_df = pd.DataFrame({'spkitemid': ['a1', 'b1', 'c1', 'd1'],
'sc1': [1, 2, 1, 3],
'feature': [2, 3, 4, 5],
'flag1': [1, 0, 20, 14],
'flag2': [1, 1.0, 'TD', '03']})
flag_dict = {'flag1': [1, 0, 14], 'flag2': ['TD']}
df_new, df_excluded = filter_on_flag_columns(bad_df, flag_dict)
import ipdb
ipdb.set_trace()
def poll():
# global curr_time
# ipdb.set_trace()
global curr_time
# curr = session['curr']
while os.path.isfile('/mnt/lock'):
pass
a = soldier.run('sudo touch /mnt/lock', sudo=syspass)
resp = []
f = open('/mnt/chat.txt', 'r')
lines = f.readlines()
print lines
for line in lines:
tm = line.split("$$$")[0]
print str(curr_time) + " $$$ " + str(tm)
print int(tm) > int(curr_time)
if int(tm) > int(curr_time):
tt = datetime.datetime.fromtimestamp(int(tm)/1000).strftime('%Y-%m-%d %H:%M:%S')
try:
resp.append(tt + ' : ' + line.split("$$$")[1] + ' : ' + line.split("$$$")[2] )
curr_time = int(tm)
except:
pass
try:
curr_time = int(tm)
except:
pass
f.close()
a = soldier.run('sudo rm /mnt/lock', sudo=syspass)
# session['curr'] = curr
return resp
# return 'hello'
def send(msg,tm):
# ipdb.set_trace()
curr = tm
while os.path.isfile('/mnt/lock'):
pass
a = soldier.run('sudo touch /mnt/lock', sudo=syspass)
resp = []
f = open('/mnt/chat.txt', 'a')
f.write(str(curr) + '$$$' + str(session['name']) + '$$$' + msg + '\n')
f.close()
a = soldier.run('sudo rm /mnt/lock', sudo=syspass)
return "success"
def params_compare(old_ps, new_ps):
try:
from itertools import zip_longest
for (o, ov), (n, nv) in zip_longest(old_ps.items(), new_ps.items(), fillvalue=(None, None)):
if o == n and ov == nv:
continue
param_compare(ov, nv)
except:
import ipdb
ipdb.set_trace()
def ipdb_breakpoint(x):
"""A simple hook function for :func:`put_hook` that runs ipdb.
Parameters
----------
x : :class:`~numpy.ndarray`
The value of the hooked variable.
"""
import ipdb
ipdb.set_trace()
def feature(aegan, filename):
import ipdb
with ipdb.launch_ipdb_on_exception():
aegan.load(prefix='./samples/reid_aegan/aegan/50')
paths = map(lambda x: x.strip(), open('protocol/cuhk01-all.txt').readlines())
x = transform( np.array([load_image(path, (64, 128)) for path in paths]) )
code = aegan.autoencoder.encoder.predict(x)
ipdb.set_trace()
def test(aegan, prefix):
import ipdb
with ipdb.launch_ipdb_on_exception():
aegan.load(prefix=prefix)
from GAN.utils.vis import vis_grid
vis_grid(inverse_transform(aegan.generator.random_generate(128)), (2, 20), 'random_generate.png')
paths = map(lambda x: x.strip(), open('protocol/cuhk01-all.txt').readlines())
from load import load_image
sample = transform( np.array([load_image(path, (64, 128)) for path in paths[:128]]) )
vis_grid(inverse_transform(sample), (2, 20), 'sample.png')
vis_grid(inverse_transform(aegan.autoencoder.autoencoder.predict(sample)), (2, 20), 'reconstruct.png')
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# codes = aegan.autoencoder.encoder.predict(sample)
# codes = aegan.generator.sample(128)
codes = aegan.autoencoder.encoder.predict(aegan.generator.random_generate(128))
for ind, code in enumerate(codes):
n, bins, patches = plt.hist(code, 50, normed=1, facecolor='green', alpha=0.75)
plt.savefig('test/{}.pdf'.format(ind))
plt.clf()
ipdb.set_trace()
def feature(aegan, filename):
import ipdb
with ipdb.launch_ipdb_on_exception():
aegan.load(prefix='./samples/reid_aegan/aegan/50')
paths = map(lambda x: x.strip(), open('protocol/cuhk01-all.txt').readlines())
x = transform( np.array([load_image(path, (64, 128)) for path in paths]) )
code = aegan.autoencoder.encoder.predict(x)
ipdb.set_trace()
def test(aegan, prefix):
import ipdb
with ipdb.launch_ipdb_on_exception():
aegan.load(prefix=prefix)
from GAN.utils.vis import vis_grid
vis_grid(inverse_transform(aegan.generator.random_generate(128)), (2, 20), 'random_generate.png')
paths = map(lambda x: x.strip(), open('protocol/cuhk01-all.txt').readlines())
from load import load_image
sample = transform( np.array([load_image(path, (64, 128)) for path in paths[:128]]) )
vis_grid(inverse_transform(sample), (2, 20), 'sample.png')
vis_grid(inverse_transform(aegan.autoencoder.autoencoder.predict(sample)), (2, 20), 'reconstruct.png')
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# codes = aegan.autoencoder.encoder.predict(sample)
# codes = aegan.generator.sample(128)
codes = aegan.autoencoder.encoder.predict(aegan.generator.random_generate(128))
for ind, code in enumerate(codes):
n, bins, patches = plt.hist(code, 50, normed=1, facecolor='green', alpha=0.75)
plt.savefig('test/{}.pdf'.format(ind))
plt.clf()
ipdb.set_trace()
def feature_aegan(aegan, modelname, protoname):
with ipdb.launch_ipdb_on_exception():
aegan.load(prefix=modelname)
x = transform(load_all(protoname, (npxw, npxh)))
code = aegan.autoencoder.encoder.predict(x)
ipdb.set_trace()
def apply(self, inputs, gate_inputs, mask=None):
def step(inputs, gate_inputs, states, state_to_gates, state_to_state):
#import ipdb
#ipdb.set_trace()
gate_values = self.gate_activation.apply(
states.dot(self.state_to_gates) + gate_inputs)
update_values = gate_values[:, :self.dim]
reset_values = gate_values[:, self.dim:]
states_reset = states * reset_values
next_states = self.activation.apply(
states_reset.dot(self.state_to_state) + inputs)
next_states = (next_states * update_values +
states * (1 - update_values))
return next_states
def step_mask(inputs, gate_inputs, mask_input, states, state_to_gates, state_to_state):
next_states = step(inputs, gate_inputs, states, state_to_gates, state_to_state)
if mask_input:
next_states = (mask_input[:, None] * next_states +
(1 - mask_input[:, None]) * states)
return next_states
if mask:
func = step_mask
sequences = [inputs, gate_inputs, mask]
else:
func = step
sequences = [inputs, gate_inputs]
#[dict(input=inputs), dict(input=gate_inputs), dict(input=mask)]
output = tensor.repeat(self.params[2].dimshuffle('x',0), inputs.shape[1], axis=0)
states_output, _ = theano.scan(fn=func,
sequences=sequences,
outputs_info=[output],
non_sequences=[self.state_to_gates, self.state_to_state],
strict=True,
#allow_gc=False)
)
return states_output
def apply(self, inputs, update_inputs, reset_inputs, mask=None):
def step(inputs, update_inputs, reset_inputs, states, state_to_update, state_to_reset, state_to_state):
#import ipdb
#ipdb.set_trace()
reset_values = self.gate_activation.apply(
states.dot(self.state_to_reset) + reset_inputs)
update_values = self.gate_activation.apply(
states.dot(self.state_to_update) + update_inputs)
next_states_proposed = self.activation.apply(
(states * reset_values).dot(self.state_to_state) + inputs)
next_states = (next_states_proposed * update_values +
states * (1 - update_values))
return next_states
def step_mask(inputs, update_inputs, reset_inputs, mask_input, states, state_to_update, state_to_reset, state_to_state):
next_states = step(inputs, updatE_inputs, reset_inputs, states, state_to_update, state_to_reset, state_to_state)
if mask_input:
next_states = (mask_input[:, None] * next_states +
(1 - mask_input[:, None]) * states)
return next_states
if mask:
func = step_mask
sequences = [inputs, update_inputs, reset_inputs, mask]
else:
func = step
sequences = [inputs, update_inputs, reset_inputs]
#[dict(input=inputs), dict(input=gate_inputs), dict(input=mask)]
#output = tensor.repeat(self.params[2].dimshuffle('x',0), inputs.shape[1], axis=0)
states_output, _ = theano.scan(fn=func,
sequences=sequences,
outputs_info=[self.initial_state('initial_state', inputs.shape[1])],
non_sequences=[self.state_to_reset, self.state_to_update, self.state_to_state],
strict=True,
allow_gc=False)
return states_output
def get_or_create_module(self, fullname):
"""
Given a name and a path it will return a module instance
if found.
When the module could not be found it will raise ImportError
"""
LOGGER.info('Loading module {0}'.format(fullname))
parent, _, module_name = fullname.rpartition('.')
if fullname in modules:
LOGGER.info('Found cache entry for {0}'.format(fullname))
return modules[fullname]
module = modules.setdefault(fullname, imp.new_module(fullname))
if len(fullname.strip('.')) > 3:
absolute_from_root = fullname.split('.', 3)[-1]
modules.setdefault(absolute_from_root, module)
if len(fullname.split('.')) == 4:
# add the root of the project
modules[fullname.split('.')[-1]] = module
# required by PEP 302
module.__file__ = self.get_filename(fullname)
LOGGER.info('Created module {0} with fullname {1}'.format(self.get_filename(fullname), fullname))
module.__name__ = fullname
module.__loader__ = self
module.__path__ = self.path
if self.is_package(fullname):
module.__path__ = self.path
module.__package__ = fullname
else:
module.__package__ = fullname.rpartition('.')[0]
LOGGER.debug('loading file {0}'.format(self.get_filename(fullname)))
source = self.get_source(fullname)
try:
exec(source, module.__dict__)
except Exception as ex:
ipdb.set_trace()
return module
def sample(self, dist_info):
samples = self._f_sample(dist_info["prob"])
import ipdb
ipdb.set_trace()