How to create HDF5 file (mutli label classification) out of txt file to use in Caffe
<p>I have the following structure in a .txt file:</p>

<blockquote>
<pre><code>/path/to/image x y
/path/to/image x y
</code></pre>
</blockquote>

<p>where x and y are integers.</p>

<p>What I want to do now is: Create a hdf5 file to use in Caffe (<code>'train.prototxt'</code>)</p>

<p>My Python code looks like this:</p>

<pre><code>import h5py
import numpy as np
import os

text = 'train'
text_dir = text + '.txt'

data = np.genfromtxt(text_dir, delimiter=" ", dtype=None)

h = h5py.File(text + '.hdf5', 'w')
h.create_dataset('data', data=data[:1])
h.create_dataset('label', data=data[1:])

with open(text + "_hdf5.txt", "w") as textfile:
    textfile.write(os.getcwd() + '/' +text + '.hdf5')
</code></pre>

<p>But this does not work! Any ideas what could be wrong?</p>

<p>It does not work because your <code>'data'</code> is <code>/path/to/image</code> instead of the image itself.</p>

<p>See <a href="http://stackoverflow.com/a/31808324/1714410">this answer</a>, and <a class='doc-link' href="http://stackoverflow.com/documentation/caffe/5344/prepare-data-for-training/19117/prepare-arbitrary-data-in-hdf5-format#t=201608100602208392787">this documentation section</a> for more information.</p>

python neural-network deep-learning caffe multilabel-classification