4 num_total_samples=10000;
5 % to simulate data being read from disk / generated etc.
6 data_disk=rand(5,5,1,num_total_samples);
7 label_disk=rand(10,num_total_samples);
12 for batchno=1:num_total_samples/chunksz
13 fprintf('batch no. %d\n', batchno);
14 last_read=(batchno-1)*chunksz;
16 % to simulate maximum data to be held in memory before dumping to hdf5 file
17 batchdata=data_disk(:,:,1,last_read+1:last_read+chunksz);
18 batchlabs=label_disk(:,last_read+1:last_read+chunksz);
21 startloc=struct('dat',[1,1,1,totalct+1], 'lab', [1,totalct+1]);
22 curr_dat_sz=store2hdf5(filename, batchdata, batchlabs, ~created_flag, startloc, chunksz);
23 created_flag=true;% flag set so that file is created only once
24 totalct=curr_dat_sz(end);% updated dataset size (#samples)
27 % display structure of the stored HDF5 file
32 % Read data and labels for samples #1000 to 1999
33 data_rd=h5read(filename, '/data', [1 1 1 1000], [5, 5, 1, 1000]);
34 label_rd=h5read(filename, '/label', [1 1000], [10, 1000]);
35 fprintf('Testing ...\n');
37 assert(isequal(data_rd, single(data_disk(:,:,:,1000:1999))), 'Data do not match');
38 assert(isequal(label_rd, single(label_disk(:,1000:1999))), 'Labels do not match');
40 fprintf('Success!\n');
42 fprintf('Test failed ...\n');
48 % CREATE list.txt containing filename, to be used as source for HDF5_DATA_LAYER
49 FILE=fopen('list.txt', 'w');
50 fprintf(FILE, '%s', filename);
52 fprintf('HDF5 filename listed in %s \n', 'list.txt');
54 % NOTE: In net definition prototxt, use list.txt as input to HDF5_DATA as:
61 % source: "/path/to/list.txt"