Skip to content

Commit

Permalink
Merge pull request BVLC#813 from sergeyk/dev
Browse files Browse the repository at this point in the history
Fix for bug in HDF5 Output Layer
  • Loading branch information
sergeyk committed Jul 28, 2014
2 parents c0462ab + 3715a08 commit e2f960e
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/caffe/layers/hdf5_output_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Dtype HDF5OutputLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
for (int i = 0; i < bottom[0]->num(); ++i) {
caffe_copy(data_datum_dim, &bottom[0]->cpu_data()[i * data_datum_dim],
&data_blob_.mutable_cpu_data()[i * data_datum_dim]);
caffe_copy(label_datum_dim, &bottom[0]->cpu_data()[i * label_datum_dim],
caffe_copy(label_datum_dim, &bottom[1]->cpu_data()[i * label_datum_dim],
&label_blob_.mutable_cpu_data()[i * label_datum_dim]);
}
SaveBlobs();
Expand Down
5 changes: 4 additions & 1 deletion src/caffe/test/test_data/generate_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
data = np.arange(total_size)
data = data.reshape(num_rows, num_cols, height, width)
data = data.astype('float32')
label = np.arange(num_rows)[:, np.newaxis]

# We had a bug where data was copied into label, but the tests weren't
# catching it, so let's make label 1-indexed.
label = 1 + np.arange(num_rows)[:, np.newaxis]
label = label.astype('float32')

print data
Expand Down
Binary file modified src/caffe/test/test_data/sample_data.h5
Binary file not shown.
Binary file modified src/caffe/test/test_data/sample_data_2_gzip.h5
Binary file not shown.
2 changes: 1 addition & 1 deletion src/caffe/test/test_hdf5_output_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void HDF5OutputLayerTest<TypeParam>::CheckBlobEqual(const Blob<Dtype>& b1,
for (int c = 0; c < b1.channels(); ++c) {
for (int h = 0; h < b1.height(); ++h) {
for (int w = 0; w < b1.width(); ++w) {
EXPECT_EQ(b1.data_at(n, c, h, w), b1.data_at(n, c, h, w));
EXPECT_EQ(b1.data_at(n, c, h, w), b2.data_at(n, c, h, w));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/caffe/test/test_hdf5data_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ TYPED_TEST(HDF5DataLayerTest, TestRead) {

// On even iterations, we're reading the first half of the data.
// On odd iterations, we're reading the second half of the data.
int label_offset = (iter % 2 == 0) ? 0 : batch_size;
// NB: label is 1-indexed
int label_offset = 1 + ((iter % 2 == 0) ? 0 : batch_size);
int data_offset = (iter % 2 == 0) ? 0 : batch_size * data_size;

// Every two iterations we are reading the second file,
Expand Down

0 comments on commit e2f960e

Please sign in to comment.