DeepLearning 工具包DeepLearnToolbox 的使用

时间:2024-04-17 08:01:21

DeepLearn Toolbox是一个非常有用的matlab deep learning工具包,下载地址:https://github.com/dupuleng/DeepLearnToolbox-master

要使用它首先要将该工具包添加到matlab的搜索路径中,

1、将包复制到matlab 的toolbox中,作者的路径是D:\program Files\matlab\toolbox\

2、在matlab的命令行中输入:  

cd D:\program Files\matlab\toolbox\deepLearnToolbox\
addpath(gepath(\'D:\program Files\matlab\toolbox\deepLearnToolbox-master\\')
savepath   %保存,这样就不需要每次都添加一次

3、验证添加是否成功,在命令行中输入  

which saesetup

如果成功就会出现,saesetup.m的路径D:\program Files\matlab\toolbox\deepLearnToolbox-master\SAE\saesetup.m 


4、使用deepLearnToolbox

load mnist_uint8;

train_x = double(train_x)/255;
test_x  = double(test_x)/255;
train_y = double(train_y);
test_y  = double(test_y);

%%  ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN
%  Setup and train a stacked denoising autoencoder (SDAE)
rand(\'state\',0)
sae = saesetup([784 100]);
sae.ae{1}.activation_function       = \'sigm\';
sae.ae{1}.learningRate              = 1;
sae.ae{1}.inputZeroMaskedFraction   = 0.5;
opts.numepochs =   1;
opts.batchsize = 100;
sae = saetrain(sae, train_x, opts);
visualize(sae.ae{1}.W{1}(:,2:end)\')

% Use the SDAE to initialize a FFNN
nn = nnsetup([784 100 10]);
nn.activation_function              = \'sigm\';
nn.learningRate                     = 1;
nn.W{1} = sae.ae{1}.W{1};

% Train the FFNN
opts.numepochs =   1;
opts.batchsize = 100;
nn = nntrain(nn, train_x, train_y, opts);
[er, bad] = nntest(nn, test_x, test_y);
assert(er < 0.16, \'Too big error\');