本文整理汇总了Python中pylearn2.datasets.dense_design_matrix.DenseDesignMatrix.get_topological_view方法的典型用法代码示例。如果您正苦于以下问题:Python DenseDesignMatrix.get_topological_view方法的具体用法?Python DenseDesignMatrix.get_topological_view怎么用?Python DenseDesignMatrix.get_topological_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylearn2.datasets.dense_design_matrix.DenseDesignMatrix
的用法示例。
在下文中一共展示了DenseDesignMatrix.get_topological_view方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_with_X_or_topo
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [as 别名]
def test_init_with_X_or_topo():
# tests that constructing with topo_view works
# tests that construction with design matrix works
# tests that conversion from topo_view to design matrix and back works
# tests that conversion the other way works too
rng = np.random.RandomState([1, 2, 3])
topo_view = rng.randn(5, 2, 2, 3)
d1 = DenseDesignMatrix(topo_view=topo_view)
X = d1.get_design_matrix()
d2 = DenseDesignMatrix(X=X, view_converter=d1.view_converter)
topo_view_2 = d2.get_topological_view()
assert np.allclose(topo_view, topo_view_2)
X = rng.randn(*X.shape)
topo_view_3 = d2.get_topological_view(X)
X2 = d2.get_design_matrix(topo_view_3)
assert np.allclose(X, X2)
示例2: get_feats_from_cnn
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [as 别名]
def get_feats_from_cnn(rows, model=None):
"""
fprop rows using best trained model and returns activations of the
penultimate layer
"""
conf = utils.get_config()
patch_size = conf['patch_size']
region_size = conf['region_size']
batch_size = None
preds = utils.get_predictor(model=model, return_all=True)
y = np.zeros(len(rows))
samples = np.zeros(
(len(rows), region_size, region_size, 1), dtype=np.float32)
for i, row in enumerate(rows):
print 'processing %i-th image: %s' % (i, row['image_filename'])
try:
samples[i] = utils.get_samples_from_image(row, False)[0]
except ValueError as e:
print '{1} Value error: {0}'.format(str(e), row['image_filename'])
y[i] = utils.is_positive(row)
ds = DenseDesignMatrix(topo_view=samples)
pipeline = utils.get_pipeline(
ds.X_topo_space.shape, patch_size, batch_size)
pipeline.apply(ds)
return preds[-2](ds.get_topological_view()), y
示例3: function
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [as 别名]
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() )
W = model.W.get_value()
weights_view = dataset.get_weights_view( W.T )
示例4: PatchViewer
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [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()
示例5: make_majority_vote
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [as 别名]
def make_majority_vote():
model_paths = ['convnet_' + str(i+1) + '.pkl' for i in range(10)]
out_path = 'submission.csv'
models = []
for model_path in model_paths:
print('Loading ' + model_path + '...')
try:
with open(model_path, 'rb') as f:
models.append(pkl.load(f))
except Exception as e:
try:
with gzip.open(model_path, 'rb') as f:
models.append(pkl.load(f))
except Exception as e:
usage()
print(model_path + "doesn't seem to be a valid model path, I got this error when trying to load it: ")
print(e)
# load the test set
with open('test_data_for_pylearn2.pkl', 'rb') as f:
dataset = pkl.load(f)
dataset = DenseDesignMatrix(X=dataset, view_converter=DefaultViewConverter(shape=[32, 32, 1], axes=['b', 0, 1, 'c']))
preprocessor = GlobalContrastNormalization(subtract_mean=True, sqrt_bias=0.0, use_std=True)
preprocessor.apply(dataset)
predictions = []
print('Model description:')
print('')
print(models[1])
print('')
for model in models:
model.set_batch_size(dataset.X.shape[0])
X = model.get_input_space().make_batch_theano()
Y = model.fprop(X) # forward prop the test data
y = T.argmax(Y, axis=1)
f = function([X], y)
x_arg = dataset.get_topological_view()
y = f(x_arg.astype(X.dtype))
assert y.ndim == 1
assert y.shape[0] == dataset.X.shape[0]
# add one to the results!
y += 1
predictions.append(y)
predictions = np.array(predictions, dtype='int32')
y = mode(predictions.T, axis=1)[0]
y = np.array(y, dtype='int32')
import itertools
y = list(itertools.chain(*y))
assert len(y) == dataset.X.shape[0]
util.write_results(y, out_path)
print('Wrote predictions to submission.csv.')
return np.reshape(y, (1, -1))
示例6: print
# 需要导入模块: from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix [as 别名]
# 或者: from pylearn2.datasets.dense_design_matrix.DenseDesignMatrix import get_topological_view [as 别名]
print(len(models))
for model in models:
print(model)
model.set_batch_size(dataset.X.shape[0])
X = model.get_input_space().make_batch_theano()
Y = model.fprop(X) # forward prop the test data
y = T.argmax(Y, axis=1)
f = function([X], y)
x_arg = dataset.get_topological_view()
y = f(x_arg.astype(X.dtype))
assert y.ndim == 1
assert y.shape[0] == dataset.X.shape[0]
# add one to the results!
y += 1
predictions.append(y)
print(y)
predictions = np.array(predictions, dtype='int32')
y = mode(predictions.T, axis=1)[0]
y = np.array(y, dtype='int32')
开发者ID:deepxkn,项目名称:facial-expression-recognition-1,代码行数:33,代码来源:make_majority_vote_submission_from_pickled_ensemble.py