<p>You don't need to use the exact same format - this is just a tutorial.... All you need to do is provide one or multiple data layers, with a total of three top Blobs: <code>data</code>, <code>data_p</code>, and <code>sim</code>. You can do that in any way you'd like, e.g. LMDB (like in the MNIST example), HDF5, or whatever.</p>
<h3>General explanation</h3>
<p>In the tutorial, they further show and easy way to load the image pairs: you concatenate two images in the channel dimension. For gray-scale, you take two input images, where each has for example the dimension <code>[1, 1, 28, 28]</code> (i.e. 1 image, 1 channel, 28x28 resolution). Then you concatenate them to be one image of size <code>[1, 2, 28, 28]</code> and save them e.g. to an LMDB.</p>
<p>In the network, the first step after loading the data is a &quot;Slice&quot; layer, which takes this image, and slices it (i.e. it splits it up) along that axis, thus creating two Top blobs, <code>data</code> and <code>data_p</code>.</p>
<h3> How to create the data files?</h3>
<p>There is no single right way to do that. The <a href="https://github.com/BVLC/caffe/blob/master/examples/siamese/convert_mnist_siamese_data.cpp" rel="nofollow noreferrer">code</a> from the tutorial is only for the MNIST set, so unless you have the <em>exact</em> same format, you can't use it without changes. You have a couple of possibilities:</p>
<ol>
<li><p>Convert your images to the MNIST-format. Then, the code from the Caffe tutorial works out-of-the-box. It appears that you are trying this - if you need help on that, please be specific: what is &quot;mnisten&quot;, include your code, and so on.</p>
</li>
<li><p>Write your own script to convert the images.
This is actually very simple: all you need to do is read the images in your favorite programming language, select the pairs, calculate the labels, and re-save as LMDB.
This is definitely the more flexible way.</p>
</li>
<li><p>Create HDF5 files with multiple Top blobs. This is very simple to do, but will probably be a bit slower than using LMDB.</p>
</li>
</ol>
<p>What you use is up to you - I'd probably go with HDF5, as this is an easy and very flexible way to start.</p>
<h3> How to generate the pairs?</h3>
<p>Now, this is the difficult question here. The code from the tutorial just selects random pairs, which is not really optimal, and will make learning rather slow. You don't just need random pairs, you needmeaningful, difficult, but still solvable pairs. How to do that depends entirely on your dataset.</p>
<p>A very sophisticated example is presented, in (Radenović, 2016): they use a Siamese network for learning a representation for image retrieval on buildings. They use a Structure-from-Motion (SfM) algorithm to create a 3-D reconstruction of a building, and then sample image pairs from those reconstructions.</p>
<p>How exactly you create the pairs depends on your data - maybe you are fine with random pairs - maybe you need a sophisticated method.</p>
<p><strong>Literature:</strong></p>
<p>F. Radenović, G. Tolias, and O. Chum. &quot;CNN Image Retrieval Learns from BoW: Unsupervised Fine-Tuning with Hard Examples&quot;. In: European Conference on Computer Vision (ECCV), 2016. arXiv: <a href="http://arxiv.org/abs/1604.02426" rel="nofollow noreferrer">1604.02426</a>.</p>
How to convert an arbitrary dataset to the siamese network dataset format in caffe?
<p>I have a dataset that I have created of gray scale images which i want to use with the siamese network example in caffe in which the documentation uses mnist dataset. I want to replace the mnist dataset with my own dataset </p>

<p>I see that for doing this I need my dataset to be in the format required by the siamese netwrk. This can be created using the 'create_mnist_siamese.sh' which loads the mnist dataset in the idx3-ubyte format and creates a dataset lmdb database with two images and a matching/non matching label in each location of the lmdb database.</p>

<p>So I figured for me to use the 'create_mnist_siamese.sh' script, my dataset also needs to be in the idx-ubyte format. I tried to convert my dataset to the idx-ubyte format using 'mnisten'. However i get the error 'error:total images are less than num_tests'. I guess the script is not identifying my images. The folder structure of the dataset is like this:</p>

<pre><code>parent-directory
  - subfolder
  - subfolder 
  .
  .
  .
  -txt file
</code></pre>

<p>parent directory name - 'generated dataset'<br>
subfolders - 1 ,2 ,3 ... (the subfolders are titled 1 - 30 as I want to label the data in each subfolder by the name of the subfolder)<br>
The txt file contains image title on each row with the class label.</p>

<p>How do I work with my dataset on the siamese network in caffe? Is there a direct way to convert my dataset to the lmdb format for the siamese network? Or do I have to use mnisten? If I do then how do I fix my error ? Anu help will be much appreciated. Thanks.</p>