tic
n = 300
m=20
train_x = []
test_x = []
for i = 1:n
%filename = strcat(['D:\Program Files\MATLAB\R2012a\work\DeepLearn\Solar_SAE\64_64_3train\' num2str(i,'%03d') '.bmp'])
%filename = strcat(['E:\matlab\work\c0\TrainImage' num2str(i,'%03d') '.bmp'])
filename = strcat(['E:\image restoration\3-(' num2str(i) ')-4.jpg'])
b = imread(filename)
%c = rgb2gray(b)
c=b
[ImageRow ImageCol] = size(c)
c = reshape(c,[1,ImageRow*ImageCol])
train_x = [train_xc]
end
for i = 1:m
%filename = strcat(['D:\Program Files\MATLAB\R2012a\work\DeepLearn\Solar_SAE\64_64_3test\' num2str(i,'%03d') '.bmp'])
%filename = strcat(['E:\matlab\work\c0\TestImage' num2str(i+100,'%03d') '-1.bmp'])
filename = strcat(['E:\image restoration\3-(' num2str(i+100) ').jpg'])
b = imread(filename)
%c = rgb2gray(b)
c=b
[ImageRow ImageCol] = size(c)
c = reshape(c,[1,ImageRow*ImageCol])
test_x = [test_xc]
end
train_x = double(train_x)/255
test_x = double(test_x)/255
%train_y = double(train_y)
%test_y = double(test_y)
% Setup and train a stacked denoising autoencoder (SDAE)
rng(0)
%sae = saesetup([4096 500 200 50])
%sae.ae{1}.activation_function = 'sigm'
%sae.ae{1}.learningRate = 0.5
%sae.ae{1}.inputZeroMaskedFraction = 0.0
%sae.ae{2}.activation_function = 'sigm'
%sae.ae{2}.learningRate = 0.5
%%sae.ae{2}.inputZeroMaskedFraction = 0.0
%sae.ae{3}.activation_function = 'sigm'
%sae.ae{3}.learningRate = 0.5
%sae.ae{3}.inputZeroMaskedFraction = 0.0
%sae.ae{4}.activation_function = 'sigm'
%sae.ae{4}.learningRate = 0.5
%sae.ae{4}.inputZeroMaskedFraction = 0.0
%opts.numepochs = 10
%opts.batchsize = 50
%sae = saetrain(sae, train_x, opts)
%visualize(sae.ae{1}.W{1}(:,2:end)')
% Use the SDAE to initialize a FFNN
nn = nnsetup([4096 1500 500 200 50 200 500 1500 4096])
nn.activation_function = 'sigm'
nn.learningRate = 0.03
nn.output = 'linear'% output unit 'sigm' (=logistic), 'softmax' and 'linear'
%add pretrained weights
%nn.W{1} = sae.ae{1}.W{1}
%nn.W{2} = sae.ae{2}.W{1}
%nn.W{3} = sae.ae{3}.W{1}
%nn.W{4} = sae.ae{3}.W{2}
%nn.W{5} = sae.ae{2}.W{2}
%nn.W{6} = sae.ae{1}.W{2}
%nn.W{7} = sae.ae{2}.W{2}
%nn.W{8} = sae.ae{1}.W{2}
% Train the FFNN
opts.numepochs = 30
opts.batchsize = 150
tx = test_x(14,:)
nn1 = nnff(nn,tx,tx)
ty1 = reshape(nn1.a{9},64,64)
nn = nntrain(nn, train_x, train_x, opts)
toc
tic
nn2 = nnff(nn,tx,tx)
toc
tic
ty2 = reshape(nn2.a{9},64,64)
tx = reshape(tx,64,64)
tz = tx - ty2
tz = im2bw(tz,0.1)
%imshow(tx)
%figure,imshow(ty2)
%figure,imshow(tz)
ty = cat(2,tx,ty2,tz)
montage(ty)
filename3 = strcat(['E:\image restoration\3.jpg'])
e=imread(filename3)
f= rgb2gray(e)
f=imresize(f,[64,64])
%imshow(ty2)
f=double (f)/255
[PSNR, MSE] = psnr(ty2,f)
imwrite(ty2,'E:\image restoration\bptest.jpg','jpg')
toc
%visualize(ty)
%[er, bad] = nntest(nn, tx, tx)
%assert(er <0.1, 'Too big error')
1,我用的是matlab R2008,一列代表一个样本。其他版本的不知道2,matlab中神经网络工具箱就已经很方便了,调用函数和修改参数就可以用了。
3,net_1.trainParam.lr代表学习速率,net_1.trainParam.mc则是动量系数。至于参数的确定,要看具体情况。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)