本文整理汇总了Python中pylearn2.datasets.dense_design_matrix.DenseDesignMatrix.apply_preprocessor方法的典型用法代码示例。如果您正苦于以下问题:Python DenseDesignMatrix.apply_preprocessor方法的具体用法?Python DenseDesignMatrix.apply_preprocessor怎么用?Python DenseDesignMatrix.apply_preprocessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylearn2.datasets.dense_design_matrix.DenseDesignMatrix
的用法示例。
在下文中一共展示了DenseDesignMatrix.apply_preprocessor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zero_vector
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
def test_zero_vector(self):
""" Test that passing in the zero vector does not result in
a divide by 0 """
dataset = DenseDesignMatrix(X=as_floatX(np.zeros((1, 1))))
# the settings of subtract_mean and use_norm are not relevant to
# the test
# std_bias = 0.0 is the only value for which there should be a risk
# of failure occurring
preprocessor = GlobalContrastNormalization(subtract_mean=True, sqrt_bias=0.0, use_std=True)
dataset.apply_preprocessor(preprocessor)
result = dataset.get_design_matrix()
assert not np.any(np.isnan(result))
assert not np.any(np.isinf(result))
示例2: test_random_image
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
def test_random_image(self):
"""
Test on a random image if the per-processor loads and works without
anyerror and doesn't result in any nan or inf values
"""
rng = np.random.RandomState([1, 2, 3])
X = as_floatX(rng.randn(5, 32 * 32 * 3))
axes = ["b", 0, 1, "c"]
view_converter = dense_design_matrix.DefaultViewConverter((32, 32, 3), axes)
dataset = DenseDesignMatrix(X=X, view_converter=view_converter)
dataset.axes = axes
preprocessor = LeCunLCN(img_shape=[32, 32])
dataset.apply_preprocessor(preprocessor)
result = dataset.get_design_matrix()
assert not np.any(np.isnan(result))
assert not np.any(np.isinf(result))
示例3: function
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
feat = ( H > 0.5) * Mu1
else:
assert False
print 'compiling theano function'
f = function([V],feat)
print 'running theano function'
feat = f(X2)
feat_dataset = DenseDesignMatrix(X = feat, view_converter = DefaultViewConverter([1, 1, feat.shape[1]] ) )
print 'reassembling features'
ns = 32 - size + 1
depatchifier = ReassembleGridPatches( orig_shape = (ns, ns), patch_shape=(1,1) )
feat_dataset.apply_preprocessor(depatchifier)
print 'making topological view'
topo_feat = feat_dataset.get_topological_view()
assert topo_feat.shape[0] == X.shape[0]
print 'assembling visualizer'
n = np.ceil(np.sqrt(model.nhid))
pv3 = PatchViewer(grid_shape = (X.shape[0], num_filters), patch_shape=(ns,ns), is_color= False)
pv4 = PatchViewer(grid_shape = (n,n), patch_shape = (size,size), is_color = True, pad = (7,7))
pv5 = PatchViewer(grid_shape = (1,num_filters), patch_shape = (size,size), is_color = True, pad = (7,7))
idx = sorted(range(model.nhid), key = lambda l : -topo_feat[:,:,:,l].std() )
示例4: enumerate
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
rng = np.random.RandomState([1,2,3])
for i, img_path in enumerate(ImageIterator(path, suffix=".npy")):
img = np.load(img_path)
if img.shape[2] == 1:
img = np.concatenate((img,img,img),axis=2)
img = img.reshape(1,img.shape[0],img.shape[1],img.shape[2])
d = DenseDesignMatrix( topo_view = img, view_converter = DefaultViewConverter(img.shape[1:]) )
random_rng = np.random.RandomState([ rng.randint(0,256), rng.randint(0,256), rng.randint(0,256)])
p = ExtractPatches( patch_shape = patch_shape, num_patches = k , rng = random_rng)
d.apply_preprocessor(p)
X[i*3:(i+1)*3,:] = d.X
d.X = X
base = '/data/lisatmp/goodfeli/darpa_imagenet_patch_%dx%d_train.' % (patch_shape[0], patch_shape[1])
d.use_design_loc(base+'npy')
serial.save(base+'pkl',d)
示例5: PatchViewer
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
from pylearn2.utils import serial
stl10 = serial.load('/data/lisa/data/stl10/stl10_32x32/train.pkl')
batch = stl10.X[24:25,:]
img = stl10.view_converter.design_mat_to_topo_view(batch)[0,...] / 127.5
from pylearn2.gui.patch_viewer import PatchViewer
pv = PatchViewer((27,27),(6,6),pad=(1,1),is_color=True)
pipeline = serial.load('/data/lisa/data/stl10/stl10_patches/preprocessor.pkl')
del pipeline.items[0]
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix, DefaultViewConverter
for row in xrange(27):
for col in xrange(27):
patch = img[row:row+6,col:col+6]
d = DenseDesignMatrix( topo_view = patch.reshape(1,6,6,3), view_converter = DefaultViewConverter((6,6,3)) )
d.apply_preprocessor(pipeline)
pv.add_patch(d.get_topological_view()[0,...], rescale = True)
pv.show()
示例6: __call__
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import apply_preprocessor [as 别名]
def __call__(self, full_X):
feature_type = self.feature_type
pooling_region_counts = self.pooling_region_counts
model = self.model
size = self.size
nan = 0
full_X = full_X.reshape(1,full_X.shape[0],full_X.shape[1],full_X.shape[2])
if full_X.shape[3] == 1:
full_X = np.concatenate( (full_X, full_X, full_X), axis=3)
print 'full_X.shape: '+str(full_X.shape)
num_examples = full_X.shape[0]
assert num_examples == 1
pipeline = self.preprocessor
def average_pool( stride ):
def point( p ):
return p * ns / stride
rval = np.zeros( (topo_feat.shape[0], stride, stride, topo_feat.shape[3] ) , dtype = 'float32')
for i in xrange(stride):
for j in xrange(stride):
rval[:,i,j,:] = self.region_features( topo_feat[:,point(i):point(i+1), point(j):point(j+1),:] )
return rval
outputs = [ np.zeros((num_examples,count,count,model.nhid),dtype='float32') for count in pooling_region_counts ]
assert len(outputs) > 0
fd = DenseDesignMatrix(X = np.zeros((1,1),dtype='float32'), view_converter = DefaultViewConverter([1, 1, model.nhid] ) )
ns = 32 - size + 1
depatchifier = ReassembleGridPatches( orig_shape = (ns, ns), patch_shape=(1,1) )
batch_size = 1
for i in xrange(0,num_examples-batch_size+1,batch_size):
print i
t1 = time.time()
d = DenseDesignMatrix( topo_view = np.cast['float32'](full_X[i:i+batch_size,:]), view_converter = DefaultViewConverter((32,32,3)))
t2 = time.time()
#print '\tapplying preprocessor'
d.apply_preprocessor(pipeline, can_fit = False)
X2 = d.get_design_matrix()
t3 = time.time()
#print '\trunning theano function'
feat = self.f(X2)
t4 = time.time()
assert feat.dtype == 'float32'
feat_dataset = copy.copy(fd)
if np.any(np.isnan(feat)):
nan += np.isnan(feat).sum()
feat[np.isnan(feat)] = 0
feat_dataset.set_design_matrix(feat)
#print '\treassembling features'
feat_dataset.apply_preprocessor(depatchifier)
#print '\tmaking topological view'
topo_feat = feat_dataset.get_topological_view()
assert topo_feat.shape[0] == batch_size
t5 = time.time()
#average pooling
for output, count in zip(outputs, pooling_region_counts):
output[i:i+batch_size,...] = average_pool(count)
t6 = time.time()
print (t6-t1, t2-t1, t3-t2, t4-t3, t5-t4, t6-t5)
return outputs[0]