如何从图像目录中创建立体声网络的HDF5训练数据?

时间:2016-06-14 05:56:03

标签: matlab neural-network deep-learning caffe stereoscopy

此问题涉及回答here的问题 接受的答案建议动态创建标签。我有一个非常类似的问题,但需要使用HDF5。

这是我的原型文件:

name: "StereoNet"
layer {
    name: "layer_data_left"
    type: "HDF5Data"
    top: "data_left"
    top: "labels_left"
    include {
        phase: TRAIN
    }
    hdf5_data_param {
        source: "/home/ubuntu/trainLeftPatches.txt"
        batch_size: 128
    }
}
layer {
    name: "layer_data_right"
    type: "HDF5Data"
    top: "data_right"
    top: "labels_right"
    include {
        phase: TRAIN
    }
    hdf5_data_param {
        source: "/home/ubuntu/trainRightPatches.txt"
        batch_size: 128
    }
}
...  etc.

正如您所希望的那样,我创建了两个独立的数据HDF5数据文件。它们由正面和负面样本组成,其中在相同的索引上左图像和右图像,它们组合为正或负样本。 labels_left和labels_right是相同的1和0的matlab数组。我之前尝试使用单个标签数组,但是caffe给出了一个错误,这似乎表明两个进程发生了冲突。当更改为标签数组的副本时,可以开始培训。

以下是我正在使用的Matlab数据创建文件的一部分,数据是KITTI数据:

h5create('trainLeftPatches.h5','/data_left',[9 9 1 numberOfTrainingPatches],'Datatype','double');
h5create('trainLeftPatches.h5','/labels_left',[1 numberOfTrainingPatches],'Datatype','double');

h5create('trainRightPatches.h5','/data_right',[9 9 1 numberOfTrainingPatches],'Datatype','double');
h5create('trainRightPatches.h5','/labels_right',[1 numberOfTrainingPatches],'Datatype','double');

h5create('valLeftPatches.h5','/data_left',[9 9 1 numberOfValidatePatches],'Datatype','double');
h5create('valLeftPatches.h5','/labels_left',[1 numberOfValidatePatches],'Datatype','double');

h5create('valRightPatches.h5','/data_right',[9 9 1 numberOfValidatePatches],'Datatype','double');
h5create('valRightPatches.h5','/labels_right',[1 numberOfValidatePatches],'Datatype','double');

h5write('trainLeftPatches.h5','/data_left', dataLeft_permutated(:, :, :, 1:numberOfTrainingPatches));
h5write('trainLeftPatches.h5','/labels_left', labels_permutated(:, 1:numberOfTrainingPatches));

h5write('trainRightPatches.h5','/data_right', dataRight_permutated(:, :, :, 1:numberOfTrainingPatches));
h5write('trainRightPatches.h5','/labels_right', labels_permutated(:, 1:numberOfTrainingPatches));

h5write('valLeftPatches.h5','/data_left', dataLeft_permutated(:, :, :, numberOfTrainingPatches+1:end));
h5write('valLeftPatches.h5','/labels_left', labels_permutated(:, numberOfTrainingPatches+1:end));

h5write('valRightPatches.h5','/data_right', dataRight_permutated(:, :, :, numberOfTrainingPatches+1:end));
h5write('valRightPatches.h5','/labels_right', labels_permutated(:, numberOfTrainingPatches+1:end));

toc;

最后迷你批次的损失是可以接受的,但在测试中保持过高

请指教。 (可能不起作用)。如果有错误,可能会非常微妙。

1 个答案:

答案 0 :(得分:0)

您应该考虑以下几点:

  1. 您的网络是一个连体网络:它包含左右两条路径,但这些路径共享相同的过滤器。请参阅this tutorial如何构建跨层共享过滤器的暹罗网络。

  2. NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"dd/MM/YYYY HH:mm:s"]; NSString *str = [format stringFromDate:date]; 图层不限于两个输出(“顶部”),它可以包含您想要的任意数量。因此,您可以为火车和单层进行单层测试:

    "HDF5Data"

    相应的hdf5文件应该为layer { name: "data" type: "HDF5Data" top: "data_left" top: "data_right" top: "labels" hdf5_data_param { ... } include { phase: TRAIN } } 命令指定三个数据集(而不是代码中只有两个)。

  3. 您是否考虑过使用minibatch loss而不是配对丢失?