如何在 caffe 中训练/测试我自己的数据集? [英] How to training/testing my own dataset in caffe?

查看:38
本文介绍了如何在 caffe 中训练/测试我自己的数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Caffe 开始,mnist 示例运行良好.
我将火车和标签数据作为 data.mat.(我有 300 个训练数据,其中 30 个特征和标签是保存在 data.mat 中的 (-1, +1)).

I started with Caffe and the mnist example ran well.
I have the train and label data as data.mat. (I have 300 training data with 30 features and labels are (-1, +1) that have saved in data.mat).

但是,我不太明白如何使用 caffe 来实现自己的数据集?

However, I don't quite understand how I can use caffe to implement my own dataset?

有没有分步教程可以教我?

Is there a step by step tutorial can teach me?

非常感谢!!!!任何建议将不胜感激!

Many thanks!!!! Any advice would be appreciated!

推荐答案

我认为将数据从 Matlab 传输到 caffe 最直接的方法是通过 HDF5 文件.

I think the most straight forward way to transfer data from Matlab to caffe is via HDF5 file.

首先,使用 将 Matlab 中的数据保存在 HDF5 文件中hdf5write.我假设您的训练数据存储在大小为 300×30 的变量名称 X 中,标签存储在 y 一个 300×1 向量中:

First, save your data in Matlab in an HDF5 file using hdf5write. I assume your training data is stored in a variable name X of size 300-by-30 and the labels are stored in y a 300-by-1 vector:

hdf5write('my_data.h5', '/X', 
  single( permute(reshape(X,[300, 30, 1, 1]),[4:-1:1]) ) );
hdf5write('my_data.h5', '/label', 
  single( permute(reshape(y,[300, 1, 1, 1]),[4:-1:1]) ), 
  'WriteMode', 'append' );

请注意,数据保存为 4D 数组:第一个维度是特征的数量,第二个是特征的维度,最后两个是 1(表示没有空间维度).另请注意,HDF5 中数据的名称是 "X""label" - 这些名称应用作 "top" 输入数据层的 blob.

Note that the data is saved as a 4D array: the first dimension is the number of features, second one is the feature's dimension and the last two are 1 (representing no spatial dimensions). Also note that the names given to the data in the HDF5 are "X" and "label" - these names should be used as the "top" blobs of the input data layer.

为什么要置换?请参阅此答案了解说明.

Why permute? please see this answer for an explanation.

您还需要准备一个文本文件,列出您正在使用的所有 hdf5 文件的名称(在您的情况下,只有 my_data.h5).文件 /path/to/list/file.txt 应该只有一行

You also need to prepare a text file listing the names of all hdf5 files you are using (in your case, only my_data.h5). File /path/to/list/file.txt should have a single line

/path/to/my_data.h5

/path/to/my_data.h5

现在您可以将输入数据层添加到您的 train_val.prototxt

Now you can add an input data layer to your train_val.prototxt

layer {
  type: "HDF5Data"
  name: "data"
  top: "X"     # note: same name as in HDF5
  top: "label" # 
  hdf5_data_param {
    source: "/path/to/list/file.txt"
    batch_size: 20
  }
  include { phase: TRAIN }
}

有关 hdf5 输入层的更多信息,您可以查看此答案.

For more information regarding hdf5 input layer, you can see in this answer.

这篇关于如何在 caffe 中训练/测试我自己的数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆