我正在尝试使用Matlab为1D数据设置一个简单的去噪自动编码器。目前,1D数据没有专门的输入层,必须使用imageInputLayer()
函数:
function net = DenoisingAutoencoder(data)
[N, n] = size(data);
%setting up input
X = zeros([n 1 1 N]);
for i = 1:n
for j = 1:N
X(i, 1, 1, j) = data(j,i);
end
end
% noisy X : 1/10th of elements are set to 0
Xnoisy = X;
mask1 = (mod(randi(10, size(X)), 7) ~= 0);
Xnoisy = Xnoisy .* mask1;
layers = [imageInputLayer([n 1 1]) fullyConnectedLayer(n) regressionLayer()];
opts = trainingOptions('sgdm');
net = trainNetwork(X, Xnoisy, layers, opts);
但是,代码失败并显示以下错误消息:
最后一层的输出大小[1 1 n ]与 响应大小[ n 1 1]。
有关如何重新配置输入/图层的任何想法?如果省略fullyConnectedLayer
,那么代码运行正常,但显然我没有隐藏层。
答案 0 :(得分:0)
目标输出应该是矩阵,而不是4D张量。
这是上一代码的工作版本:
function DenoisingAutoencoder(data)
[N, n] = size(data);
X = data;
Xoriginal = data;
Xout = data';
% corrupting the input
zeroMask = (mod(randi(100, size(X)), 99) ~= 0);
X = X + randn(size(X))*0.05;
X = X .* zeroMask;
X4D = reshape(X, [1 n 1 N]);
layers = [imageInputLayer([1 n]) fullyConnectedLayer(n) regressionLayer()];
opts = trainingOptions('sgdm');
net = trainNetwork(X4D, Xout, layers, opts);
R = predict(net, X4D)';