【发布时间】:2017-05-08 22:38:21
【问题描述】:
我正在尝试使用单输出训练 MNIST 数据集。这意味着当我给一个 28*28 的输入(图像)时,模型给了我们一个公正的数字。例如我给'5',模型给我的结果是4.9,5、5.002或接近5。所以我有一些红色的文件。人们告诉softmaxlayer必须用回归层来改变。为了这样做。我正在使用 matconvnet 库及其 mnist 示例。我已经改变了我的网络并编写了回归层损失函数。这些是我的代码:
net.layers = {} ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{f*randn(5,5,1,20, 'single'), zeros(1, 20, 'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'pool', ...
'method', 'max', ...
'pool', [2 2], ...
'stride', 2, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{f*randn(5,5,20,50, 'single'),zeros(1,50,'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'pool', ...
'method', 'max', ...
'pool', [2 2], ...
'stride', 2, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{f*randn(4,4,50,500, 'single'), zeros(1,500,'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'relu') ;
net.layers{end+1} = struct('type', 'conv', ...
'weights', {{f*randn(1,1,500,1, 'single'), zeros(1,1,'single')}}, ...
'stride', 1, ...
'pad', 0) ;
net.layers{end+1} = struct('type', 'normloss');
这是回归损失函数:
function Y = vl_normloss(X,c,dzdy)
size(X)%1 1 1 100
size(c)%1 100
if nargin <= 2
Y = 0.5*sum((squeeze(X)'-c).^2);
size(Y)%1 1
Y % 1.7361e+03
else
size(Y)
Y = +((squeeze(X)'-c))*dzdy;
Y = reshape(Y,size(X));
end
我将opts.errorFunction = 'multiclass' ; 更改为'none'
我也加了
case 'normloss'
res(i+1).x = vl_normloss(res(i).x,l.class) ;
到 vl_simplenn 脚本
但是当我运行 train 时会出现这个错误
错误使用 vl_nnconv DEROUTPUT 维度与 X 和 过滤器。
vl_simplenn 中的错误(第 415 行) [res(i).dzdx, dzdw{1}, dzdw{2}] = ...
我必须做些什么来解决这个问题?谢谢
【问题讨论】:
-
> 我正在尝试使用单输出训练 MNIST 数据集 不要那样做。对分类任务使用回归是个坏主意。
-
我知道这是个坏主意,但我必须这样做
-
我按照你说的做了,我的意思是我改变了 vl_simplenn 并使用 norm loss 作为最后一层,但是当我训练网络时,在输出中,它说它是 softmaxloss,它没有使用 normloss。你知道为什么会这样吗?
-
可能 Softmaxloss 没有随着您的代码中的 normloss 发生变化,您可以在 vl_simplenn 脚本中检查前馈和后向部分的函数名称(normloss softmaxloss)。还要检查您的 cnn_init 脚本。你的错误看起来很简单,但我不知道确切
标签: regression deep-learning mnist loss matconvnet