【问题标题】:Training neural network for image segmentation训练神经网络进行图像分割
【发布时间】:2015-05-22 21:18:30
【问题描述】:

我有一组原始图像块(101x101 矩阵)和另一组相应的二进制图像块(相同大小 101x101),它们是训练神经网络的“答案”。我想训练我的神经网络,以便它可以学习、识别从给定图像中训练出来的形状,并在输出矩阵(作为分割的结果)生成图像(可能是 150x10201 的相同矩阵形式?)。

原始图像在左侧,所需输出在右侧。

因此,对于数据的预处理阶段,我将原始图像块重塑为每个图像块的1x10201 的向量矩阵。结合其中的 150 个,我得到一个 150x10201 矩阵作为我的输入,另一个来自二进制图像补丁的 150x10201 矩阵。然后我将这些输入数据提供给深度学习网络。在这种情况下,我使用了深度信念网络。

我的用于设置和训练 DBN 的 Matlab 代码如下:

%训练一个 4 层 100 个隐藏单元 DBN 并使用它的权重来初始化一个 NN

rand('state',0)

%训练数据库

dbn.sizes = [100 100 100 100];
opts.numepochs =   5;
opts.batchsize =   10;
opts.momentum  =   0; 
opts.alpha     =   1;
dbn = dbnsetup(dbn, train_x, opts);
dbn = dbntrain(dbn, train_x, opts);

%将 dbn 展开为 nn

nn = dbnunfoldtonn(dbn, 10201);
nn.activation_function = 'sigm';

%train nn

opts.numepochs =  1;
opts.batchsize = 10;

assert(isfloat(train_x), 'train_x must be a float');
assert(nargin == 4 || nargin == 6,'number ofinput arguments must be 4 or 6')

loss.train.e               = [];
loss.train.e_frac          = [];
loss.val.e                 = [];
loss.val.e_frac            = [];
opts.validation = 0;
if nargin == 6
    opts.validation = 1;
end

fhandle = [];
if isfield(opts,'plot') && opts.plot == 1
    fhandle = figure();
end

m = size(train_x, 1);

batchsize = opts.batchsize;
numepochs = opts.numepochs;

numbatches = m / batchsize;

assert(rem(numbatches, 1) == 0, 'numbatches must be a integer');

L = zeros(numepochs*numbatches,1);
n = 1;
for i = 1 : numepochs
tic;

kk = randperm(m);
for l = 1 : numbatches
    batch_x = train_x(kk((l - 1) * batchsize + 1 : l * batchsize), :);

    %Add noise to input (for use in denoising autoencoder)
    if(nn.inputZeroMaskedFraction ~= 0)
        batch_x = batch_x.*(rand(size(batch_x))>nn.inputZeroMaskedFraction);
    end

    batch_y = train_y(kk((l - 1) * batchsize + 1 : l * batchsize), :);

    nn = nnff(nn, batch_x, batch_y);
    nn = nnbp(nn);
    nn = nnapplygrads(nn);

    L(n) = nn.L;

    n = n + 1;
end

t = toc;

if opts.validation == 1
    loss = nneval(nn, loss, train_x, train_y, val_x, val_y);
    str_perf = sprintf('; Full-batch train mse = %f, val mse = %f',
loss.train.e(end), loss.val.e(end));
else
    loss = nneval(nn, loss, train_x, train_y);
    str_perf = sprintf('; Full-batch train err = %f', loss.train.e(end));
end
if ishandle(fhandle)
    nnupdatefigures(nn, fhandle, loss, opts, i);
end

disp(['epoch ' num2str(i) '/' num2str(opts.numepochs) '. Took ' num2str(t) '  seconds' '. Mini-batch mean squared error on training set is ' num2str(mean(L((n-numbatches):(n-1)))) str_perf]);
nn.learningRate = nn.learningRate * nn.scaling_learningRate;
end

谁能告诉我,像这样的 NN 训练是否使其能够进行分割工作?或者我应该如何修改代码来训练神经网络,以便它可以将输出/结果生成为150x10201 形式的图像矩阵?

非常感谢..

【问题讨论】:

    标签: matlab image-segmentation deep-learning


    【解决方案1】:

    您的输入太大。您应该尝试使用从 19x19 到最大 30x30 的更小的补丁(这已经代表 900 个神经元进入输入层)。

    然后是您的主要问题:您只有 150 张图片!当你训练一个 NN 时,你需要的训练实例至少是 NN 中权重的三倍。所以要非常小心你选择的架构。

    CNN 可能更适合您的问题。

    【讨论】:

      猜你喜欢
      • 2015-06-02
      • 2017-05-28
      • 2017-10-07
      • 2019-11-13
      • 2011-04-07
      • 1970-01-01
      • 2013-08-24
      • 2019-10-04
      • 2010-11-20
      相关资源
      最近更新 更多