从 pylearn2 中的无监督学习中获取数据的学习表示 [英] Getting the learned representation of the data from the unsupervised learning in pylearn2
问题描述
我们可以使用以下 YAML 文件(以及 pylearn2/scripts/train.py)在 pylearn2 中训练自动编码器
We can train an autoencoder in pylearn2 using below YAML file (along with pylearn2/scripts/train.py)
!obj:pylearn2.train.Train {
dataset: &train !obj:pylearn2.datasets.mnist.MNIST {
which_set: 'train',
start: 0,
stop: 50000
},
model: !obj:pylearn2.models.autoencoder.DenoisingAutoencoder {
nvis : 784,
nhid : 500,
irange : 0.05,
corruptor: !obj:pylearn2.corruption.BinomialCorruptor {
corruption_level: .2,
},
act_enc: "tanh",
act_dec: null, # Linear activation on the decoder side.
},
algorithm: !obj:pylearn2.training_algorithms.sgd.SGD {
learning_rate : 1e-3,
batch_size : 100,
monitoring_batches : 5,
monitoring_dataset : *train,
cost : !obj:pylearn2.costs.autoencoder.MeanSquaredReconstructionError {},
termination_criterion : !obj:pylearn2.termination_criteria.EpochCounter {
max_epochs: 10,
},
},
save_path: "./dae_l1.pkl",
save_freq: 1
}
我们得到的是学习的自动编码器模型,如dae_l1.pkl".
What we get is the learned autoencoder model as "dae_l1.pkl".
如果我想使用这个模型进行监督训练,我可以使用dae_l1.pkl"来初始化一个 MLP 的层.然后我可以训练这个模型.我什至可以使用 'fprop' 函数预测模型的输出.
If I want to use this model for supervised training, I can use "dae_l1.pkl" to initialize the layer of an MLP. I can then train this model. I can even predict the output of the model using 'fprop' function.
但是,如果我不想使用这个预训练模型进行监督学习,而我只想使用自动编码器保存我的数据的新学习表示怎么办.
But what if I dun want to use this pretrained model for supervised learning and I just want to save the new learned representation of my data with the autoencoder.
我该怎么做?
更详细的问题放在这里
推荐答案
我认为您可以使用自动编码器的编码和解码功能来获取隐藏表示.例如:
I think you can use the encode and decode functions of the autoencoder to get the hidden representation. E.g:
l1_path = 'dae_l1.pkl'
l1 = serial.load(l1_path)
"""encode"""
#layer 1
l1Input = l1.get_input_space().make_theano_batch()
l1Encode = l1.encode(l1Input)
l1Decode = l1.decode(l1Encode)
l1EncodeFunction = theano.function([l1Input], l1Encode)
l1DecodeFunction = theano.function([l1Encode], l1Decode)
然后,表示将是:
l1encode = l1EncodeFunction(YourData)
这篇关于从 pylearn2 中的无监督学习中获取数据的学习表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!