本文整理匯總了Python中pylearn2.gui.patch_viewer.PatchViewer.show方法的典型用法代碼示例。如果您正苦於以下問題:Python PatchViewer.show方法的具體用法?Python PatchViewer.show怎麽用?Python PatchViewer.show使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylearn2.gui.patch_viewer.PatchViewer
的用法示例。
在下文中一共展示了PatchViewer.show方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_monitor
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
def on_monitor(self, *args, **kwargs):
if not hasattr(self, 'record'):
self.record = {}
self.size = {}
for dataset in self.datasets:
assert tuple(dataset.view_converter.axes) == ('c', 0, 1, 'b')
self.record[dataset] = dataset.get_topological_view().copy()
self.size[dataset] = dataset.X.shape[0]
else:
for i, dataset in enumerate(self.datasets):
size = self.size[dataset]
assert dataset.X.shape[0] == size
self.record[dataset] = np.concatenate((self.record[dataset], dataset.get_topological_view().copy()),
axis=-1)
record_view = self.record[dataset].copy()
record_view /= np.abs(record_view).max()
pv = PatchViewer(grid_shape=(record_view.shape[3]/size, size),
patch_shape = record_view.shape[1:3], is_color = record_view.shape[0] == 3)
for j in xrange(record_view.shape[3]):
pv.add_patch(np.transpose(record_view[:,:,:,j], (1, 2, 0)), rescale=False)
print 'Dataset %d: ' % i
pv.show()
x = raw_input()
示例2: xrange
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
for i in xrange(Wv.shape[1]-1):
for j in xrange(i+1,Wv.shape[1]):
dot = abs(np.dot(Wv[:,i],Wv[:,j]))
to_sort.append( (-dot, (i,j) ) )
to_sort = sorted(to_sort)[0:100]
print -to_sort[0][0]
print -to_sort[99][0]
from pylearn2.config import yaml_parse
dataset = yaml_parse.load(model.dataset_yaml_src)
weights_view = dataset.get_weights_view(Wv.T)
from pylearn2.gui.patch_viewer import PatchViewer
pv = PatchViewer((100,2),(28,28),is_color=False)
for i in xrange(100):
l, r = to_sort[i][1]
l = weights_view[l]
r = weights_view[r]
pv.add_patch(l,rescale=True)
pv.add_patch(r,rescale=True)
pv.show()
示例3: function
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
F = T.matrix()
recons_func = function([F], model.energy_function.reconstruct(F))
def reconstruct(X, use_noise):
corrupt_X = X.copy()
if use_noise:
noise = N.random.randn(*corrupt_X.shape)
scaled_noise = noise * sigma
corrupt_X += scaled_noise
R = recons_func(corrupt_X)
return X, corrupt_X, R
for i in range(0,rows):
for j in range(0, examplesPerRow):
x = dataset.get_batch_design(1)
p.add_patch( reshape(x),rescale=True)
truth, noise, reconstruction = reconstruct(x, use_noise = True)
p.add_patch(reshape(truth ),rescale=True)
p.add_patch(reshape(noise ), rescale=True)
p.add_patch(reshape(reconstruction) , rescale=True)
print ( 'mse', N.square(reconstruction-truth).mean(), \
'mae', N.abs(reconstruction-truth).mean() )
truth, noise, reconstruction = reconstruct(x, use_noise = False)
p.add_patch( reshape(reconstruction) , rescale=True)
p.show()
示例4: xrange
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
pv4.add_patch(weights_view[cur_idx,:], rescale = True,
activation = activation)
if j >= filter_start and j < filter_start + num_filters:
pv5.add_patch(weights_view[cur_idx,:], rescale = True,
activation = activation)
if feature_type == 'exp_h':
print 'features are not rescaled; showing expectation of h without adjustment'
topo_feat *= 2.
topo_feat -= 1.
else:
print "features are contrast normalized so that each column uses 0.5 grey " \
"for 0 and its maximal absolute value is at the edge of the dynamic range"
for i in xrange(filter_start, filter_start + num_filters):
topo_feat[:,:,:,idx[i]] /= np.abs(topo_feat[:,:,:,idx[i]]).max()
for i in xrange(X.shape[0]):
#indices of channels sorted in order of descending standard deviation on this example
#plot the k most interesting channels
for j in xrange(filter_start, filter_start+num_filters):
pv3.add_patch(topo_feat[i,:,:,idx[j]], rescale = False, activation = 0.)
pv1.show()
pv3.show()
pv4.show()
pv5.show()
print 'weights viewer dimensions: '+str((n,n))
示例5: plot
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
main_viewer.add_patch(chan_viewer.image[:,:,viewer_dims] - 0.5)
chan_viewer.clear()
return copy.copy(main_viewer.image)
w_image = plot(wv)
if opts.phi:
phi_image = plot(phi)
nplots = 2 if opts.phi else 1
viewer = PatchViewer((1,nplots),
(w_image.shape[0],
w_image.shape[1]),
is_color = opts.color,
pad=(20,20))
viewer_dims = slice(0, None) if opts.color else 0
viewer.add_patch(w_image[:,:, viewer_dims] - 0.5)
if opts.phi:
viewer_dims = slice(0, None) if opts.color else 1
viewer.add_patch(phi_image[:,:,0] - 0.5)
pl.imshow(viewer.image, interpolation='nearest')
pl.savefig('filters_%s.png' % opts.path)
pl.close()
if not opts.noshow:
viewer.show()
示例6: DefaultViewConverter
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
viewconv = DefaultViewConverter(topo_shape)
viewdims = slice(0, None) if opts.color else 0
# load model and retrieve parameters
model = serial.load(opts.path)
wv = model.Wv.get_value().T
if opts.mu:
wv = wv * model.mu.get_value()[:, None]
wv_viewer = PatchViewer(get_dims(len(wv)), (opts.height, opts.width),
is_color = opts.color, pad=(2,2))
for i in xrange(len(wv)):
topo_wvi = viewconv.design_mat_to_topo_view(wv[i:i+1])
wv_viewer.add_patch(topo_wvi[0])
if opts.wv_only:
wv_viewer.show()
os.sys.exit()
wg = model.Wg.get_value()
wh = model.Wh.get_value()
wg_viewer2 = PatchViewer((opts.top, opts.top), (opts.height, opts.width),
is_color = opts.color, pad=(2,2))
wg_viewer1 = PatchViewer(get_dims(len(wg)/opts.top),
(wg_viewer2.image.shape[0], wg_viewer2.image.shape[1]),
is_color = opts.color, pad=(2,2))
for i in xrange(0, len(wg), opts.top):
for j in xrange(i, i + opts.top):
idx = numpy.argsort(wg[j])[-opts.top:][::-1]
for idx_j in idx:
topo_wgi = viewconv.design_mat_to_topo_view(wv[idx_j:idx_j+1])
wg_viewer2.add_patch(topo_wgi[0])
示例7: PatchViewer
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
dataset = yaml_parse.load(model.dataset_yaml_src)
W = model.W.get_value()
T = dataset.get_topological_view(W.T)
from pylearn2.gui.patch_viewer import PatchViewer
pv1 = PatchViewer((3,3),(32,32),is_color = True)
pv2 = PatchViewer((3,4),(32,32),is_color=True)
import numpy as np
rng = np.random.RandomState([1,2,3])
for i in xrange(12):
print i
while True:
print 'looping'
idxs = rng.randint(0,T.shape[0],(9,))
for j in xrange(9):
pv1.add_patch(T[idxs[j],:],activation=0.)
pv1.show()
x = raw_input('use which? (0-9): ')
idx = idxs[eval(x)]
break
pv2.add_patch(T[idx,:],activation=0.)
pv2.show()
示例8: eval
# 需要導入模塊: from pylearn2.gui.patch_viewer import PatchViewer [as 別名]
# 或者: from pylearn2.gui.patch_viewer.PatchViewer import show [as 別名]
wv = rbm.Wv.get_value().T
if opts.rings:
rings = eval(opts.rings)
wv = retina.decode(wv, (opts.height, opts.width, opts.chans), rings)
### Build channels for individual channels ###
chans_viewer = []
for chani in range(opts.chans):
patch_viewer = PatchViewer(
get_dims(len(wv)),
(opts.height, opts.width),
is_color = opts.color,
pad=(2,2))
chans_viewer += [patch_viewer]
for i in range(len(wv)):
patch_viewer.add_patch(wv[i,:,:,chani])
main_viewer = PatchViewer((1,opts.chans),
(chans_viewer[0].image.shape[0],
chans_viewer[0].image.shape[1]),
is_color = opts.color,
pad=(10,10))
for chan_viewer in chans_viewer:
main_viewer.add_patch(chan_viewer.image[:,:,viewdims] - 0.5)
main_viewer.show()