1 // Copyright Sergey Karayev 2014
4 - only load parts of the file, in accordance with a prototxt param "max_mem"
14 #include "caffe/layer.hpp"
15 #include "caffe/util/io.hpp"
16 #include "caffe/vision_layers.hpp"
22 template <typename Dtype>
23 void HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
24 vector<Blob<Dtype>*>* top) {
25 const int batchsize = this->layer_param_.batchsize();
26 const int data_count = (*top)[0]->count() / (*top)[0]->num();
27 const int label_data_count = (*top)[1]->count() / (*top)[1]->num();
29 for (int i = 0; i < batchsize; ++i, ++current_row_) {
30 if (current_row_ == data_blob_.num()) {
34 if (current_file_ == num_files_) {
36 LOG(INFO) << "looping around to first file";
39 load_hdf5_file_data(hdf_filenames_[current_file_].c_str());
44 CUDA_CHECK(cudaMemcpy(
45 &(*top)[0]->mutable_gpu_data()[i * data_count],
46 &data_blob_.cpu_data()[current_row_ * data_count],
47 sizeof(Dtype) * data_count,
48 cudaMemcpyHostToDevice));
50 CUDA_CHECK(cudaMemcpy(
51 &(*top)[1]->mutable_gpu_data()[i * label_data_count],
52 &label_blob_.cpu_data()[current_row_ * label_data_count],
53 sizeof(Dtype) * label_data_count,
54 cudaMemcpyHostToDevice));
58 template <typename Dtype>
59 Dtype HDF5DataLayer<Dtype>::Backward_gpu(const vector<Blob<Dtype>*>& top,
60 const bool propagate_down, vector<Blob<Dtype>*>* bottom) {
64 INSTANTIATE_CLASS(HDF5DataLayer);